#include <iostream> #include <string> #include <set> #include <fstream> #include <cstdlib> #include <vector> #include <windows.h> #include <algorithm> using namespace std; class score //分数 { public: int s_total; int s_ave; int s_sum; }; class course //课程信息 { public: int cou_id; string cou_name; int mark; //分数 }; class student:public score //学生信息 { public: string name; string sex; int std_id; int s_normal; //平时成绩 double per; //平时成绩所占百分比 int m; //该学生选课的门数 vector<course> cour; //该学生所选的课 }; bool operator < (const student &stu1,const student &stu2) { return stu1.std_id> stu2.std_id; } class grades //班级 { public: string major; int cla_id; int peop_num; multiset<student> stu; void fread(int n); //对成绩的录入,n个学生 void revise(int t_ID); //根据学号修改学生信息 void display(void); //打印班级成绩单 void seek(int t_ID); //查找 void failshow(void); //打印不及格学生名单 }; void grades::failshow() { ofstream outfile("outn.dat",ios::out); multiset<student>::iterator iter; for(iter=stu.begin();iter!=stu.end();iter++) { if((*iter).s_ave<60) outfile<<(*iter).name<<" "<<(*iter).std_id<<" "<<endl; } outfile.close(); cout<<"完成:输出到:./outn.dat"<<endl; } void grades::seek(int t_ID) //查找学号为t_ID的学生 { student temstu; temstu.std_id=t_ID; multiset<student>::iterator iter=stu.find(temstu); if(iter!=stu.end()) { cout<<"姓名: "<<(*iter).name<<"学号:"<<(*iter).std_id<<endl; for(int i=0;i<(*iter).m;i++) { cout<<(*iter).cour.at(i).cou_name<<": "<<(*iter).cour.at(i).mark; } cout<<"总成绩:"<<(*iter).s_sum<<"综评成绩:"<<(*iter).s_total<<endl; } else cout<<"找不到该学生"<<endl; } void grades::display(void) //输出班级成绩单 { multiset<student>::iterator iter; ofstream outfile("out.dat",ios::out); if(!outfile) { cout<<"open error"<<endl; exit(1); } outfile<<"专业:"<<major<<"班级:"<<cla_id<<"人数"<<peop_num<<endl; outfile<<"姓名 "<<"性别 "<<"学号 "<<"各科成绩 "<<"总成绩 "<<"综评成绩 "<<endl; for(iter=stu.begin();iter!=stu.end();iter++) { outfile<<(*iter).name<<" "<<(*iter).sex<<" "<<(*iter).std_id<<" "; for(int i=0;i<(*iter).m;i++) outfile<<(*iter).cour.at(i).cou_name<<" "<<(*iter).cour.at(i).mark<<" "; outfile<<" "<<(*iter).s_sum<<" "<<(*iter).s_total<<" "<<endl; } outfile.close(); cout<<"完成,输出到:./out.dat"<<endl; } void grades::fread(int n) { student tem; course t; ifstream infile("in.dat",ios::in); if(!infile) { cout<<"open error !"<<endl; exit (1); } for(int i=0;i<n;i++) { infile>>tem.name>>tem.sex>>tem.std_id>>tem.per>>tem.s_normal; //设置学生信息 infile>>tem.m; tem.s_sum=0; for(int j=0;j<tem.m;j++) { infile>>t.cou_id>>t.cou_name>>t.mark; tem.s_sum+=t.mark; //总分 tem.cour.push_back(t); } tem.s_ave=(tem.s_sum)/tem.m; //平均分 tem.s_total=tem.s_normal*tem.per+tem.s_sum*(1-tem.per); //总评成绩 stu.insert(tem); } infile.close(); } void grades::revise(int t_ID) { student temstu; temstu.std_id=t_ID; temstu.s_sum=0; vector<course>::iterator i; multiset<student>::iterator iter=stu.find(temstu); if(iter!=stu.end()) { cout<<"请输入要修改的学生信息"<<endl; /*for(i=(*iter).cour.begin();i!=(*iter).cour.end();i++) { cout<<(*iter).cour.at(i).cou_name<<":"<<endl; cin>>temstu.cour.at(i).mark; temstu.s_sum+=temstu.cour.at(i).mark; }*/ cout<<"平时成绩"<<endl; cin>>temstu.s_normal; cout<<"平时成绩所占百分比"<<endl; cin>>temstu.per; temstu.s_ave=temstu.s_sum/temstu.m; temstu.s_total=temstu.s_normal*temstu.per+temstu.s_sum*(1-temstu.per); cout<<"姓名"<<endl; cin>>temstu.name; cout<<"性别:"<<endl; cin>>temstu.sex; stu.erase(iter); //删除旧元素 stu.insert(temstu); //插入新元素 cout<<"修改完成"<<endl; } else cout<<"找不到该学生"<<endl; } int main() { system("color d0"); int c; int t; grades cla; cout<<"********************************************************************************"<<endl; cout<<"********************************学生管理系统************************************"<<endl; cout<<"请输入学生人数:"<<endl; cin>>cla.peop_num; cout<<"请输入专业:"<<endl; cin>>cla.major; cout<<"请输入班级"<<endl; cin>>cla.cla_id; cla.fread(cla.peop_num); while(1) { system("cls"); cout<<"********************************************************************************"<<endl; cout<<"********************************************************************************"<<endl; cout<<" ~~~~~~~~~1_修改学生信息~~~~~~~~~"<<endl; cout<<" ~~~~~~~~2_打印班级成绩单~~~~~~~~"<<endl; cout<<" ~~~~~~~~3_打印个人成绩单~~~~~~~~"<<endl; cout<<" ~~~~~~4_打印不及格学生名单~~~~~~"<<endl; cout<<" ~~~~~~~~~~~~~~5_退出~~~~~~~~~~~~"<<endl; cin>>c; switch (c) { case 1: cout<<"请输入要修改的学生学号:"; cin>>t; cla.revise(t); break; case 2: cla.display(); break; case 3: cout<<"请输入要打印的学生学号:"; cin>>t; cla.seek(t); break; case 4: cla.failshow(); break; case 5: return 0; default: cout<<"输入错误!"<<endl; } system("pause"); } return 0; }