一个实现统计班级分数排名的系统...

#include<iostream> #include<algorithm> #include<stdlib.h> #include<string> #include<fstream> using namespace std; int count_user,count_classes,count_language,count_submit; class student_user//定义学生信息. { public: string num;//定义学生学号..... string classnum;//定义班级类别..... string sex;//定义性别..... string name;//定义学生姓名...... string cs;//定义学生属于的系别..... int if_mark;//满足条件的mark..... int right[1000];//正确提交题目标记为1..... int score;//学生的分数总和....... }; int cmp(const student_user &a,const student_user &b)//定义cmp函数,来调用比较排序按分数高到低排..... { return a.score>b.score; } class Language//定义提交语言的信息..... { public: int number; string Language_name;//语言的名称.... string Language_kinds;//语言的种类.... }; class classes { public: string number; string cs; }; class submit { public: int submit_number;//提交的题目编号.... int language_number;//提交语言的的编号.... int problem_num;//提交题目列表..... string student_xuehao;//提交学生的学号.... string submit_time;//提交学生的时间.... string submit_year; string result;//学生提交的结果... }; /*文件的输入信息*/ void Initstudent_user(student_user *stu)//从文件输入用户信息..... { //cout<<"学号 班级编号 姓名 性别"<<endl; ifstream f1("users.in"); int i=1; while(f1>>stu[i].num) { f1>>stu[i].classnum; f1>>stu[i].name; f1>>stu[i].sex; i++; } count_user=i-1; } void Initclasses(classes *cl)//从文件输入班级信息.... { //cout<<"编号*** ***描述"<<endl; int i=1; ifstream f2("classes.in"); while(f2>>cl[i].number) { f2>>cl[i].cs; i++; } count_classes=i-1; } void Initlanguage(Language *La)//从文件读入语言信息,有3种语言.... { ifstream f3("language.in"); int i=1; while(f3>>La[i].number) { f3>>La[i].Language_name; f3>>La[i].Language_kinds; } count_language=i-1; } void Initsubmit(submit *sub)//从文件读入提交信息...... { ifstream f4("exsubmits.in"); int i=1; while(f4>>sub[i].submit_number)//输入提交者的题目编号.. { f4>>sub[i].language_number;//输入提交题目的语言编号. f4>>sub[i].problem_num;//输入提交者题目编号.. f4>>sub[i].student_xuehao;;//输入提交者的学号.. f4>>sub[i].submit_year;//输入提交者的年份... f4>>sub[i].submit_time;//输入提交者的时间... f4>>sub[i].result;//输入提交者 的结果.. i++; } count_submit=i-1; } void Initscore(student_user *stu)//学生成绩分数的初始化...... { int i,j; for(i=1;i<=count_user;i++) { stu[i].score=0;//初始成绩都等于0..... stu[i].if_mark=0; } for(i=1;i<=count_user;i++) { for(j=1;j<=1000;j++) { stu[i].right[j]=0;//开始状态每个用户提交题目的正确数为0... } } } int read_language()//语言读入的选择...... { cout<<" __________________________^^^^^^^^^^^^_________________________ "<<endl; cout<<" * *"<<endl; cout<<" * @编号 @名称 @语言类型 *"<<endl; cout<<" * *"<<endl; cout<<" * 1 Java语言 java *"<<endl; cout<<" * *"<<endl; cout<<" * 2 GNU C语言 GNU C *"<<endl; cout<<" * *"<<endl; cout<<" * 3 GNU C++语言 GNU C++ *"<<endl; cout<<" * *"<<endl; cout<<" *________________________^^^^^^^^^^^^^__________________________*"<<endl; cout<<" 请您输入要进行统计的语言的编号:"; int num; cin>>num; cout<<endl; return num; } string get_startyear(submit *sub)//读入提交者的开始日期.... { system("cls"); cout<<"................................................................."<<endl; string years; cout<<"******************可 以 选 择 的 时 期 范 围*********************"<<endl; cout<<"开始日期和时间:"; cout<<sub[1].submit_year<<" "<<sub[1].submit_time<<endl; cout<<"结束时期和时间:"; cout<<sub[count_submit].submit_year<<" "<<sub[count_submit].submit_time<<endl; cout<<" ................................................................"<<endl; cout<<" 备注: 日期的输入格式为:xxxx-xx-xx"<<endl; cout<<" 备注:时间的输入格式为:xx-xx-xx"<<endl; cout<<" 请按正确的格式输入否则不能统计出正确的结果!"<<endl; cout<<" 输入包括两个部分日期和时间输入日期或时间后请按回车"<<endl; cout<<"请输入开始日期:"; cin>>years; return years; } string get_endyear()//读入提交者的结束日期..... { string endyear; cout<<"请输入结束日期:"; cin>>endyear; return endyear; } string get_time()//读入提交者的开始时间... { string times; cout<<"请输入开始时间:"; cin>>times; cout<<endl; return times; } string get_endtime()//读入提交者的结束时间...... { string endtime; cout<<"请输入结束时间:"; cin>>endtime; cout<<endl; return endtime; } void check_classes(classes *cl,student_user *stu)//通过学生的班级学号来检查系别. { int i,j; for(i=1;i<=count_user;i++) { for(j=1;j<=count_classes;j++) { if(stu[i].classnum==cl[j].number) { stu[i].cs=cl[j].cs; break; } } } } int check_student(submit *sub,student_user *stu,string s)//通过学号来找到学生..... { int i; int t; for(i=1;i<=count_user;i++) { if(stu[i].num==s) { t=i; break; } } return t; } void check_run(submit *sub,student_user *stu,int lan_num,string startyear,string starttime,string endyear,string endtime) { int i,f; string g; string start; string end; start=startyear+starttime; end=endyear+endtime; string temp; for(i=1;i<=count_submit;i++) { temp=sub[i].submit_year+sub[i].submit_time; if(sub[i].language_number==lan_num&&(temp>=start&&temp<=end)) { f=sub[i].problem_num;//提交题目的列表.... g=sub[i].student_xuehao; int t; t=check_student(sub,stu,g);//检查出提交者... stu[t].if_mark=1; if(sub[i].result=="OK!") { if(stu[t].right[f]!=1)//如果提交者在这道题上没有提交正确过,就进行... { stu[t].score=stu[t].score+10; stu[t].right[f]=1;//表示提交者在这道题目上已经提交正确过.... } } } else if(temp>end)break; } } void Out(student_user *stu,string cl,string start,string end,int lan_num)//按照规定时间和所选的班级和语言输出.. { int i; system("cls"); string k; if(lan_num==1) { k="java"; } else if(lan_num==2) { k="GNU C"; } else if(lan_num==3) { k="GNU C++"; } cout<<"................................................................"<<endl; cout<<" 您选择的时间段为:"<<endl; cout<<start<<"---"<<endl<<endl; cout<<"接下来是按照您的选择来进行的统计排名在下边显示"<<endl; cout<<"****************************************************"<<endl; int run=0; int count=0; int f=0; for(i=1;i<=count_user;i++) { if(stu[i].if_mark==1&&(stu[i].classnum==cl)) { f++; run++; cout<<run<<" "<<stu[i].num<<" "<<stu[i].name<<" "<<stu[i].cs<<" "<<stu[i].score<<endl; if(f%20==0) { count++; if(count==1) cout<<" 第一页 "<<endl; if(count==2) cout<<" 第二页 "<<endl; if(count==3) cout<<" 第三页 "<<endl; if(count==4) cout<<" 第四页 "<<endl; if(count==5) cout<<" 第五页 "<<endl; if(count==6) cout<<" 第六页 "<<endl; if(count==7) cout<<" 第七页 "<<endl; cout<<"<准备跳到下一页>"<<endl; system("pause"); system("cls"); } } } cout<<endl; } int judge() { int i; cout<<" ......................................................."<<endl; cout<<" 如果您需要继续查询,请按1,否则退出按0"<<endl; cin>>i; system("cls"); if(i==0) { cout<<"*********************************************************"<<endl; cout<<"......谢谢你的使用,欢迎下次继续....."<<endl; cout<<"*********************************************************"<<endl; return 0; } else { return 1; } } void welcome_leihuiwu()//系统显示的界面.. { cout<<" * * "<<endl; cout<<" * * * * "<<endl; cout<<" * * * * "<<endl; cout<<" * * * * "<<endl; cout<<" * * * "<<endl; cout<<" * * "<<endl; cout<<" * * "<<endl; cout<<" ******************************************** "<<endl; cout<<" * *欢迎使用分语言和时间段提交排名结果统计系统* * "<<endl; cout<<" * * ............................ * * " <<endl; cout<<" * * .--作者:雷辉武--0906401026. * * " <<endl; cout<<" * * .--计算机科学与技术09级一班. * * " <<endl; cout<<" * * ............................ * *" <<endl; cout<<" * * * * * * ******************************************** * * * * * * " <<endl; system("pause"); system("cls"); } void system_class(classes *cl)//班级列表系统... { cout<<".................怀化学院计算机系班级列表..................."<<endl; int i; cout<<"班级:"<<endl; int count=0; for(i=1;i<=count_classes;i++) { cout<<cl[i].number<<endl; if(i%10==0) { count++; if(count==1) cout<<" 第一页 "<<endl; if(count==2) cout<<" 第二页 "<<endl; if(count==3) cout<<" 第三页 "<<endl; if(count==4) cout<<" 第四页 "<<endl; if(count==5) cout<<" 第五页 "<<endl; if(count==6) cout<<" 第六页 "<<endl; if(count==7) cout<<" 第七页 "<<endl; cout<<"<准备跳到下一页>"<<endl; system("pause"); system("cls"); } } } string system_tishi()//提示班级列表的选择。。 { string k; cout<<"请您输入要选择查看班级成绩的编号:"<<endl; cin>>k; system("pause"); system("cls"); return k; } void save(student_user *stu,string cl,string start,string end,int lan_num)//将输出的结果保存在文件中.... { string wenben; cout<<".............输入您要保存的文本名称"<<endl; cin>>wenben; cout<<endl; ofstream fout(wenben.c_str()); int i,t; string k; t=0; if(lan_num==1) k="java"; else if(lan_num==2) k="GNU C"; else if(lan_num==3) k="GNU C++"; fout<<"..........................................................."<<endl; fout<<" 您选择的语言是 "<<k<<endl<<endl; fout<<" 您选择的时间段是:"; fout<<start<<"---"<<end<<endl<<endl; fout<<" 按照您的选择统计排名如下:/n/n"; fout<<" .........................................................../n/n"; int f=0; int count=0; for(i=1;i<=count_user;i++) { if(stu[i].if_mark==1&&(stu[i].classnum==cl)) { f++; t++; fout<<t<<' '<<stu[i].num<<' '<<stu[i].name<<' '<<stu[i].cs<<' '<<stu[i].score<<endl; if(f%20==0) { count++; if(count==1) fout<<" 第一页 "<<endl; if(count==2) fout<<" 第二页 "<<endl; if(count==3) fout<<" 第三页 "<<endl; if(count==4) fout<<" 第四页 "<<endl; if(count==5) fout<<" 第五页 "<<endl; if(count==6) fout<<" 第六页 "<<endl; if(count==7) fout<<" 第七页 "<<endl; } } } fout<<" 统计结果已成功的保存到了 "<<wenben<<endl; } int main() { system("color 1F"); student_user *st; st=new student_user [2001]; Language *lan; lan=new Language[4]; classes *cl; cl=new classes[2000]; submit *sub; sub=new submit[20001]; Initstudent_user(st);//初始化个人信息... Initclasses(cl);//初始化班级信息... Initlanguage(lan);//初始化语言.... Initsubmit(sub);//初始化提交者... string starttime,endtime,startyear,endyear,start,end; int lan_num; welcome_leihuiwu(); int t=1; while(t!=0) { string class_num; system_class(cl); class_num=system_tishi(); Initscore(st); check_classes(cl,st); lan_num=read_language(); startyear=get_startyear(sub);//读入开始年月日. starttime=get_time();//读入开始的时间. endyear=get_endyear();//读入结束年月日. endtime=get_endtime();//读入结束的时间. start=startyear+' '+starttime; end=endyear+' '+endtime; check_run(sub,st,lan_num,startyear,starttime,endyear,endtime); sort(st+1,st+1+count_user,cmp);//实现排序,按总分的高低排.... Out(st,class_num,start,end,lan_num); save(st,class_num,start,end,lan_num); t=judge(); } return 0; }

你可能感兴趣的:(java,String,user,System,Class,语言)