• 大小: 4.54MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-19
  • 语言: C/C++
  • 标签: C++  course  

资源简介

C++程序设计课程的作业,允许使用STL。功能要求是,有注册学生、注册课程、选课、退课的功能。大体实现思路是,对于每个课程和学生,用map保存其信息,灵活方便;为实现注册功能,用指针线性表管理学生和课程,方便动态创建和统一析构;为实现选课和退课功能,维护学生和课程之间的二元关系及其逆关系(用指针序偶的集合实现)。可见,学生信息和课程信息在内存中是唯一的,选课和退课的操作都是对指针进行的,节省内存。注意,与硬盘交互的文件功能可能存在问题。

资源截图

代码片段和文件信息

#include “pch.h“
#include “Course.h“
#include 

const char Course::signature[30] = { “Course“ };

Course::Course()
{
info[“ID“];
info[“name“];
info[“teacher“];
info[“domain“];
info[“time“];
info[“credit“];
info[“evaluation mode“];
}


Course::operator MyString() const
{
MyString _str(signature);
_str.append(“ “);
for (auto it = info.cbegin();
it != info.cend(); it++)
{
_str.append(“{“);
_str.append(it->first);
_str.append(“: “);
_str.append(it->second);
_str.append(“} “);
}
return _str;
}


Course::~Course()
{
}


Course::Course(const Course & c)
{
ID = c.ID;
info = c.info;
}


Course & Course::operator=(const Course & c)
{
ID = c.ID;
info = c.info;
return *this;
}


void Course::init()
{
std::cout << signature << std::endl;
MyString value;
for (auto it = info.begin();
it != info.end(); it++)
{
std::cout << it->first << “: “;
getline(std::cin value);
info[it->first] = value;
}
ID = info[“ID“];
}


void Course::save(std::ofstream & os) const
{
os << signature << std::endl;
for (auto it = info.cbegin(); it != info.cend(); it++)
os << “{“ << it->first << “:“ << it->second << “} “;
os << std::endl;
}


void Course::restore(std::ifstream & is)
{
std::streampos pos = is.tellg();
char buff[300];
char key[120];
char value[130];
MyString sig;
getline(is sig);
if (sig ==
MyString(signature))
{
is.getline(buff 300);
std::stringstream ss(buff);
ss.ignore(300 ‘{‘);
while (!ss.eof())
{
ss.getline(key 120 ‘:‘);
ss.getline(value 130 ‘}‘);
info[MyString(key)] = MyString(value);
ss.ignore(300 ‘{‘);
}
ID = info[“ID“];
}
else
is.seekg(pos);
}


MyString Course::getID() const
{
return ID;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-12-22 08:59  CourseSelectionSystem\
     目录           0  2018-12-18 22:22  CourseSelectionSystem\.vs\
     目录           0  2018-12-18 22:22  CourseSelectionSystem\.vs\CourseSelectionSystem\
     目录           0  2018-12-28 19:49  CourseSelectionSystem\.vs\CourseSelectionSystem\v15\
     文件       91648  2018-12-28 19:49  CourseSelectionSystem\.vs\CourseSelectionSystem\v15\.suo
     文件     5967872  2018-12-28 19:49  CourseSelectionSystem\.vs\CourseSelectionSystem\v15\Browse.VC.db
     目录           0  2018-12-28 19:43  CourseSelectionSystem\.vs\CourseSelectionSystem\v15\ipch\
     文件      327680  2018-12-22 11:02  CourseSelectionSystem\.vs\CourseSelectionSystem\v15\ipch\3d84e2152de53b30.ipch
     文件      327680  2018-12-28 19:44  CourseSelectionSystem\.vs\CourseSelectionSystem\v15\ipch\a75d1391a2f1a14f.ipch
     目录           0  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\
     文件        1476  2018-12-18 22:22  CourseSelectionSystem\CourseSelectionSystem.sln
     文件        1814  2018-12-28 10:05  CourseSelectionSystem\CourseSelectionSystem\Course.cpp
     文件         460  2018-12-22 08:12  CourseSelectionSystem\CourseSelectionSystem\Course.h
     文件         147  2018-12-20 15:17  CourseSelectionSystem\CourseSelectionSystem\courses.txt
     文件        6027  2018-12-28 10:04  CourseSelectionSystem\CourseSelectionSystem\CourseSelectionSystem.cpp
     文件        1053  2018-12-22 11:23  CourseSelectionSystem\CourseSelectionSystem\CourseSelectionSystem.h
     文件        8945  2018-12-19 14:06  CourseSelectionSystem\CourseSelectionSystem\CourseSelectionSystem.vcxproj
     文件        2335  2018-12-19 14:06  CourseSelectionSystem\CourseSelectionSystem\CourseSelectionSystem.vcxproj.filters
     文件         165  2018-12-18 22:22  CourseSelectionSystem\CourseSelectionSystem\CourseSelectionSystem.vcxproj.user
     目录           0  2018-12-28 10:05  CourseSelectionSystem\CourseSelectionSystem\Debug\
     文件      619021  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\Course.obj
     目录           0  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\
     文件       15506  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\CL.command.1.tlog
     文件      144078  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\CL.read.1.tlog
     文件        7784  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\CL.write.1.tlog
     文件         225  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\CourseSelectionSystem.lastbuildstate
     文件        5938  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\link.command.1.tlog
     文件        5988  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\link.read.1.tlog
     文件        1980  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSe.7C65D630.tlog\link.write.1.tlog
     文件         408  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSelectionSystem.log
     文件      850299  2018-12-28 10:06  CourseSelectionSystem\CourseSelectionSystem\Debug\CourseSelectionSystem.obj
............此处省略29个文件信息

评论

共有 条评论