一.目的与要求通过本课程设计的实践,全面总结C++课程学习中的的数据类型、程序结构、数组、函数、指针、结构体、链表等基本概念,掌握其使用方法掌握面向对象程序设计中有关类、对象、继承、重载、多态性、输入输出流类体系、文件操作的基本概念,初步学会用类与对象这种面向对象的程序设计方法编写应用程序培养使用面向对象的程序设计方法编写计算机程序的能力通过设计一个《学生成绩统计管理》,进一步熟悉C++中类的概念、类的封装、继承的实现方式了解系统开发的需求分析、类层次设计、模块分解、编码测试、模块组装与整体调试的全过程,加深对C++的理解与Visual C++环境的使用;逐步熟悉程序设计的方法,并养成良好的编程习惯程序设计是一门实践性很强的课程,必须十分重视实践环节许多实际的知识不是靠听课和看书学到的,而是通过长时间的实践积累的一、 设计内容学生成绩管理系统1. 基本功能: 这个程序的主要功能是输入学生姓名、成绩,学号,并可以对学生的成绩按学号进行查询该系统具有存贮学生数据,按学号按需要修改学生成绩,列出学生成绩和统计功能2. 扩展功能:学生数据的添加、修改、与删除2.E—R修改数据删除数据查询数据显示数据平均数据添加数据学生成绩管理系统 二、 过程与结果主要内容如下:1. 关键类的设计,继承层次关系,代码:首先,创建了一个student类. Student类的声明如下:class Student{public: int Class,num; char name[8]; float cpp,math,eng,ave; int order; Student *next;public: Student() {} Student(int c1,int n1,char*n,float e1,float c2,float m,float e2,float s,float p,float a, int o,Student *next=NULL) { Class=c1;num=n1; strcpy(name,n); cpp=c2;math=m;eng=e2;ave=a; order=o; this->next=next; } 主要功能函数的设计:1. 创建学生数据,对学生的成绩的录入。
代码:friend Student *Create(Student *head,istream& in) {int y; Student *p; int Class,num; char name[8]; float cpp,math,eng; if(&in==&cin) //cout<<"\n\n请输入学生数据(输入成绩非法,则结束),数据输入格式为:\n" //<<"班级 姓名 学号 C++ 数学 英语 \n"; //in>>Class>>name>>num>>cpp>>math>>eng; //cout<<"\n\n请输入学生数据:\n" cout<<"班级:"<>Class; cout<<"姓名:"<>name; cout<<"学号:"<>num; cout<<"C++的成绩:"<>cpp; cout<<"数学的成绩:"<>math; cout<<"英语的成绩 :"<>eng; /*while(Valid(elec)&&Valid(cpp)&&Valid(math)&&Valid(eng)&&Valid(sport)&&Valid(polity)) {*/p=new Student; 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); //设置排名 return head; } 2. 此函数为查找函数的实现过程 主要代码:friend const Student * Lookup(const Student *head,int num) //查找指定学号为num的结点 { while(head && head->num!=num) head=head->next; return head; } friend void OutputOne(const Student* head) //输出一个学生数据 { cout<Class<<'\t'<name<<'\t'<num<<'\t' <cpp<<'\t'<math<<'\t' <eng<<'\t' <order<
主要代码:friend Student *DeleteStudent(Student *head,int num) { Student *p1=head,*p2=p1; while(p2&&p2->num!=num) p1=p2,p2=p2->next; if(p2) { if(p2==p1) { head=head->next;delete p1; } else { p1->next=p2->next;delete p2; } cout<<"已删除"<order=order++;head=head->next;} }5.修改学生的信息friend Student *Modify(Student *head,int num) //修改学号为学生的数据 { 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<<"班级:"<>p2->Class; cout<<"姓名:"<>p2->name; cout<<"学号:"<>p2->num; cout<<"C++的成绩:"<>p2->cpp; cout<<"数学的成绩:"<>p2->math; cout<<"英语的成绩 :"<>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); } else cout<<"没找到指定学生!\n"; return head; } 6.显示数据: friend void OutputAll(const Student*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.平均数据函数 friend void Statistic(const Student *head) { int i=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没有任何。