/////////////////////////////////////////////////////////////////头文件及函数声明#includeiostream#includestdlib.h#includeconio.h#includefstream#includestring#includeiomanipusingnamespacestd;classXS;classJS;classstu;classsubject;intmenu();//主菜单intmenu1();//学生选课端菜单intmenu2();//管理端菜单templateclassTvoidADD(TP);//增加功能函数模板templateclassTvoidLOOK(TP);//查看功能函数模板templateclassTvoidDELETE(TP);//删除功能函数模板voidxuanke(XSP,charnu[],charna[]);//选课功能函数voidtuixuan(XSP,charnu[],charna[]);//退选课程功能函数voidlookyixuan(XSP,charnu[],charna[]);//查看学生已选课程函数voiddayin(XSP,charnu[],charna[]);//打印学生选课情况函数voidtuichu();//退出系统函数voidpassword();//密码检查功能函数///////////////////////////////////////////////定义课程信息类structcourse{charcnum[10];charcname[20];charcteacher[20];floatcredit;};structCourse{coursekecheng;Course*next;};classsubject{Course*head;//头指针Course*p;//当前指针public:subject(){head=p=NULL;};voidAdd();voidDelete();//删除课程intSearch(charnu[]);//根据课程号查找课程voidReadFile();//从文件中读取课程信息voidWriteFile();//向文件写入课程信息voidDisplay();//在屏幕中输出全部课程信息friendXS;friendJS;friendvoidxuanke(XSP,charnu[],charna[]);};voidsubject::Add(){p=newCourse;cout\t请输入课程号:;cinp-kecheng.cnum;if(Search(p-kecheng.cnum)==0){cout\t请输入课程名:;cinp-kecheng.cname;cout\t请输入任课教师:;cinp-kecheng.cteacher;cout\t请输入课程学分:;cinp-kecheng.credit;p-next=head;//头插入建链表head=p;cout增加课程操作成功!endl;}elsecout\n\t已经存在该课程,不能重复添加!endl;}voidsubject::Delete()//按课程号删除{if(head!=NULL){intn=0;Course*kc=head;Course*q1=head,*q2=head-next;charkh[10];cout\t请输入您要删除的课程号:;cinkh;while(kc!=NULL){n++;if(strcmp(kc-kecheng.cnum,kh)==0)break;kc=kc-next;}if(kc==NULL)cout不存在该课程号!endl;else{if(n==1)head=head-next;else{for(inti=1;in-1;i++){q1=q2;q2=q2-next;}if(q2==NULL)q1=NULL;elseq1-next=q2-next;}cout删除成功!endl;}}}intsubject::Search(charnu[]){Course*kc=head;while(kc!=NULL){if(strcmp(kc-kecheng.cnum,nu)==0)break;kc=kc-next;}if(kc==NULL)return0;elsereturn1;}voidsubject::Display()//在屏幕中输出全部课程信息{if(head==NULL)cout没有课程信息!\n\n;else{Course*k=head;coutsetiosflags(ios::left)setw(10)课程号setiosflags(ios::left)setw(15)课程名setiosflags(ios::left)setw(15)任课教师setiosflags(ios::left)setw(5)学分endl;while(k){coutsetiosflags(ios::left)setw(10)k-kecheng.cnumsetw(15)setiosflags(ios::left)k-kecheng.cnamesetw(16)setiosflags(ios::left)k-kecheng.cteachersetw(5)setiosflags(ios::left)k-kecheng.creditendl;k=k-next;}coutendl;}}voidsubject::ReadFile()//从文件读取课程信息{p=newCourse;ifstreamfip(课程信息.dat,ios::in|ios::binary);if(!fip)cout文件打开失败!endl;elsewhile(fip.read((char*)&p-kecheng,sizeof(p-kecheng))){p-next=head;head=p;p=newCourse;}fip.close();deletep;}voidsubject::WriteFile()//向文件写入课程信息{Course*s=head;ofstreamfop;fop.open(课程信息.dat,ios::binary|ios::trunc);if(!fop){cout课程信息.dat无法打开!endl;abort();}while(s){while(fop.write((char*)&s-kecheng,sizeof(s-kecheng))){s=s-next;}}fop.close();}///////////////定义教师信息类structteacher{chartnum[10];chartname[20];charzhicheng[20];};structTeacher{teacherjiaoshi;Teacher*next;};classJS{Teacher*head;//头指针Teacher*p;//当前指针public:JS(){head=p=NULL;};voidAdd();voidDelete();voidSearch(charna[]);//通过教师姓名查找任课教师intSearch1(charnu[]);//通过教师号查找教师voidReadFile();//从文件中读取教师信息voidWriteFile();//向文件写入教师信息voidDisplay();//在屏幕中输出全部教师信息friendXS;};voidJS::Add(){p=newTeacher;cout\t请输入教师证号:;cinp-jiaoshi.tnum;if(Search1(p-jiaoshi.tnum)==0){cout\t请输入教师姓名:;cinp-jiaoshi.tname;cout\t请输入教师职称:;cinp-jiaoshi.zhicheng;p-next=head;//头插入建链表head=p;cout增加教师操作成功!endl;}elsecout\n\t该教师已经存在,不能重复添加!endl;}voidJS::Delete(){if(head!=NULL){intn=0;Teacher*js=head;Teacher*q1=head,*q2=head-next;charzh[10];cout\t请输入您要删除的教师证号:;cinzh;while(js!=NULL){n++;if(strcmp(js-jiaoshi.tnum,zh)==0)break;js=js-next;}if(js==NULL)cout不存在该教师!endl;else{if(n==1)head=head-next;else{for(inti=1;in-1;i++){q1=q2;q2=q2-next;}if(q2==NULL)q1=NULL;elseq1-next=q2-next;}cout删除教师成功!endl;}}}voidJS::Search(charna[]){Teacher*js=head;while(js!=NULL){if(strcmp(na,js-jiaoshi.tname)==0)break;js=js-next;}if(js!=NULL){coutsetiosflags(ios::left)setw(10)教师证号setiosflags(ios::left)setw(16)教师姓名setiosflags(ios::left)setw(16)教师职称endl;coutsetiosflags(ios::left)setw(10)js-jiaoshi.tnumsetw(16)setiosflags(ios::left)js-jiaoshi.tnamesetw(16)setiosflags(ios::left)js-jiaoshi.zhichengendl;}elsecout没有该教师信息!endl;}voidJS::Display(){if(head==NULL)cout没有教师信息!\n\n;else{Teacher*k=head;coutsetiosflags(ios::left)setw(10)教师证号setiosflags(ios::left)setw(16)教师姓名setiosflags(ios::left)setw(16)教师职称endl;while(k){coutsetiosflags(ios::left)setw(10)k-jiaoshi.tnumsetw(16)setiosflags(ios::left)k-jiaoshi.tnamesetw(16)setiosflags(ios::left)k-jiaoshi.zhichengendl;k=k-next;}coutendl;}}intJS::Search1(charnu[]){Teacher*js=head;while(js!=NULL){if(strcmp(nu,js-jiaoshi.tnum)==0)break;js=js-next;}if(js==NULL)return0;elsereturn1;}voidJS::WriteFile(){Teacher*s=head;ofstreamfop;charxs[]=教师信息.dat;fop.open(xs,ios::binary|ios::trun