/*1.学生成绩管理系统V1.0
某班有最多不超过40人(具体人数由键盘输入)参加某门课程的考试,用数组作函数参数编程实现如下学生成绩管理:
(1)录入每个学生的学号和考试成绩;
(2)计算课程的总分和平均分;
(3)按成绩由高到低排出名次表;
(4)按学号由小到大排出成绩表;
(5)按学号查询学生排名及其考试成绩;
(6)按优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5个类别,统计每个类别的人数以及所占的百分比;
(7)输出每个学生的学号、考试成绩,课程总分和平均分。
2.学生成绩管理系统V1.1
在学生成绩管理系统V1.0的基础上,要求程序运行后先显示如下菜单,并提示用户输入选项:
(1)Append record
(2)Calculate total and average score of course
(3)Sort in descending order by score
(4)Sort in ascending order by number
(5)Search by number
(6)Statistic analysis
(7)List record
(8)Exit
*/
1.0
#include <stdio.h>
#include <stdlib.h>
#define N 40
int Menu();
int ReadScore(int score[],long num[]);
int calculate(int score[],int n);
int ScoreSort(int score[],long num[],int n);
void printScore(int score[],long num[],int n);
int SearchScore(int score[],long num[],int n);
int main()
{
int score[N],n,sum,i,a=0,b=0,c=0,d=0,e=0,s;
long num[N];
n=ReadScore(score,num);
sum=calculate(score,n);
printf("Calculate total and average score of course:\n");
printf("sum=%d,ave=%d\n",sum,sum/n);
printf("Sort in ascending order by number:\n");
printScore(score,num,n);
ScoreSort(score,num,n);
printf("Sort in descending order by score:\n");
printScore(score,num,n);
SearchScore(score,num,n);
for(i=0;i<n;i++)
{
if(score[i]>=90 && score[i]<=100)
a++;
if(score[i]>=80 && score[i]<90)
b++;
if(score[i]>=70 && score[i]<80)
c++;
if(score[i]>=60 && score[i]<70)
d++;
if(score[i]>=0 && score[i]<60)
e++;
}
printf("Statistic analysis\n");
printf("优秀(90-100)=%d\n良好(80-89)=%d\n中等(70-79)=%d\n及格(60-69)=%d\n不及格(0-59)=%d\n",a,b,c,d,e);
printf("优秀(90-100)=%d\n良好(80-89)=%d\n中等(70-79)=%d\n及格(60-69)=%d\n不及格(0-59)=%d\n",a/n,b/n,c/n,d/n,e/n);
return 0;
}
int ReadScore(int score[],long num[])
{
int i=20221401,n;
for(n=0;n<N;n++)
{
scanf("%d",&score[n]);
if(score[n]<0)
return n;
num[n]=i;
i++;
}
return n;
}
int calculate(int score[],int n)
{
int i,sum;
sum=0;
for(i=0;i<n;i++)
{
sum+=score[i];
}
return sum;
}
int ScoreSort(int score[],long num[],int n)
{
int a,b,c,temp1;
long temp2;
for(a=0;a<n-1;a++)
{
c=a;
for(b=a+1;b<n;b++)
{
if(score[b]>score[c])
{
c=b;
}
}
if(c!=a)
{
temp1=score[c];
score[c]=score[a];
score[a]=temp1;
temp2=num[c];
num[c]=num[a];
num[a]=temp2;
}
}
}
void printScore(int score[],long num[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%10ld%4d\n",num[i],score[i]);
}
}
SearchScore(int score[],long num[],int n)
{
int m;
long i;
printf("Search by number:");
scanf("%ld",&i);
for(m=0;m<=n;m++)
{
if(i==num[m])
{
printf("%d\n",score[m]);
}
}
}
2.0
#include <stdio.h>
#include <stdlib.h>
#define N 40
#define M 20221401
int Menu();
int ReadScore(int score[],long num[]);
int calculate(int score[],int n);
int ScoreSort(int score[],long num[],int n);
int NumSort(int score[],long num[],int n);
int printScore(int score[],long num[],int n);
int SearchScore(int score[],long num[],int n);
int Analysis(int score[],long num[],int n);
int main()
{
int score[N],n,sum;
char select;
long num[N];
while(1)
{
select = Menu();
switch(select)
{
case 1:
n=ReadScore(score,num);
break;
case 2:
sum=calculate(score,n);
break;
case 3:
ScoreSort(score,num,n);
break;
case 4:
NumSort(score,num,n);
break;
case 5:
SearchScore(score,num,n);
break;
case 6:
Analysis(score,num,n);
break;
case 7:
printScore(score,num,n);
sum=calculate(score,n);
printf("Calculate total and average score of course:\n");
printf("sum=%d,ave=%d\n",sum,sum/n);
break;
case 8:
printf("End");
exit(0);
default:
printf("Error!");
}
}
}
int Menu()
{
int select;
printf("Management System for Students' scores\n");
printf("1.Input record\n");
printf("2.Caculate total and average score of course\n");
printf("3.Sort in descending order by score\n");
printf("4.Sort in ascending order by number\n");
printf("5.Search by number\n");
printf("6.Statistic analysis\n");
printf("7.List record\n");
printf("8.Exit\n");
printf("Please Input your choice:\n");
scanf("%d",&select);
return select;
}
int ReadScore(int score[],long num[])
{
int n;
long i=M;
for(n=0; n<N; n++)
{
scanf("%d",&score[n]);
if(score[n]<0)
return n;
num[n]=i;
i++;
}
return n;
}
int calculate(int score[],int n)
{
int i,sum;
sum=0;
for(i=0; i<n; i++)
{
sum+=score[i];
}
return sum;
}
int ScoreSort(int score[],long num[],int n)
{
int a,b,c,temp1;
long temp2;
for(a=0; a<n-1; a++)
{
c=a;
for(b=a+1; b<n; b++)
{
if(score[b]>score[c])
{
c=b;
}
}
if(c!=a)
{
temp1=score[c];
score[c]=score[a];
score[a]=temp1;
temp2=num[c];
num[c]=num[a];
num[a]=temp2;
}
}
}
int NumSort(int score[],long num[],int n)
{
int a,b,c,temp1;
long temp2;
for(a=0;a<n;a++)
{
c=a;
for(b=a+1;b<n;b++)
{
if(num[b]<num[c])
{
c=b;
}
}
if(c!=a)
{
temp1=score[c];
score[c]=score[a];
score[a]=temp1;
temp2=num[c];
num[c]=num[a];
num[a]=temp2;
}
}
}
int printScore(int score[],long num[],int n)
{
int i;
for(i=0; i<n; i++)
{
printf("%10ld%4d\n",num[i],score[i]);
}
}
int SearchScore(int score[],long num[],int n)
{
int m;
long i;
printf("Search by number:");
scanf("%ld",&i);
for(m=0; m<=n; m++)
{
if(i==num[m])
{
printf("%d\n",score[m]);
return 0;
}
}
printf("Not Found!");
}
int Analysis(int score[],long num[],int n)
{
int i;
float a=0,b=0,c=0,d=0,e=0;
for(i=0; i<n; i++)
{
if(score[i]>=90 && score[i]<=100)
a++;
if(score[i]>=80 && score[i]<90)
b++;
if(score[i]>=70 && score[i]<80)
c++;
if(score[i]>=60 && score[i]<70)
d++;
if(score[i]>=0 && score[i]<60)
e++;
}
printf("Statistic analysis\n");
printf("优秀(90-100)=%d\n良好(80-89)=%d\n中等(70-79)=%d\n及格(60-69)=%d\n不及格(0-59)=%d\n",a,b,c,d,e);
printf("优秀(90-100)=%f\n良好(80-89)=%f\n中等(70-79)=%f\n及格(60-69)=%f\n不及格(0-59)=%f\n",a/n,b/n,c/n,d/n,e/n);
}
标签:num,管理系统,int,sum,long,score,实验,printf,成绩
From: https://www.cnblogs.com/20031004wzy/p/16884571.html