C++学生成绩管理系统课程设计报告.docx
- 文档编号:24248900
- 上传时间:2023-05-25
- 格式:DOCX
- 页数:26
- 大小:69.29KB
C++学生成绩管理系统课程设计报告.docx
《C++学生成绩管理系统课程设计报告.docx》由会员分享,可在线阅读,更多相关《C++学生成绩管理系统课程设计报告.docx(26页珍藏版)》请在冰豆网上搜索。
C++学生成绩管理系统课程设计报告
一.目的与要求
通过本课程设计的实践,全面总结C++课程学习中的的数据类型、程序结构、数组、函数、指针、结构体、链表等基本概念,掌握其使用方法。
掌握面向对象程序设计中有关类、对象、继承、重载、多态性、输入输出流类体系、文件操作的基本概念,初步学会用类与对象这种面向对象的程序设计方法编写应用程序。
培养使用面向对象的程序设计方法编写计算机程序的能力。
通过设计一个《学生成绩统计管理》,进一步熟悉C++中类的概念、类的封装、继承的实现方式。
了解系统开发的需求分析、类层次设计、模块分解、编码测试、模块组装与整体调试的全过程,加深对C++的理解与VisualC++环境的使用;逐步熟悉程序设计的方法,并养成良好的编程习惯。
程序设计是一门实践性很强的课程,必须十分重视实践环节。
许多实际的知识不是靠听课和看书学到的,而是通过长时间的实践积累的。
一、设计内容
学生成绩管理系统
1.基本功能:
这个程序的主要功能是输入学生姓名、成绩,学号,并可以对学生的成绩按学号进行查询。
该系统具有存贮学生数据,按学号按需要修改学生成绩,列出学生成绩和统计功能。
2.扩展功能:
学生数据的添加、修改、与删除
2.E—R
二、过程与结果
主要内容如下:
1.关键类的设计,继承层次关系,代码:
首先,创建了一个student类.Student类的声明如下:
classStudent{
public:
intClass,num;
charname[8];
floatcpp,math,eng,ave;
intorder;
Student*next;
public:
Student(){}
Student(intc1,intn1,char*n,floate1,floatc2,floatm,floate2,floats,floatp,floata,
into,Student*next=NULL)
{
Class=c1;num=n1;
strcpy(name,n);
cpp=c2;math=m;eng=e2;ave=a;
order=o;
this->next=next;
}
主要功能函数的设计:
1.创建学生数据,对学生的成绩的录入。
代码:
friendStudent*Create(Student*head,istream&in)
{inty;
Student*p;
intClass,num;
charname[8];
floatcpp,math,eng;
if(&in==&cin)
//cout<<"\n\n请输入学生数据(输入成绩非法,则结束),数据输入格式为:
\n"
//<<"班级姓名学号C++数学英语\n";
//in>>Class>>name>>num>>cpp>>math>>eng;
//cout<<"\n\n请输入学生数据:
\n"
cout<<"班级:
"< in>>Class; cout<<"姓名: "< in>>name; cout<<"学号: "< in>>num; cout<<"C++的成绩: "< in>>cpp; cout<<"数学的成绩: "< in>>math; cout<<"英语的成绩: "< in>>eng; /*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)) {*/p=newStudent; p->Class=Class;p->num=num;strcpy(p->name,name); p->cpp=cpp;p->math=math; p->eng=eng; p->ave=(cpp+math+eng)/6; head=Insert(head,p); //in>>Class>>name>>num>>elec>>cpp>>math>>eng>>polity>>sport; cout<<"\t\t*****继续添加请按1*******\n"; cout<<"\t\t*****返回主菜单请按2*******\n"; in>>y; if(y==2) { ShowMenu(); } else{head=Create(head,cin);} SetOrder(head);//设置排名 returnhead; } 2.此函数为查找函数的实现过程 主要代码: friendconstStudent*Lookup(constStudent*head,intnum)//查找指定学号为num的结点 { while(head&&head->num! =num) head=head->next; returnhead; } friendvoidOutputOne(constStudent*head)//输出一个学生数据 { cout< < < < } 3.此函数为删除函数的实现部分。 主要代码: friendStudent*DeleteStudent(Student*head,intnum) { Student*p1=head,*p2=p1; while(p2&&p2->num! =num) p1=p2,p2=p2->next; if(p2) { if(p2==p1) { head=head->next;deletep1; } else { p1->next=p2->next;deletep2; } cout<<"已删除"< SetOrder(head); }elsecout<<"没找到指定学生! \n"; returnhead; } 4.排序函数中平均分来排序,排序结果为降序操作。 friendvoidSetOrder(Student*head) { intorder=1; while(head) {head->order=order++;head=head->next;} } 5.修改学生的信息 friendStudent*Modify(Student*head,intnum)//修改学号为学生的数据 { Student*p1=head,*p2=p1; while(p2&&p2->num! =num)//寻找待修改的结点 p1=p2,p2=p2->next; if(p2)//修改指定结点数据 { /*cout<<"\n\n请输入新数据,格式为: \n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng;*/ cout<<"班级: "< cin>>p2->Class; cout<<"姓名: "< cin>>p2->name; cout<<"学号: "< cin>>p2->num; cout<<"C++的成绩: "< cin>>p2->cpp; cout<<"数学的成绩: "< cin>>p2->math; cout<<"英语的成绩: "< cin>>p2->eng; while(! Valid(p2->cpp)||! Valid(p2->math)||! Valid(p2->eng) ) { cout<<"\n\n成绩数据非法! 请重新输入,格式为: \n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng; } p2->ave=(p2->cpp+p2->math+p2->eng)/3; //将修改的指定结点从原链表上修改下来,并重新降序插入原链表 if(p2==p1) head=Insert(p2->next,p2); else { p1->next=p2->next; head=Insert(head,p2); } SetOrder(head); } elsecout<<"没找到指定学生! \n"; returnhead; } 6.显示数据: friendvoidOutputAll(constStudent*head)//输出所有学生的数据 { if(! head){cout<<"\n\n\t\t没有任何学生数据! \n\n";return;} cout<<"\n\n\t\t学生成绩表\n\n"; cout<<"班级\t姓名\t学号\tC++\t数学\t英语\t名次\n"; while(head) { OutputOne(head);head=head->next; } } 7.平均数据函数 friendvoidStatistic(constStudent*head) { inti=0; float ave_cpp=0, ave_math=0, ave_eng=0; while(head) { ave_cpp+=head->cpp; ave_math+=head->math; ave_eng+=head->eng; i++;head=head->next; } if(! i) { cout<<"\n\n没有任何学生数据! \n";return;} cout<<"\n\n\t\t各门课程平均成绩表\n\n"; cout<<"tC++\t数学\t英语\n"; cout< < } 程序测试结果: 1运行程序.会出现如下画面,按照提示进行选择. 2.首先选择1,然后按Enter键.按照提示对学生情况进行输入.如图: 3.按1键可以添加多个学生成绩的数据,按2返回主界面。 4.选择5,然后按Enter键,显示刚才输入的数据和排名的情况。 5在主界面选择2可以修改学生的数据。 6.在主界面选择3可以按学号查询学生成绩情况 7.在主界面选择7可以按学号删除学生的成绩信息 三、设计总结 这次课程设计基本上涵盖了学习到的C++语言知识点,课程设计题目要求不仅要求对课本虽然是网上搜来的代码,但这些代码没办法运行,我把这些代码改了和增加了自己写的代码,终于可以运行,而且到达自己想要的结果,这次课程设计不仅让我修补了以前学习的漏洞,也让我知道一个道理: 编程需要兴趣和实际动手。 C++语言程序设计课程设计,我从中受益匪浅,并且对C++语言程序设计这一门课程有了更深一步的认识。 附件 程序源代码清单: #include #include classStudent{ public: intClass,num; charname[8]; floatcpp,math,eng,ave; intorder; Student*next; public: Student(){} Student(intc1,intn1,char*n,floate1,floatc2,floatm,floate2,floats,floatp,floata, into,Student*next=NULL) { Class=c1;num=n1; strcpy(name,n); cpp=c2;math=m;eng=e2;ave=a; order=o; this->next=next; } friendintValid(floatscore) { return(score<0||score>100)? 0: 1; } friendvoidSetOrder(Student*head) { intorder=1; while(head) {head->order=order++;head=head->next;} } friendStudent*Insert(Student*head,Student*p)//在head所指的链表中降序插入结点p { Student*p1,*p2; if(head==0) { head=p;p->next=0; } elseif(head->ave<=p->ave) { p->next=head;head=p; } else { p2=p1=head; while(p2->next&&p2->ave>p->ave) { p1=p2;p2=p2->next; } if(p2->ave>p->ave) { p2->next=p;p->next=0; } else{ p->next=p2;p1->next=p; } } returnhead; } friendStudent*Create(Student*head,istream&in) {inty; Student*p; intClass,num; charname[8]; floatcpp,math,eng; if(&in==&cin) //cout<<"\n\n请输入学生数据(输入成绩非法,则结束),数据输入格式为: \n" //<<"班级姓名学号C++数学英语\n"; //in>>Class>>name>>num>>cpp>>math>>eng; //cout<<"\n\n请输入学生数据: \n" cout<<"班级: "< in>>Class; cout<<"姓名: "< in>>name; cout<<"学号: "< in>>num; cout<<"C++的成绩: "< in>>cpp; cout<<"数学的成绩: "< in>>math; cout<<"英语的成绩: "< in>>eng; /*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)) {*/p=newStudent; p->Class=Class;p->num=num;strcpy(p->name,name); p->cpp=cpp;p->math=math; p->eng=eng; p->ave=(cpp+math+eng)/6; head=Insert(head,p); //in>>Class>>name>>num>>elec>>cpp>>math>>eng>>polity>>sport; cout<<"\t\t*****继续添加请按1*******\n"; cout<<"\t\t*****返回主菜单请按2*******\n"; in>>y; if(y==2) { ShowMenu(); } else{head=Create(head,cin);} SetOrder(head);//设置排名 returnhead; } friendconstStudent*Lookup(constStudent*head,intnum)//查找指定学号为num的结点 { while(head&&head->num! =num) head=head->next; returnhead; } friendvoidOutputOne(constStudent*head)//输出一个学生数据 { cout< < < < } friendvoidOutputAll(constStudent*head)//输出所有学生的数据 { if(! head){cout<<"\n\n\t\t没有任何学生数据! \n\n";return;} cout<<"\n\n\t\t学生成绩表\n\n"; cout<<"班级\t姓名\t学号\tC++\t数学\t英语\t名次\n"; while(head) { OutputOne(head);head=head->next; } } friendStudent*Modify(Student*head,intnum)//修改学号为学生的数据 { Student*p1=head,*p2=p1; while(p2&&p2->num! =num)//寻找待修改的结点 p1=p2,p2=p2->next; if(p2)//修改指定结点数据 { /*cout<<"\n\n请输入新数据,格式为: \n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng;*/ cout<<"班级: "< cin>>p2->Class; cout<<"姓名: "< cin>>p2->name; cout<<"学号: "< cin>>p2->num; cout<<"C++的成绩: "< cin>>p2->cpp; cout<<"数学的成绩: "< cin>>p2->math; cout<<"英语的成绩: "< cin>>p2->eng; while(! Valid(p2->cpp)||! Valid(p2->math)||! Valid(p2->eng) ) { cout<<"\n\n成绩数据非法! 请重新输入,格式为: \n" <<"班级姓名学号C++数学英语\n"; cin>>p2->Class>>p2->name>>p2->num>>p2->cpp>>p2->math >>p2->eng; } p2->ave=(p2->cpp+p2->math+p2->eng)/3; //将修改的指定结点从原链表上修改下来,并重新降序插入原链表 if(p2==p1) head=Insert(p2->next,p2); else { p1->next=p2->next; head=Insert(head,p2); } SetOrder(head); } elsecout<<"没找到指定学生! \n"; returnhead; } friendStudent*DeleteStudent(Student*head,intnum) { Student*p1=head,*p2=p1; while(p2&&p2->num! =num) p1=p2,p2=p2->next; if(p2) { if(p2==p1) { head=head->next;deletep1; } else { p1->next=p2->next;deletep2; } cout<<"已删除"< SetOrder(head); }elsecout<<"没找到指定学生! \n"; returnhead; } friendvoidStatistic(constStudent*head) { inti=0; float ave_cpp=0, ave_math=0, ave_eng=0; while(head) { ave_cpp+=head->cpp; ave_math+=head->math; ave_eng+=head->eng; i++;head=head->next; } if(! i) { cout<<"\n\n没有任何学生数据! \n";return;} cout<<"\n\n\t\t各门课程平均成绩表\n\n"; cout<<"tC++\t数学\t英语\n"; cout< < } friendvoidDeleteChain(Student*head)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 学生 成绩管理系统 课程设计 报告