编写的简单的学生成绩管理系统_第1页
编写的简单的学生成绩管理系统_第2页
编写的简单的学生成绩管理系统_第3页
编写的简单的学生成绩管理系统_第4页
编写的简单的学生成绩管理系统_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include<iostream> #include<string> #include<iomanip> #include<fstream> using namespace std; class CData public: CData(); virtual int comparename(CData &) =0; virtual void show()=0; virtual CData(); ; class CNode public: CNode()pdata=0;pnext=0; CNode(CNode &n); void i

2、nputdata(CData *pd)pdata=pd; void shownode()pdata->show(); CData *getdata()return pdata; friend class CList; private: CData *pdata; CNode *pnext; ; CNode:CNode(CNode &n) pdata=n.pdata; pnext=n.pnext; class CList public: CList()phead=0; CList()deletelist(); void addnode(CNode *pnode); void del

3、etelist(); CNode *deletenode(CNode *pnode); CNode *lookup(CData &data); CNode *getlisthead()return phead; void showlist(); CNode *getnext(CNode *pnode); private: CNode * phead; ; void CList:addnode(CNode *pnode) if(phead=0) phead=pnode; pnode->pnext=0; return; else pnode->pnext=phead; phea

4、d=pnode; void CList:deletelist() CNode *p1,*p2; p1=phead; while(p1) delete p1->pdata; p2=p1; p1=p1->pnext; delete p2; CNode *CList:deletenode(CNode *pnode) CNode *p1,*p2; p1=phead; while(p1!=pnode&&p1->pnext!=0) p2=p1; p1=p1->pnext; if(p1=phead) phead=phead->pnext; return pnod

5、e; p2->pnext=p1->pnext; return pnode; CNode *CList:lookup(CData &data) CNode *p1=phead; while(p1) if(p1->pdata->comparename(data)=0) return p1; p1=p1->pnext; return 0; void CList:showlist() if(phead=0) cout<<"对不起,没有任何记录.n" else CNode *p=phead; while(p) p->pdata-

6、>show(); p=p->pnext; CNode *CList:getnext(CNode *pnode) CNode *p=pnode; p=p->pnext; return p; class Student:public CData private: char s_class17; char s_num17; char s_name17; double ele_technique; double c_program; double mul_technique; double col_english; double sen_math; double col_gym; d

7、ouble marx_economy; double average; public: Student(); virtual int comparename(CData &); void show(); void set(char *c,char*n,char *nam,double e,double cp, double m,double ce,double sm,double cg,double mar,double aver); ; Student:Student() strcpy(s_class,"0"); strcpy(s_num,"0"

8、;); strcpy(s_name,"0"); ele_technique=0; c_program=0; mul_technique=0; col_english=0; sen_math=0; col_gym=0; marx_economy=0; int Student:comparename(CData &data) Student &temp=(Student &)data; return strcmp(s_name,temp.s_name); void Student:show() cout<<setw(7)<<s_c

9、lass<<setw(12)<<s_num<<setw(12)<<s_name; cout<<setw(6)<<ele_technique<<setw(6)<<c_program<<setw(6)<<mul_technique; cout<<setw(6)<<col_english<<setw(6)<<sen_math<<setw(6)<<col_gym; cout<<setw(6)<&

10、lt;marx_economy<<" "<<setw(3)<<average<<endl; void Student:set(char *c,char*n,char *nam,double e,double cp,double m,double ce,double sm,double cg,double mar,double aver) strcpy(s_class,c); strcpy(s_num,n); strcpy(s_name,nam); ele_technique=e; c_program=cp; mul_techn

11、ique=m; col_english=ce; sen_math=sm; col_gym=cg; marx_economy=mar; average=aver; void print() cout<<setw(7)<<"class"<<setw(12)<<"number"<<setw(12)<<"name" cout<<setw(6)<<"ele"<<setw(6)<<"C+"

12、<<setw(6)<<"media" cout<<setw(6)<<"eng"<<setw(6)<<"math"<<setw(6)<<"gym" cout<<setw(6)<<"marx"<<setw(6)<<"aver"<<endl; void display(CList &stulist) print(); s

13、tulist.showlist(); cout<<endl; cout<<"按任意键返回主菜单" getchar();getchar(); void add(CList &stulist) CNode *p; Student *s; char c17,n17,nam17; double e,cp,m,ce,sm,cg,mar;float aver; cout<<"请输入姓名(输入0结束):" cin.ignore(); cin.getline(nam,17); while(strcmp(nam,"0&

14、quot;) cout<<"输入学号:"cin.getline(n,17); cout<<"输入班级:"cin.getline(c,17); cout<<"输入计算机成绩:"cin>>e; cout<<"输入大学英语成绩:"cin>>ce; cout<<"输入高等数学成绩:"cin>>sm; aver=(e+cp+m+ce+sm)*0.8/5+cg*0.15+mar*0.05); s=new Stud

15、ent; s->set(c,n,nam,e,cp,m,ce,sm,cg,mar,aver); p=new CNode; p->inputdata(s); stulist.addnode(p); cout<<"记录添加成功."<<endl; cout<<"请输入姓名(输入0结束):" cin.ignore(); cin.getline(nam,17); void lookup(CList &stulist) CNode *plook; char name17; cout<<"请输

16、入你要查找的姓名(输入0结束):" cin.ignore(); cin.getline(name,17); while(strcmp(name,"0") Student s; s.set("0","0",name,0,0,0,0,0,0,0,0); plook=stulist.lookup(s); if(plook) print(); plook->shownode(); else cout<<"对不起,在学生记录中查找不到"<<name<<"的记录.&

17、quot;<<endl; cout<<"请输入你要查找的姓名(输入0结束):" cin.getline(name,17); void deletes(CList &stulist) CNode *plook; char name17; cout<<"请输入要删除的记录的学生姓名(输入0结束):" cin.ignore(); cin.getline(name,17); while(strcmp(name,"0") Student s; s.set("0","0&q

18、uot;,name,0,0,0,0,0,0,0,0); plook=stulist.lookup(s); if(plook) print(); plook->shownode(); stulist.deletenode(plook); cout<<name<<"的记录已经删除.n" else cout<<"对不起,在学生记录中查找不到"<<name<<"的记录.n"<<endl; cout<<"请输入要删除的记录的学生姓名(输入0结束)

19、:" cin.getline(name,17); void storefile(CList &stulist) ofstream outfile("student.dat",ios:binary); if(!outfile) cout<<"数据文件打开错误,数据存入文件失败!"<<endl; return; CNode *p; Student *s; p=stulist.getlisthead(); while(p) s=(Student *)p->getdata(); outfile.write(char

20、 *)s,sizeof(Student); p=stulist.getnext(p); outfile.close(); void loadfile(CList &stulist) ifstream infile("student.dat",ios:binary); if(!infile) cout<<"没有数据文件!"<<endl; return; CNode *p; Student *s; while(! infile.eof() s=new Student; infile.read(char *)s,sizeof(Student); p=new CNode; p->inputdata(s); stulist.addnode(p); stulist.deletenode(p); infile.close(); void operate(CList &stulist) int choice; do system("cls")

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论