C++程序设计课程的作业,允许使用STL。功能要求是,有注册学生、注册课程、选课、退课的功能。大体实现思路是,对于每个课程和学生,用map保存其信息,灵活方便;为实现注册功能,用指针线性表管理学生和课程,方便动态创建和统一析构;为实现选课和退课功能,维护学生和课程之间的二元关系及其逆关系(用指针序偶的集合实现)。可见,学生信息和课程信息在内存中是唯一的,选课和退课的操作都是对指针进行的,节省内存。注意,与硬盘交互的文件功能可能存在问题。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-12-22 08:59 CourseSelectionSystem
目录 0 2018-12-18 22:22 CourseSelectionSystem.vs
目录 0 2018-12-18 22:22 CourseSelectionSystem.vsCourseSelectionSystem
目录 0 2018-12-28 19:49 CourseSelectionSystem.vsCourseSelectionSystemv15
文件 91648 2018-12-28 19:49 CourseSelectionSystem.vsCourseSelectionSystemv15.suo
文件 5967872 2018-12-28 19:49 CourseSelectionSystem.vsCourseSelectionSystemv15Browse.VC.db
目录 0 2018-12-28 19:43 CourseSelectionSystem.vsCourseSelectionSystemv15ipch
文件 327680 2018-12-22 11:02 CourseSelectionSystem.vsCourseSelectionSystemv15ipch3d84e2152de53b30.ipch
文件 327680 2018-12-28 19:44 CourseSelectionSystem.vsCourseSelectionSystemv15ipcha75d1391a2f1a14f.ipch
目录 0 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystem
文件 1476 2018-12-18 22:22 CourseSelectionSystemCourseSelectionSystem.sln
文件 1814 2018-12-28 10:05 CourseSelectionSystemCourseSelectionSystemCourse.cpp
文件 460 2018-12-22 08:12 CourseSelectionSystemCourseSelectionSystemCourse.h
文件 147 2018-12-20 15:17 CourseSelectionSystemCourseSelectionSystemcourses.txt
文件 6027 2018-12-28 10:04 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.cpp
文件 1053 2018-12-22 11:23 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.h
文件 8945 2018-12-19 14:06 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.vcxproj
文件 2335 2018-12-19 14:06 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.vcxproj.filters
文件 165 2018-12-18 22:22 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.vcxproj.user
目录 0 2018-12-28 10:05 CourseSelectionSystemCourseSelectionSystemDebug
文件 619021 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourse.obj
目录 0 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlog
文件 15506 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCL.command.1.tlog
文件 144078 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCL.read.1.tlog
文件 7784 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCL.write.1.tlog
文件 225 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCourseSelectionSystem.lastbuildstate
文件 5938 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tloglink.command.1.tlog
文件 5988 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tloglink.read.1.tlog
文件 1980 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tloglink.write.1.tlog
文件 408 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSelectionSystem.log
文件 850299 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSelectionSystem.obj
............此处省略29个文件信息
#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.vsCourseSelectionSystem
目录 0 2018-12-28 19:49 CourseSelectionSystem.vsCourseSelectionSystemv15
文件 91648 2018-12-28 19:49 CourseSelectionSystem.vsCourseSelectionSystemv15.suo
文件 5967872 2018-12-28 19:49 CourseSelectionSystem.vsCourseSelectionSystemv15Browse.VC.db
目录 0 2018-12-28 19:43 CourseSelectionSystem.vsCourseSelectionSystemv15ipch
文件 327680 2018-12-22 11:02 CourseSelectionSystem.vsCourseSelectionSystemv15ipch3d84e2152de53b30.ipch
文件 327680 2018-12-28 19:44 CourseSelectionSystem.vsCourseSelectionSystemv15ipcha75d1391a2f1a14f.ipch
目录 0 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystem
文件 1476 2018-12-18 22:22 CourseSelectionSystemCourseSelectionSystem.sln
文件 1814 2018-12-28 10:05 CourseSelectionSystemCourseSelectionSystemCourse.cpp
文件 460 2018-12-22 08:12 CourseSelectionSystemCourseSelectionSystemCourse.h
文件 147 2018-12-20 15:17 CourseSelectionSystemCourseSelectionSystemcourses.txt
文件 6027 2018-12-28 10:04 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.cpp
文件 1053 2018-12-22 11:23 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.h
文件 8945 2018-12-19 14:06 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.vcxproj
文件 2335 2018-12-19 14:06 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.vcxproj.filters
文件 165 2018-12-18 22:22 CourseSelectionSystemCourseSelectionSystemCourseSelectionSystem.vcxproj.user
目录 0 2018-12-28 10:05 CourseSelectionSystemCourseSelectionSystemDebug
文件 619021 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourse.obj
目录 0 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlog
文件 15506 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCL.command.1.tlog
文件 144078 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCL.read.1.tlog
文件 7784 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCL.write.1.tlog
文件 225 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogCourseSelectionSystem.lastbuildstate
文件 5938 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogli
文件 5988 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogli
文件 1980 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSe.7C65D630.tlogli
文件 408 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSelectionSystem.log
文件 850299 2018-12-28 10:06 CourseSelectionSystemCourseSelectionSystemDebugCourseSelectionSystem.obj
............此处省略29个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)