學生成績登記分析處理系統
工具/原料
visual c++ 6.0
方法/步驟
11 綜合實驗模塊化編程:
#include
#include
#include
struct test {char num[15],name[20];float k1,k2,k3,sum,avr;};
void input(struct test t[],int n);//輸入
void sort(struct test t[],int n);//排序
void analyse(struct test t[],int n,char e);//統計
void lookfor(struct test t[],int n,char s[]);//查找
//以下是主函數
void main(){
printf("\n%30s\n\n","***歡迎使用***");
printf("請輸入學生人數(50人以內):");
int n;
scanf("%d",&n);
printf("請分別輸入每個學生的學號、姓名以及各科成績:\n");
struct test student[51];
input(student,n);
char x,y,s[51];
printf("\n請選擇功能編號: a.成績排名 b.分數段統計 c.查找 d.退出\n\n");
for (;;){
scanf("%c",&x);
if (x=='a' x=='A') sort(student,n);
if (x=='b' x=='B') {
printf("請選擇科目: a.線代 b.大物 c.C語言\n");
do {scanf("%c",&y);}
while (y!='a'&&y!='b'&&y!='c');
analyse(student,n,y); }
if (x=='c' x=='C') {
printf("請輸入學號:");
scanf("%s",s);
lookfor(student,n,s); }
if (x=='d' x=='D') break; }
printf("【按任意鍵結束】");
getch(); return; }
//以下函數實現數據輸入
void input(struct test t[],int n){
int i;
for (i=0;i
printf("第%d個學生\n\t學號:",i+1);
scanf("%s",t[i].num);
printf("\t姓名:");
scanf("%s",t[i].name);
printf("\t線 代:");
scanf("%f",&t[i].k1);
printf("\t大 物:");
scanf("%f",&t[i].k2);
printf("\tC語言:");
scanf("%f",&t[i].k3);
t[i].sum=t[i].k1+t[i].k2+t[i].k3;
t[i].avr=t[i].sum*1.0/3; } }
//以下函數實現數據排序
void sort(struct test t[],int n){
struct test p;
int i,j;
for (i=0;i
for (j=i+1;j
if (t[i].sum
p=t[i],t[i]=t[j],t[j]=p;
printf("%-6s%-14s%-7s%-10s%-10s%-7s%-6s%-7s\n","排名","學號","姓名","線性代數","大學物理","C語言","總分","平均分");
for (i=0;i
printf("%3d %-14s%-8s%-10.1f%-9.1f%-7.1f%-7.1f%-5.3f\n",i+1,t[i].num,t[i].name,t[i].k1,t[i].k2,t[i].k3,t[i].sum,t[i].avr); }
printf("\n請選擇功能編號: a.成績排名 b.分數段統計 c.查找 d.退出\n\n");}
//以下函數實現數據分佈統計
void analyse(struct test t[],int n,char e){
int i,a[5]={0,0,0,0,0};
float b[51];
for (i=0;i
if (e=='a') b[i]=t[i].k1;
if (e=='b') b[i]=t[i].k2;
if (e=='c') b[i]=t[i].k3; }
for (i=0;i
if (b[i]<60) a[0]++;
if (b[i]>=60&&b[i]<70) a[1]++;
if (b[i]>=70&&b[i]<80) a[2]++;
if (b[i]>=80&&b[i]<90) a[3]++;
if (b[i]>=90) a[4]++;}
for (i=0;i<5;i++)
b[i]=a[i]*100.0/n;
printf("低於60分\t%2d人\t佔%.1f%c\n",a[0],b[0],'%');
printf("[60,70)分\t%2d人\t佔%.1f%c\n",a[1],b[1],'%');
printf("[70,80)分\t%2d人\t佔%.1f%c\n",a[2],b[2],'%');
printf("[80,90)分\t%2d人\t佔%.1f%c\n",a[3],b[3],'%');
printf("90分以上\t%2d人\t佔%.1f%c\n",a[4],b[4],'%');
printf("\n請選擇功能編號: a.成績排名 b.分數段統計 c.查找 d.退出\n\n");}
//以下函數實現數據搜索
void lookfor(struct test t[],int n,char s[]){
int i;
for (i=0;i
if (strcmp(t[i].num,s)==0){
printf("搜索結果:\n姓名:%s 線代%.1f 大物%.1f C語言%.1f 總分%.1f 平均分%.3f\n",t[i].name,t[i].k1,t[i].k2,t[i].k3,t[i].sum,t[i].avr);
i=-1; break;}}
if (i!=-1) printf("沒搜到\n");
printf("\n請選擇功能編號: a.成績排名 b.分數段統計 c.查找 d.退出\n\n");}