#include <bits/stdc++.h>
#define int long long
#define judge(a,func) case a:func();break;
using namespace std; void println(string s){
cout<<s<<'\n';
} void main_menu(){
println("Welcome to Student Performance Management System (SPMS).");
println("");
println("1 - Add");
println("2 - Remove");
println("3 - Query");
println("4 - Show ranking");
println("5 - Show Statistics");
println("0 - Exit");
println("");
} struct Student{
string sid,name;
int cid;
int chinese,mathematics,english,programming;
bool operator==(const Student &x) const{
return sid==x.sid && cid==x.cid && chinese==x.chinese && mathematics==x.mathematics && english==x.english && programming == x.programming;
}
}; vector<Student> v;
map<string,bool> duplicated; void add(){
println("Please enter the SID, CID, name and four scores. Enter 0 to finish.");
string sid;
cin>>sid;
if(sid=="0")return;
Student student;
student.sid=sid;
cin>>student.cid>>student.name>>student.chinese>>student.mathematics>>student.english>>student.programming;
if(duplicated[sid]){
println("Duplicated SID.");
}
else{
duplicated[sid]=1;
v.push_back(student);
}
add();
} void remove(){
println("Please enter SID or name. Enter 0 to finish.");
string str;
cin>>str;
stack<vector<Student>::iterator> removing;
if(str=="0")return;
int tot=0;
for(auto ite=v.begin();ite!=v.end();ite++){
if((*ite).sid==str || (*ite).name==str){
tot++;
duplicated[(*ite).sid]=0;
removing.push(ite);
}
}
while(!removing.empty()){
v.erase(removing.top());
removing.pop();
}
cout<<tot;
println(" student(s) removed.");
remove();
} int total(Student x){
return x.chinese+x.english+x.mathematics+x.programming;
} void query(){
println("Please enter SID or name. Enter 0 to finish.");
string str;
cin>>str;
if(str=="0")return;
for(Student i : v){
if(i.sid==str || i.name==str){
vector<Student> same_class;
for(Student j : v){
same_class.push_back(j);
}
sort(same_class.begin(),same_class.end(),[&](const Student &x,const Student &y){
return x.chinese+x.mathematics+x.english+x.programming>y.chinese+y.mathematics+y.english+y.programming;
});
int ret=0;
for(vector<Student>::size_type j=0;j<same_class.size();j++){
if(j>0&&total(same_class[j])==total(same_class[j-1])){}
else ret=j+1;
if(same_class[j]==i){
break;
}
}
cout<<ret<<' '<<i.sid<<' '<<i.cid<<' '<<i.name<<' ';
cout<<i.chinese<<' '<<i.mathematics<<' '<<i.english<<' '<<i.programming<<' ';
cout<<(i.chinese+i.mathematics+i.english+i.programming)<<' ';
printf("%.2lf\n",((double)((i.chinese+i.mathematics+i.english+i.programming))/4.0)+1e-5);
}
}
query();
} void show_ranking(){
println("Showing the ranklist hurts students' self-esteem. Don't do that.");
} void show_statisitics(){
println("Please enter class ID, 0 for the whole statistics.");
int cid;cin>>cid;
int passed=0,failed=0;
double aver=0;
int cnt=0;
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
cnt++;
}
{
println("Chinese");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.chinese;
passed += (i.chinese >= 60);
failed += (i.chinese < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
{
aver=0;failed=0;passed=0;
println("Mathematics");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.mathematics;
passed += (i.mathematics >= 60);
failed += (i.mathematics < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
{
aver=0;failed=0;passed=0;
println("English");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.english;
passed += (i.english >= 60);
failed += (i.english < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
{
aver=0;failed=0;passed=0;
println("Programming");
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
aver += i.programming;
passed += (i.programming >= 60);
failed += (i.programming < 60);
}
aver /= cnt;
cout<<"Average Score: ";
printf("%.2lf\n",aver+1e-5);
cout<<"Number of passed students: "<<passed<<'\n';
cout<<"Number of failed students: "<<failed<<'\n';
println("");
}
println("Overall:");
int all=0,one=0,two=0,three=0,failed_all=0;
for(Student i : v){
if(i.cid!=cid&&cid!=0)continue;
int ret = (int)(i.chinese>=60)+(int)(i.mathematics>=60)+(int)(i.english>=60)+(int)(i.programming>=60);
if(ret>=1)one++;
if(ret>=2)two++;
if(ret>=3)three++;
if(ret>=4)all++;
if(ret==0)failed_all++;
}
cout<<"Number of students who passed all subjects: "<<all<<'\n';
cout<<"Number of students who passed 3 or more subjects: "<<three<<'\n';
cout<<"Number of students who passed 2 or more subjects: "<<two<<'\n';
cout<<"Number of students who passed 1 or more subjects: "<<one<<'\n';
cout<<"Number of students who failed all subjects: "<<failed_all<<'\n';
println("");
} signed main(){
// freopen("1.out","w",stdout);
while(1){
main_menu();
int op;
cin>>op;
switch(op){
judge(1,add);
judge(2,remove);
judge(3,query);
judge(4,show_ranking);
judge(5,show_statisitics);
case 0:return 0;
}
}
}

最新文章

  1. 53. 特殊的O(n)时间排序[sort ages with hashtable]
  2. css3 翻转和旋转的区别
  3. android 网络加载图片,对图片资源进行优化,并且实现内存双缓存 + 磁盘缓存
  4. Post 的数据被截断
  5. gamit10.6问题汇总
  6. ICE学习第四步-----客户端请求服务器返回数据
  7. linux下java窗口,正确显示中文
  8. Fiddler 教程(转)
  9. nginx的五种负载算法模式
  10. Quartz.NET总结(一)
  11. Liunx文件解压与压缩
  12. MySQL_写锁_lock tables tableName write
  13. [源码分析]Java1.8中StringJoiner的使用以及源码分析
  14. apache atlas源码编译打包 centos
  15. C#--IEnumerable 与 IEnumerator 的区别
  16. 基于tensorflow的逻辑分类
  17. android rom开发
  18. CF 666E Forensic Examination——广义后缀自动机+线段树合并
  19. Set up an SSH key with Sourcetree on macOS
  20. mybatis初识

热门文章

  1. 齐博x1 小程序与公众号长期永久订阅消息的申请方法
  2. c语言中 -&gt; 的用法
  3. ES6 学习笔记(四)基本类型Number
  4. Redis可视化管理工具-RedisDesktopManager
  5. 畅联新增物联网设备接入协议:精华隆的NB一键报警
  6. 从 洛谷P5309 Ynoi2011 初始化 看卡常
  7. mybatis不知道取什么名字的标题
  8. 棋盘覆盖(java实现)
  9. 报错:com.mysql.jdbc.MysqlDataTruncation: Data truncation xxxx
  10. 关于python实现html转word(docx)