您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 人事档案/员工关系 > C++教师信息管理系统
-1-一、课程设计问题描述学院教学信息管理系统是高等学校教务管理的重要组成部分,其内容较多,为了简化计论,要求设计的管理系统能够完成以下功能:(1)输入:输入每一位教师记录,将其信息写入文件中;(2)显示:显示每位教师记录;(3)排序:按职工号或教学效果综合评分进行排序,并显示;(4)查找:完成按姓名或课程查找教师的相关记录,并显示;(5)创建:创建新的纪录,输入数位教师记录,显示在屏幕上并保存;二、课程设计目的和要求:经过一个学期的《C++面向对象实用教程》课程的学习,已经有了一定地程序设计基础,但是要学好C++程序设计,不仅要认真阅读课本知识和从事课堂学习,更重要的是要进行上机实践,通过上机实践才能增强和巩固知识。三、系统设计(算法分析)1、整体结构整个程序定义四个类(1)CPerson类:包含数据成员name,age,sex,记录姓名,年龄,性别这些信息,并包含构造函数及其他成员函数(定义CPerson类以后若有需要,可再通过继承派生其他类);(2)CTeacher:共有继承CPerson类,包含数据成员title,teano,course,score,分别记录职称,职工号,3门课程和教学效果综合评分等信息,另有其他成员函数;(3)CNode类:节点类,包含2个数据成员,CTeacher类对象p和CNode类指针对象next,作为构建链表的单位;(4)CList类:链表类,声明为CNode类的友元类,数据成员有头结点head,尾节点tail,记录当前节点的p和当前节点前一节点的pre,链表相关的输入,显示,排序,查找,创建全部设为成员函数。总体流程为先打开文件,读取文件中的记录来创建链表,然后对链表进行操作,最后保存至文件中-2-2、流程图是否是否开始打开文件读取记录输入choicechoice==0?显示当前记录添加记录创建新纪录排序查找保存保存结束-3-3、各函数的功能和实现学院教学信息管理系统的相关功能由对应的函数来实现。(1)输入教师信息并显示voidAppend()通过提示一步步输入信息,由程序构建新节点并加入链表(2)显示所有记录voidPrint()(3)按职工号或教学效果综合评分排序并显示intSortMenu()voidSortMenuControl()voidInsertByTeano(CNode*newp)voidSortByTeano()voidInsertByScore(CNode*newp)voidSortByScore()(4)按姓名或课程查找教师记录并显示intSearchMenu()voidSearchMenuControl()voidSearchByName()voidSearchByCourse()四、程序源代码#includestdafx.h#includeiostream#includefstream#includevector#includealgorithm#includecstring#includestringusingnamespacestd;classCPerson{private:-4-stringname;intage;charsex;public:CPerson(){}CPerson(stringname,intage=0,charsex='M'){this-name=name;this-age=age;this-sex=sex;}voidSetAge(intage=0){this-age=age;}voidSetNameAndSex(stringname,charsex){this-name=name;this-sex=sex;}voidShowInfo(){coutname\tage\t(sex=='M'?男:女)endl;}stringGetName(){returnname;}intGetAge(){returnage;}charGetSex(){returnsex;-5-}};classCTeacher:publicCPerson{private:stringtitle;//职称stringteano;//职工号vectorstringcourse;//教授课程floatscore;//教学效果综合评分public:CTeacher(){}CTeacher(stringname,intage=0,charsex='M'):CPerson(name,age,sex){}voidSetData(stringtitle,stringteano){this-title=title;this-teano=teano;}voidSetCourse(stringc1,stringc2,stringc3){course.push_back(c1);course.push_back(c2);course.push_back(c3);}voidSetScore(floatscore){this-score=score;}voidShowInfo(){coutteano\tGetName()\tGetAge()\t(GetSex()=='M'?男:)title\tcourse[0]\tcourse[1]\tcourse[2]\tscoreendl;}-6-voidoperator=(CTeacher&one){CPerson(one.GetName(),one.GetAge(),one.GetSex());this-title=one.title;this-teano=one.teano;this-course[0]=one.course[0];this-course[1]=one.course[1];this-course[2]=one.course[2];this-score=one.score;}vectorstringGetCourse(){returncourse;}stringGetTitle(){returntitle;}stringGetTeano(){returnteano;}floatGetScore(){returnscore;}};classCNode{friendclassCList;private:CTeacherdata;CNode*next;};classCList{private:CNode*head;-7-CNode*tail;CNode*p;CNode*pre;intnum;//当前节点数public:intMainMenu(){cout1.显示当前记录endl;cout2.添加记录endl;cout3.排序endl;cout4.查找endl;cout5.创建新纪录endl;cout0.退出endl;coutendl;intchoice;cinchoice;returnchoice;}voidMainMenuControl(){ReadData();while(1){intchoice=MainMenu();if(choice==0)break;switch(choice){case1:Print();break;case2:Append();break;case3:SortMenuControl();break;case4:SearchMenuControl();break;case5:NewList();break;}}cout是否保存?(Y/N):;charc;cinc;if(c=='y')Save();}voidReadData(){-8-head=tail=newCNode;head-next=NULL;num=0;charfname[80];cout请输入要读取的文件:;cinfname;ifstreamfile(fname);if(!file){cout出现未知错误导致无法打开!endl;exit(1);}stringname,title,teano,course[3];intage;charsex;floatscore;while(file.peek()!=EOF){fileteanonameagesextitlecourse[0]course[1]course[2]score;p=newCNode;p-data.SetNameAndSex(name,sex);p-data.SetAge(age);p-data.SetData(title,teano);p-data.SetCourse(course[0],course[1],course[2]);p-data.SetScore(score);tail-next=p;tail=p;num++;}tail-next=NULL;}voidPrint(){for(p=head-next;p!=NULL;p=p-next)p-data.ShowInfo();coutendl;}voidAppend(){while(1)-9-{p=newCNode;cout请输入:endl;cout姓名:;stringname;cinname;cout年龄:;intage;cinage;cout性别(F/M):;charsex;cinsex;p-data.SetNameAndSex(name,sex);p-data.SetAge(age);cout职称:;stringtitle;cintitle;cout职工号:;stringteano;cinteano;p-data.SetData(title,teano);cout教授课程:;stringcourse[3];cincourse[0]course[1]course[2];p-data.SetCourse(course[0],course[1],course[2]);cout教学效果综合评分:;floatscore;cinscore;p-data.SetScore(score);p-next=tail-next;tail-next=p;tail=p;num++;charc;cout是否继续添加?(Y/N):;cinc;cin.get();if(c!='y')break;}tail-next=NULL;Print();}intSortMenu()-10-{cout1.按职工号排序endl;cout2.按教学效果综合评分排序endl;cout0.退出endl;coutendl;intchoice;cinchoice;returnchoice;}voidSortMenuControl(){while(1){intchoice=SortMenu();if(choice==0)break;switch(choice){case1:SortByTeano();break;case2:SortByScore();break;}Print();}}voidInsertByTeano(CNode*newp){for(pre=head,p=head-next;p!=NULL;pre=p,p=p-next)if(newp-data.GetTeano()p-data.GetTeano())break;newp-next=p;pre-next=newp;}voidSortByTeano(){p=head-next;head-next=NULL;CNode*nextp;while(p!=NULL){nextp=p-next;InsertByTeano(p);p=nextp;}-11-}voidInsertByScore(
本文标题:C++教师信息管理系统
链接地址:https://www.777doc.com/doc-3591388 .html