C++学生管理系统课程设计-源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

//=================================================================================================================//student.h定义了抽象类Person,派生了student(及为信息类)、定义了节点类Node、定义了链表类List//=================================================================================================================#ifndefSTUDATA_H#defineSTUDATA_H#includefstream.h//================================================================intGetID();classList;//-------------------------------------classPerson{//抽象类protected:intID;//学号charName[15];//姓名public:virtualbooloperator(Person&)=0;//运算符重载virtualbooloperator=(Person&)=0;//=运算符重载};//---------------------------------------------------------------------------------------classStudent:publicPerson{//学生类intScore[4];//成绩voidSwapData(Student*);//交换数据public:Student(int=0,char*=NULL,int*=NULL);//构造函数booloperator(Person&);//运算符重载booloperator=(Person&);//=运算符重载friendofstream&operator(ofstream&,Student*);//运算符重载输出到文件friendifstream&operator(ifstream&,Student*);//运算符重载从文件输入friendostream_withassign&operator(ostream_withassign&,Student*);//运算符重载输出到显示器friendistream_withassign&operator(istream_withassign&,Student*);//运算符重载从键盘输入friendclassList;};//----------------------------------------------------------------------------------------------------------------classNode{//结点类Student*Stup;//指向学生对象指针Node*Prev,*Next;//指向前后结点指针public:Node();//构造函数Node(Student*);//构造函数Node(Node&);//拷贝构造函数~Node();//析构函数friendclassList;};//-----------------------------------------------------------------------------------------------------------------classList{Node*Head,*Tail;//链表头尾指针voidInitList();//初始化函数public:List();//构造函数~List();//析构函数voidClearList();//清空链表Node*FindID(int&);//根据学号寻找学生所在结点指针型函数voidInsert(Node*);//插入一个学生Node*CreateNode(Student*);//建立一个学生结点指针型函数voidAdd();//增加一个学生voidUpdate();//修改学生成绩voidDelete();//删除一个学生voidQuery();//查找一个学生voidSortID();//按学号排序voidSortScore();//按学生总成绩排序voidSaveBin();//以二进制形式保存数据voidPrintList();//显示链表voidPrintTitle();//显示标题voidPrintOne(Student*);//显示一个学生数据};#endif//==========================================================================//student.cpp的实现//==========================================================================#includeiostream.h#includeiomanip.h#includestring.h#includestudent.h//==========================================================================Student::Student(intid,char*name,int*score){//构造函数ID=id;if(name!=NULL)strcpy(Name,name);if(score!=NULL)for(inti=0;i=3;i++)Score[i]=score[i];}boolStudent::operator(Person&per){Student&stu=(Student&)per;return(Score[3]stu.Score[3]);}boolStudent::operator=(Person&per){return(!operator(per));//return(Score[3]=stu.Score[3])}voidStudent::SwapData(Student*stup){//学生数据交换this指针指向调用成员函数的对象Studentt=*this;*this=*stup;*stup=t;}ifstream&operator(ifstream&in,Student*stup){//运算符重载从文件输入in.read((char*)stup,sizeof(Student));//从相应的流中提取sizeof(Student)个字节,并把它们放入stup所指的缓冲区中returnin;}ofstream&operator(ofstream&out,Student*stup){//运算符重载输出至文件out.write((char*)stup,sizeof(Student));//从stup所指的缓冲区把sizeof(Student)个字节插入到相应的流上returnout;}istream_withassign&operator(istream_withassign&in,Student*stup){//运算符重载从标准文件输入inti;coutInputName,Score1-Score3endl;coutName=;instup-Name;stup-Score[3]=0;for(i=0;i3;i++){coutScorei=;instup-Score[i];stup-Score[3]+=stup-Score[i];}returnin;//输入流对象in返回的到调用处}ostream_withassign&operator(ostream_withassign&out,Student*stup){//运算符重载输出至标准文件outstup-IDsetw(8)stup-Namesetw(8)stup-Score[0]setw(10)stup-Score[1]setw(10)stup-Score[2]setw(10)stup-Score[3]endl;outendl;returnout;//输处流对象out返回的调用处/*inti;outstup-ID\tstup-Name\t;for(i=0;i4;i++){outstup-Score[i]\t;}outendl;returnout;*/}//================================================================//node.cpp的实现//================================================================#includeiostream.h#includestudent.h//---------------------------------------------------------------Node::Node(){Stup=NULL;Prev=Next=NULL;}Node::Node(Student*stup){//默认的构造函数,完成建立一个空节点Stup=stup;Prev=Next=NULL;}Node::Node(Node&node){//复制构造函数的实现OKStup=node.Stup;Prev=node.Prev;Next=node.Next;}Node::~Node(){//释放空间deleteStup;}//=================================================================================================//list.cpp的实现//================================================================================================#includeiostream#includestring#includestudent.h//=================================================================================================List::List(){//构造函数Head=Tail=newNode();//建立链表头结点Head-Next=NULL;Head-Prev=NULL;InitList();//从文件读取数据在下面调用此函数}List::~List(){//析构函数ClearList();//在下面调用此函数deleteHead;//释放空间}voidList::InitList()//从文件读取数据{ifstreaminStudent;ofstreamoutStudent;inStudent.open(gx.dat,ios::binary);//打开学生文件if(!inStudent)//文件不存在,建立该文件{inStudent.close();outStudent.open(gx.dat,ios::binary);outStudent.close();//关闭文件}else//文件存在,读取学生数据{Student*stup=newStudent();Node*nodep;inS

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功