time limit: 1.000 seconds
Problem Description
Hi, I am an undergraduate student in institute of foreign languages. As you know, C programming is a required course in our university, even if his/her major is far from computer science. I don’t like this course at all, as I am not good at computer and I don’t wanna even have a try of any programming!! But I have to do the homework in order to pass ? Sh… Could you help me with it? Please keep secret!! I know that you won’t say NO to a poor little girl, boy. ?
Task
Write a Student Performance Management System (SPMS).
Concepts
In the SPMS, there will be at most 100 students, each has an SID, a CID, a name and four scores
(Chinese, Mathematics, English and Programming).
• SID (student ID) is a 10-digit number
• CID (class ID) is a positive integer not greater than 20.
• Name is a string of no more than 10 letters and digits, beginning with a capital letter. Note that a name cannot contain space characters inside.
• Each score is a non-negative integer not greater than 100.
Main Menu
When you enter the SPMS, the main menu should be shown like this:
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Adding a Student
If you choose 1 from the main menu, the following message should be printed on the screen:
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Then your program should wait for user input. The input lines are always valid (no invalid SID, CID, or name, exactly four scores etc), but the SID may already exist. In that case, simply ignore this line and print the following:
Duplicated SID.
On the other hand, multiple students can have the same name.
You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.
Removing a Student
If you choose 2 from the main menu, the following message should be printed on the screen:
Please enter SID or name. Enter 0 to finish
Then your program should wait for user input, and remove all the students matching the SID or name in the database, and print the following message (it’s possible xx = 0):
xx student(s) removed.
You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.
Querying Students
If you choose 3 from the main menu, the following message should be printed on the screen:
Please enter SID or name. Enter 0 to finish.
Then your program should wait for user input. If no student matches the SID or name, simply do nothing, otherwise print out all the matching students, in the same order they’re added to the database. The format is similar to the input format for “adding a student”, but 3 more columns are added: rank (1st column), total score and average score (last two columns). The student with highest total score (considering all classes) received rank − 1, and if there are two rank − 2 students, the next one would be rank − 4.
You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.
Showing the Ranklist
If you choose 4 from the main menu, the following message should be printed on the screen:
Showing the ranklist hurts students’ self-esteem. Don’t do that.
Then the main menu is printed again.
Showing Statistics
If you choose 5 from the main menu, show the statistics, in the following format:
Please enter class ID, 0 for the whole statistics.
When a class ID is entered, print the following statistics. Note that “passed” means to have a score of at least 60.
Chinese
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx
Mathematics
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx
English
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx
Programming
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx
Overall:
Number of students who passed all subjects: xx
Number of students who passed 3 or more subjects: xx
Number of students who passed 2 or more subjects: xx
Number of students who passed 1 or more subjects: xx
Number of students who failed all subjects: xx
Then, the main menu is printed again.
Exiting SPMS
If you choose 0 from the main menu, the program should terminate.
Note that course scores and total score should be formatted as integers, but average scores should be formatted as a real number with exactly two digits after the decimal point.
Input
There will be a single test case, ending with a zero entered in the main menu screen. The entire input will be valid. The size of input does not exceed 10KB.
Output
Print out everything as stated in the problem description. You should be able to play around this little program in your machine, with a keyboard and a screen. However, both the input and output may look silly when they’re not mixed, as in the keyboard-screen case.
Hint:
When formatting a floating-point number such as Average Score, a good way to prevent floating-point errors is to add a small number (like 1e-5 in this problem). Otherwise, 80.315 would be printed as 80.31 if the floating-point error makes it 80.31499999…
Sample Input
1
0011223344 1 John 79 98 91 100
0022334455 1 Tom 59 72 60 81
0011223344 2 Alice 100 100 100 100
2423475629 2 John 60 80 30 99
0
3
0022334455
John
0
5
1
2
0011223344
0
5
0
4
0
Sample output
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Duplicated SID.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter SID or name. Enter 0 to finish.
2 0022334455 1 Tom 59 72 60 81 272 68.00
Please enter SID or name. Enter 0 to finish.
1 0011223344 1 John 79 98 91 100 368 92.00
3 2423475629 2 John 60 80 30 99 269 67.25
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 69.00
Number of passed students: 1
Number of failed students: 1
Mathematics
Average Score: 85.00
Number of passed students: 2
Number of failed students: 0
English
Average Score: 75.50
Number of passed students: 2
Number of failed students: 0
Programming
Average Score: 90.50
Number of passed students: 2
Number of failed students: 0
Overall:
Number of students who passed all subjects: 1
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter SID or name. Enter 0 to finish.
1 student(s) removed.
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 59.50
Number of passed students: 1
Number of failed students: 1
Mathematics
Average Score: 76.00
Number of passed students: 2
Number of failed students: 0
English
Average Score: 45.00
Number of passed students: 1
Number of failed students: 1
Programming
Average Score: 90.00
Number of passed students: 2
Number of failed students: 0
Overall:
Number of students who passed all subjects: 0
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Showing the ranklist hurts students’ self-esteem. Don’t do that.
Welcome to Student Performance Management System (SPMS).
1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
学生成绩管理系统,这不是期末的大作业么,又写了一个,不过不能AC,明明输出的与ans一模一样,难受.
- 有坑的地方是3查询,按照录入顺序输出,所以就不用排序了.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 110
#define maxl 50
struct stu{//定义结构体
char sid[maxl];
int cid;
char name[maxl];
int a[5];//0~3表示4门课成绩, a[4]表示总成绩
int rank;//年级排名
int pas;//通过的课程数
}s1[maxn],temp;
int fun(){//查询当前学生总数
int i;
for( i=100; s1[i].cid==0&&i>0; i-- );
return i+1;
}
void sort1(){//对学生进行排名和计算其通过的课程数
for( int i=0; i<fun(); i++ ){
int r=0;
s1[i].pas=0;
for( int j=0; j<4; j++ ){
if(s1[i].a[j]>=60)s1[i].pas++;
}
for( int j=0; j<fun(); j++ ){//不排序,通过循环排名
if(j==i) continue;
if(s1[j].a[4]>s1[i].a[4]) r++;
}
s1[i].rank=r+1;
}
}
void add(){//增加一个学生的信息
for(;;){
int flag=1;
printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
scanf("%s",temp.sid);
if(strcmp(temp.sid,"0")==0) break;
else scanf("%d %s %d %d %d %d",&temp.cid,temp.name,&temp.a[0],&temp.a[1],&temp.a[2],&temp.a[3]);
temp.a[4]=temp.a[0]+temp.a[1]+temp.a[2]+temp.a[3];
for( int i=0; i<fun(); i++ ){//查询是否学号重复
if(strcmp(temp.sid,s1[i].sid)==0) flag=0;
}
if(flag){
s1[fun()]=temp;
}
else printf("Duplicated SID.\n");
}
sort1();
}
void print_menu(){//菜单函数
printf("Welcome to Student Performance Management System (SPMS).\n\n");
printf("1 - Add\n");
printf("2 - Remove\n");
printf("3 - Query\n");
printf("4 - Show ranking\n");
printf("5 - Show Statistics\n");
printf("0 - Exit\n\n");
}
void dq( int isq){//2与3写在一起,2删除,3查询
char s[maxl];
for(;;){
sort1();
printf("Please enter SID or name. Enter 0 to finish.\n");
scanf("%s",s);
if(strcmp(s,"0")==0) break;
int r=0;
for( int i=0; i<fun(); i++ ){
if(strcmp(s1[i].sid,s)==0||strcmp(s1[i].name,s)==0){
if(isq){//查询
printf("%d %s %d %s %d %d %d %d %d %.2f\n",s1[i].rank,s1[i].sid,s1[i].cid,s1[i].name,s1[i].a[0],s1[i].a[1],s1[i].a[2],s1[i].a[3],s1[i].a[4],s1[i].a[4]/4.0);
}
else{//删除
s1[i]=s1[101];r++;
}
}
}
if(!isq) printf("%d student(s) removed.\n",r);
}
sort1();
}
void stat(){
printf("Please enter class ID, 0 for the whole statistics.\n");
int n;
int dd=0,sub[4],aa[4],bb[5];//dd计算操作了几个学生,sub数组计算四门学科总分, aa用于计算四门学科每科通过的人数,bb用于计算通过1~4科的学生总数
memset(sub,0,sizeof(sub));memset(aa,0,sizeof(aa));memset(bb,0,sizeof(bb));
scanf("%d",&n);
for( int i=0; i<fun(); i++ ){
if(!n?s1[i].cid:s1[i].cid==n){//n=0对全体学生操作,n不为0便对n班学生操作
sub[0]+=s1[i].a[0];sub[1]+=s1[i].a[1];sub[2]+=s1[i].a[2],sub[3]+=s1[i].a[3];
for( int j=0; j<4; j++ ){
if(s1[i].a[j]>=60) aa[j]++;
}
bb[s1[i].pas]++;
dd++;
}
}
for( int i=0; i<4; i++ ){
switch(i){
case 0:{
printf("Chinese\n");
printf("Average Score: %.2f\n",sub[0]*1.0/dd);
break;
}
case 1:{
printf("Mathematics\n");
printf("Average Score: %.2f\n",sub[1]*1.0/dd);
break;
}break;
case 2:{
printf("English\n");
printf("Average Score: %.2f\n",sub[2]*1.0/dd);
break;
}
case 3:{
printf("Programming\n");
printf("Average Score: %.2f\n",sub[3]*1.0/dd);
break;
}
}
printf("Number of passed students: %d\n",aa[i]);
printf("Number of failed students: %d\n",dd-aa[i]);
printf("\n");
}
printf("Overall:\n");
printf("Number of students who passed all subjects: %d\n",bb[4]);
printf("Number of students who passed 3 or more subjects: %d\n",bb[3]+bb[4]);
printf("Number of students who passed 2 or more subjects: %d\n",bb[2]+bb[3]+bb[4]);
printf("Number of students who passed 1 or more subjects: %d\n",bb[1]+bb[2]+bb[3]+bb[4]);
printf("Number of students who failed all subjects: %d\n",bb[0]);
printf("\n");
sort1();
}
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
memset(s1,0,sizeof(s1));
for(;;){
int choice;
print_menu();
scanf("%d",&choice);if(choice==0) break;
switch(choice){
case 1:add();break;
case 2:dq(0);break;
case 3:dq(1);break;
case 4:{
printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n");
break;
}
case 5:stat();break;
case 0:exit(0);
}
}
return 0;
}