写了个系统,可以编译运行。欢迎各位来找bug。
#include<iostream>
#include<list>
#include<string>
#include<string.h>
#include<algorithm>
#include<fstream>//输出操作头文件
using namespace std;
//Lesson类的封装
class Lesson//定义课程属性
{private:
string Num;
string Name;
string Properties;
int Total;
double Credit;
string Term;
public:
//用set开头的函数设置信息
void setNum(string Num);
void setName(string Name);
void setProperties(string Properties);
void setTotal(int Total);
void setCredit(double Credit);
void setTerm(string Term);
//用get开头的函数录入信息
string getNum() ;
string getName() ;
string getProperties() ;
int getTotal() ;
double getCredit() ;
string getTerm() ;
};
//对成员函数进行定义
void Lesson::setNum(string Num){
this->Num = Num;
}
void Lesson::setName(string Name){
this->Name = Name;
}
void Lesson::setProperties(string Properties){
this->Properties = Properties;
}
void Lesson::setTotal(int Total){
this->Total = Total;
}
void Lesson::setCredit(double Credit){
this->Credit = Credit;
}
void Lesson::setTerm(string Term){
this->Term =Term;
}
string Lesson::getNum() {return this->Num;}
string Lesson::getName() {return this->Name;}
string Lesson::getProperties() {return this->Properties;}
int Lesson::getTotal() {return this->Total;}
double Lesson::getCredit() {return this->Credit;}
string Lesson::getTerm() {return this->Term;}
//Fun类的封装
class Fun{
public:
void static show();
void static clear();
void static pause();
void static AddClass();
void static Glance();
void static showSearchByCredit();
void static AddClassNum();
void static AddClassName();
void static AddClassProperties();
void static AddTotal();
void static AddCredit();
void static AddTerm();
void static quit();
};
//操作页面样式
void Fun:: show(){
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 Fun:: clear(){//用于清除屏幕上的数据
system("cls");}
void Fun:: pause(){ //用于暂停,输入任意键后跳转
system("pause");}
void Fun:: AddClass(){ // 显示提示信息
cout << "请输入课程编号(四个数字),课程名称,课程性质,总学时,学分,开课学期" << endl;}
void Fun:: Glance(){
cout << "下列为所有课程的信息" << endl;}
void Fun:: showSearchByCredit(){
cout << "按照学分查询的结果为:" << endl;}
void Fun:: AddClassNum(){
cout << "请输入课程编号(四个数字)" << endl;}
void Fun:: AddClassName(){
cout << "请输入课程名称" << endl;}
void Fun:: AddClassProperties(){
cout << "请输入课程性质" << endl;}
void Fun:: AddTotal(){
cout << "请输入总学时" << endl;}
void Fun:: AddCredit(){
cout << "请输入学分" << endl;}
void Fun:: AddTerm(){
cout << "请输入开课学期" << endl;}
void Fun:: quit(){
cout<<"press any key to continue";}
//使用公有继承,继承Fun类中的成员函数
class Operate:public Fun{//定义了选课类的操作属性
public:
Operate(){}
void run();
void addClass();
void quit() ; //退出函数
void showAllClass();
void search();
void delect();
void help();
bool saveClass();
};
// Operate类成员函数的实现
void Operate:: run(){ //根据输入的序号,执行对应的操作
while(1){
clear();
show(); //显示界面
char key=cin.get();
switch(key){
case '1': //执行什么对应操作
clear();
AddClass();
this->addClass();
break;
case '2':
clear();
Glance();
this->showAllClass();
pause();
break;
case '3':
clear();
this->search();
pause();
break;
case '4':
clear();
this->delect();
pause();
break;
case '5':
clear();
this->help();
pause();
break;
case '6':
clear();
this->quit();
pause();
default:
break;
}
}
}
void Operate:: addClass(){//添加例如选课等操作
Lesson C;
string Num("");
string Name("");
string Properties("");
int Total(0);
double Credit(0.0);
string Term("");
AddClassNum();
cin >>Num;
C.setNum(Num);
AddClassName();
cin >>Name;
C.setName(Name);
AddClassProperties();
cin >> Properties;
C.setProperties(Properties);
AddTotal();
cin >> Total;
C.setTotal(Total);
AddCredit();
cin >> Credit;
C.setCredit(Credit);
AddTerm();
cin >>Term;
C.setTerm(Term);
ofstream outfile;//输出文件
outfile.open("classSave.txt",ios::app);
outfile<<" 课程编号:"<<Num<<" 课程名称:"<<Name <<" 课程性质:"<<Properties
<<" 总课时:"<< Total<<" 总学分:"<< Credit<<" 开课学期:"<<Term<<endl;
outfile.close();
}
void Operate::quit() //退出函数
{exit(1);}
void Operate::showAllClass(){
ifstream fin("classSave.txt");//包含
char ch;
while((ch=fin.get())!=EOF){//读到文件结尾为EOF标志
cout<<ch;
}}
void Operate::search(){
ifstream fin("classSave.txt");
static string line;//静态成员数据用于比较
string num;
int j;
cout<<"请输入对应课程编号:(四个数字)"<<endl;
cin>>num;
while(getline (fin,line))
{
for(int i=0;i<4;i++)
{
if (line[10+i]==num[i])
j++;
}
if (j==4)
cout<<line<<endl;
j=0;
}
}
void Operate::help(){
cout<<"1.关于本系统"<<endl;
cout<<"2.如何操作本系统"<<endl;
cout<<"3.系统制作人员"<<endl;
while(1){
char r=cin.get();
switch(r){
case '1':
clear();
cout<<"系统运行环境:windows"<<endl;
cout<<"系统编译环境:DevC++ 5.5.3"<<endl;
cout<<"系统制作时间:2017.6.12"<<endl;
pause();
break;
exit(2);
case '2':
clear();
cout<<"在主界面进行对应功能的选择"<<endl;
cout<<"进入对应界面后根据屏幕上的提示进行相应的操作"<<endl;
cout<<"操作完毕后按回车键范围主菜单"<<endl;
cout<<"完成所有操作后选择退出系统按钮退出课程管理系统"<<endl;
pause();
break;
exit(3);
case '3':
clear();
cout<<"Suki"<<endl;
pause();
exit(1);
default:
break;
}
}
}
void Operate::delect(){
cout<<"正在清除数据..."<<endl;
FILE*fp=fopen("classSave.txt","w");
fclose(fp);
cout<<"清除数据成功"<<endl;
}
//主函数
int main(){
Operate A;
A.run();
return 0;
}
记事本上同步,除非选择清屏,否则所有课程都会被记录。