用C++语言编写程序
设计一个学生成绩排名系统,该系统的主要功能如下:1)具备对成绩的管理功能(添加、删除、排序)2)具备对成绩的统计功能(最高分,最低分,平均分,及格率等)3)具备按学号、姓...
设计一个学生成绩排名系统,该系统的主要功能如下:1) 具备对成绩的管理功能(添加、删除、排序)2) 具备对成绩的统计功能(最高分,最低分,平均分,及格率等)3) 具备按学号、姓名、或课程名查询成绩的功能。备注:成绩记录以下信息:班级,学号,姓名,课程名,成绩(百分制)。
展开
1个回答
2013-12-02
展开全部
/*********************************************Student.h********************************************/#ifndef _STUDENT_H_#define _STUDENT_H_#include<string>class CStudent{private:std::string strName;double chinese;double math;double english;public:CStudent();CStudent(std::string Name,double c,double m,double e);void SetChinese(double a);void SetMath(double a);void SetEnglish(double a);void SetName(std::string a);std::string returnName();double returnChinese();double returnMath();double returnEnglish();double returnTotalPerformance();double returnAverage();~CStudent(){};};#endif/********************************************************student.cpp********************************/#include<iostream>#include "Student.h"#include<vector>using namespace std;CStudent::CStudent(){strName="General Student";chinese=0;english=0;math=0;}CStudent::CStudent(std::string Name,double c,double m,double e){strName=Name;chinese=c;math=m;english=e;}void CStudent::SetEnglish(double a){english=a;}void CStudent::SetChinese(double a){chinese=a;}void CStudent::SetMath(double a){math=a;}double CStudent::returnChinese(){return chinese;}double CStudent::returnEnglish(){return english;}double CStudent::returnMath(){return math;}double CStudent::returnTotalPerformance(){return chinese+math+english;}double CStudent::returnAverage(){return (chinese+math+english)/3;}string CStudent::returnName(){return strName;}
void inputStudentInfo(std::vector<CStudent>& vec)//输入函数{int a=1;//输入控制,1是继续输入,0是退出//输入CStudent temp;//临时学生对象double b;//临时double变量,用于输入成绩数据char c[20];//临时字符窜变量,用于输入学生姓名std::cout<<"Enter number 1for input students' information:\nnumber 0 for end of input:\n";while(a){std::cin>>a;if(a==1){std::cout<<"Input student's name:\n";std::cin>>c;//输入姓名temp.SetName(c);//临时学生对象填写姓名std::cout<<"Input chinese:\n";std::cin>>b;temp.SetChinese(b);std::cout<<"Input english\n";std::cin>>b;temp.SetEnglish(b);std::cout<<"Input math:\n";std::cin>>b;temp.SetMath(b);vec.push_back(temp);//将临时学生变量复制到学生对象中}else continue;std::cout<<"Enter number 1 for input students' information:\nnumber 0 for end of input:\n";}}
int findStudenr(std::vector<CStudent>&vec,//将向量以引用的形式传递进入函数体
std::vector<CStudent>::iterator it,//向量的迭代器引用std::string str)//接收待查询的学生姓名字符窜{for(it=vec.begin();it!=vec.end();it++){if(str==(*it).returnName()){return 1;break;}}it=NULL;return 0;}
void InsertSort(std::vector<CStudent>& vec)//传递一个学生向量{CStudent temp;//设置"哨兵"为临时对象for(int i=1;i<vec.size();i++){if(vec[i].returnTotalPerformance()<vec[i-1].returnTotalPerformance()){temp=vec[i];for(int j=i-1;temp.returnTotalPerformance()<vec[j].returnTotalPerformance();--j)//每个学生记录总分都跟"哨兵"总分相比{vec[j+1]=vec[i];//向量总的学生记录逐个后移}vec[j+1]=temp;//比较完毕,插入到正确位置}}}/***************************************************main.cpp********************************************/#include<iostream>#include<vector>#include "Student.h"void inputStudentInfo(std::vector<CStudent>& vec);//使用到的函数声明int findStudent(std::vector<CStudent>& vec,std::vector<CStudent>::iterator& it,std::string str);void InsertSort(std::vector<CStudent>& vec);int main(){std::vector<CStudent>classes1;//创建学生向量std::vector<CStudent>::iterator iter;//创建向量迭代器inputStudentInfo(classes1);//输入学生信息std::cout<<"Enter the name you want to check:"<<std::endl;char a[20];std::cin>>a;if(findStudent(classes1,iter,a))//找到指定姓名的学生{std::cout<<iter->returnName()<<"performance:\n"//输出该学生的相关信息<<"Chinese:"<<iter->returnChinese()<<"\nMath:"<<iter->returnMath()<<"\nEnglish:"<<iter->returnEnglish()<<std::endl;}else{std::cout<<"No fount!\n";}InsertSort(classes1);//对这些学生的总成绩排序int i;std::cout<<"All students' performance descend by total performance:\n";for(iter=classes1.begin(),i=1;iter!=classes1.end();iter++,i++){//打印总分排序后的学生信息std::cout<<" The rank "<<i<<" is :"<<std::endl;std::cout<<iter->returnName()<<std::endl;std::cout<<iter->returnTotalPerformance()<<std::endl;}std::cin.get();std::cin.get();return 0;}
void inputStudentInfo(std::vector<CStudent>& vec)//输入函数{int a=1;//输入控制,1是继续输入,0是退出//输入CStudent temp;//临时学生对象double b;//临时double变量,用于输入成绩数据char c[20];//临时字符窜变量,用于输入学生姓名std::cout<<"Enter number 1for input students' information:\nnumber 0 for end of input:\n";while(a){std::cin>>a;if(a==1){std::cout<<"Input student's name:\n";std::cin>>c;//输入姓名temp.SetName(c);//临时学生对象填写姓名std::cout<<"Input chinese:\n";std::cin>>b;temp.SetChinese(b);std::cout<<"Input english\n";std::cin>>b;temp.SetEnglish(b);std::cout<<"Input math:\n";std::cin>>b;temp.SetMath(b);vec.push_back(temp);//将临时学生变量复制到学生对象中}else continue;std::cout<<"Enter number 1 for input students' information:\nnumber 0 for end of input:\n";}}
int findStudenr(std::vector<CStudent>&vec,//将向量以引用的形式传递进入函数体
std::vector<CStudent>::iterator it,//向量的迭代器引用std::string str)//接收待查询的学生姓名字符窜{for(it=vec.begin();it!=vec.end();it++){if(str==(*it).returnName()){return 1;break;}}it=NULL;return 0;}
void InsertSort(std::vector<CStudent>& vec)//传递一个学生向量{CStudent temp;//设置"哨兵"为临时对象for(int i=1;i<vec.size();i++){if(vec[i].returnTotalPerformance()<vec[i-1].returnTotalPerformance()){temp=vec[i];for(int j=i-1;temp.returnTotalPerformance()<vec[j].returnTotalPerformance();--j)//每个学生记录总分都跟"哨兵"总分相比{vec[j+1]=vec[i];//向量总的学生记录逐个后移}vec[j+1]=temp;//比较完毕,插入到正确位置}}}/***************************************************main.cpp********************************************/#include<iostream>#include<vector>#include "Student.h"void inputStudentInfo(std::vector<CStudent>& vec);//使用到的函数声明int findStudent(std::vector<CStudent>& vec,std::vector<CStudent>::iterator& it,std::string str);void InsertSort(std::vector<CStudent>& vec);int main(){std::vector<CStudent>classes1;//创建学生向量std::vector<CStudent>::iterator iter;//创建向量迭代器inputStudentInfo(classes1);//输入学生信息std::cout<<"Enter the name you want to check:"<<std::endl;char a[20];std::cin>>a;if(findStudent(classes1,iter,a))//找到指定姓名的学生{std::cout<<iter->returnName()<<"performance:\n"//输出该学生的相关信息<<"Chinese:"<<iter->returnChinese()<<"\nMath:"<<iter->returnMath()<<"\nEnglish:"<<iter->returnEnglish()<<std::endl;}else{std::cout<<"No fount!\n";}InsertSort(classes1);//对这些学生的总成绩排序int i;std::cout<<"All students' performance descend by total performance:\n";for(iter=classes1.begin(),i=1;iter!=classes1.end();iter++,i++){//打印总分排序后的学生信息std::cout<<" The rank "<<i<<" is :"<<std::endl;std::cout<<iter->returnName()<<std::endl;std::cout<<iter->returnTotalPerformance()<<std::endl;}std::cin.get();std::cin.get();return 0;}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询