#include<iostream>
#include<list>
#include<string>
#include<iterator>
#include<algorithm>
#include<fstream>
using namespace std;
class Class{
public:
void setClassNum(string classNumTemp);//课程编号
void setClassName(string classNameTemp);//课程名称
void setClassProperties(string classPropertiesTemp);//课程性质
void setTotalClassNumber(int totalClassNumberTemp);//总学时
void setCurrentClassNumber(int currentClassNumberTemp);//授课学时
void setExpClassNumber(int expClassNumberTemp);//实验或上机学时
void setCredit(double credit);//学分
void setRightTerm(string rightTermTemp);//开课信息
string getClassNum() const;// 课程编号录入
string getClassName() const;//课程名称录入
string getClassProperties() const;//课程性质录入
int getTotalClassNumber() const;//总学时录入
int getCurrentClassNumber() const;//授课学时录入
int getExpClassNumber() const;//实验或上机学时录入
double getCredit() const;//学分录入
string getRightTerm() const;//开课信息录入
private:
string classNum;//课程编号
string className;//课程名称
string classProperties;//课程性质
int totalClassNumber;//总学时
int currentClassNumber;//授课学时
int expClassNumber;//上级或实验学时
double credit;//学分
string rightTerm;//开课学期
};
void Class::setClassNum(string classNumTemp){
this->classNum=classNumTemp;
}// 设置课程编号的实现
void Class::setClassName(string classNameTemp){
this->className = classNameTemp;
}//设置课程名称的实现
void Class::setClassProperties(string classPropertiesTemp){
this->classProperties = classPropertiesTemp;
}//设置课程性质的实现
void Class::setTotalClassNumber(int totalClassNumberTemp){
this->totalClassNumber = totalClassNumberTemp;
}//设置总学时的实现
void Class::setCurrentClassNumber(int currentClassNumber){
this->currentClassNumber = currentClassNumber;
}//设置授课学时的实现
void Class::setExpClassNumber(int expClassNumberTemp){
this->expClassNumber = expClassNumberTemp;
}//设置上机学时的实现
void Class::setRightTerm(string rightTermTemp){
this->rightTerm=rightTermTemp;
}//设置开课学期的实现
void Class::setCredit(double credit){
this->credit=credit;
}//设置课程学分的实现
string Class::getClassNum() const{//设置为常函数防止数据改变
return this-> classNum;
}
string Class::getClassName() const{
return this->className;
}
string Class::getClassProperties() const{
return this->classProperties;
}
int Class::getTotalClassNumber() const{
return this->totalClassNumber;
}
int Class::getCurrentClassNumber() const{
return this->currentClassNumber;
}
int Class::getExpClassNumber() const{
return this->expClassNumber;
}
double Class::getCredit() const{
return this->credit;
}
string Class::getRightTerm() const{return this->rightTerm;}
//Menu类的封装
class Menu
{
public:
char static getInput();
void static showMenu();
void static clearScreen();
void static pauseScreen();
void static showAddClass();
void static showBrowseClass();
void static showSearchByCredit();
void static showSearchByClassProperties();
void static showAddClassNum();
void static showAddClassName();
void static showAddClassProperties();
void static showAddTotalClassNumber();
void static showAddCurrentClassNumber();
void static showAddExpClassNumber();
void static showAddCredit();
void static showAddRightTerm();
void static showLoadingSaving();
void static showSuccessedSaving();
void static quit();
void static showEachClassInfo(Class classTemp);
};
// Menu类成员函数的实现
char Menu:: getInput(){
char key=cin.get();
return key;}
void Menu::showMenu()
{
cout<<" 欢迎进入学生选课管理系统 "<<endl;
cout<<" ******************************** "<<endl;
cout<<" "<<endl;
cout<<" 1 课程信息的录入 "<<endl;
cout<<" 2 课程信息的查询 "<<endl;
cout<<" 3 根据学分查询 "<<endl;
cout<<" 4 按课程性质查询 "<<endl;
cout<<" 5 存储信息 "<<endl;
cout<<" 6 退出系统 "<<endl;
cout<<" "<<endl;
cout<<" 请输入操作对应的序号 "<<endl;
cout<<" ********************************* "<<endl;
}
void Menu::clearScreen(){
system("cls");
}
void Menu::pauseScreen() //暂停
{
system("pause");
}
void Menu::showAddClass(){ // 显示增添课程信息
cout << "请输入要添加的课程编号\n"<<"课程名称\n"<<"课程性质\n"<<"总 学 时\n"<<"授课学时\n"<<"实验学时\n"<<"学分\n"<<"开课学期等信息\n" << endl;
}
void Menu::showBrowseClass(){
cout << "所有课程的信息为" << endl;
}
void Menu:: showSearchByCredit(){
cout << "按照学分查询的结果为:" << endl;
}
void Menu:: showSearchByClassProperties(){
cout << "按照课程性质查询的结果为:" << endl;
}
void Menu:: showAddClassNum(){
cout << "\n请输入课程编号" << endl;
}
void Menu:: showAddClassName(){
cout << "请输入课程名称" << endl;
}
void Menu:: showAddClassProperties(){
cout << "请输入课程性质" << endl;
}
void Menu:: showAddTotalClassNumber(){
cout << "请输入总学时" << endl;
}
void Menu:: showAddCurrentClassNumber(){
cout << "请输入授课学时" << endl;
}
void Menu::showAddExpClassNumber(){
cout << "请输入实验或上机学时" << endl;
}
void Menu::showAddCredit(){
cout<<"请输入学分 "<<endl;
}
void Menu:: showAddRightTerm(){
cout << "请输入开课学期" <<endl;
}
void Menu::showLoadingSaving(){
cout <<"正在存储数据"<<endl;
}
void Menu::showSuccessedSaving(){
cout<<"数据存储完毕"<<endl;
}
void Menu::quit(){
cout<<"press any key to continue";
}
void Menu::showEachClassInfo(Class classTemp){
cout<<"课程编号:"<<classTemp.getClassNum();
cout<<" 课程名称:"<<classTemp.getClassName();
cout<<" 课程性质:"<<classTemp.getClassProperties();
cout<<" 总学时:"<<classTemp.getTotalClassNumber();
cout<<" 授课学时:"<<classTemp.getCurrentClassNumber();
cout<<" 实验学时:"<<classTemp.getExpClassNumber();
cout<<" 课程学分:"<<classTemp.getCredit();
cout<<" 开课学期:"<<classTemp.getRightTerm();
cout<<" "<<endl;
cout<<" "<<endl;
}
//Control类的封装
class Control{
public:
Control(){}
void start();
void initIalization();
void addClass();
void quit();
void showAllClass();
void searchByCredit();
void searchByClassProperties();
bool saveClass();
private:
list<Class>classList;
};
// Control类成员函数的实现
void Control:: start(){ //start里面要做的事情就是初始化界面,等待用户输入判断调用
initIalization();
while(1){
Menu::clearScreen();
Menu::showMenu(); //显示界面
char key = Menu::getInput();
switch(key){
case '1': //判断是按下了哪个按键,然后执行什么对应的操作
Menu::clearScreen();
Menu::showAddClass();
this->addClass();
cin.get();
cin.get();
case '2':
Menu::clearScreen();
Menu::showBrowseClass();
this->showAllClass();
Menu::pauseScreen();
break;
case '3':
Menu::clearScreen();
this->searchByCredit();
Menu::pauseScreen();
break;
case '4':
Menu::clearScreen();
this->searchByClassProperties();
Menu::pauseScreen();
break;
case '6':
Menu::clearScreen();
this->quit();
Menu::pauseScreen();
break;
case '5':
Menu::showLoadingSaving();
if (this->saveClass()){
Menu::showSuccessedSaving();
}
Menu::pauseScreen();
Menu::pauseScreen();
default:
break;
}
}
}
void Control:: initIalization(){
ifstream ifs;//文件输入流ifs 相当于建立一个文件
ifs.open("classSave.txt",ios_base::in);
if(!ifs){
Menu::pauseScreen();
return;
}