C語言實(shí)現(xiàn)簡易學(xué)生成績管理系統(tǒng)
某班有最多不超過30人(具體人數(shù)由鍵盤輸入)參加某門課程的考試,編程實(shí)現(xiàn)如下學(xué)生成績管理:
(1)錄入每個(gè)學(xué)生的學(xué)號(hào)和考試成績;
(2)計(jì)算課程的總分和平均分;
(3)按成績由高到低排出名次表;
(4)按學(xué)號(hào)由小到大排出成績表;
(5)按學(xué)號(hào)查詢學(xué)生排名及其考試成績;
(6)按優(yōu)秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5個(gè)類別,統(tǒng)計(jì)每個(gè)類別的人數(shù)以及所占的百分比;
(7)輸出每個(gè)學(xué)生的學(xué)號(hào)、考試成績,以及課程總分和平均分。
輸入格式:
( 1 ) 錄入學(xué)生的人數(shù):
要求輸入數(shù)據(jù)格式為:"%d"
提示信息為:“Input student number(n<30):\n”
( 2 )錄入每個(gè)學(xué)生的學(xué)號(hào)和考試成績:
要求輸入數(shù)據(jù)格式為:"%ld%f"
提示信息為:“Input student's ID and score:\n”
輸出格式:
1、菜單項(xiàng)的輸出顯示:
Management for Students' scores
1.Input 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
0.Exit
Please Input your choice:
2、計(jì)算課程的總分和平均分:
要求輸出總分與平均分格式為:“sum=%.0f,aver=%.2f\n”
3、按成績由高到低排出名次表:
要求輸出格式為:"%ld\t%.0f\n"
提示信息為:“Sort in descending order by score:\n”
4、按學(xué)號(hào)由小到大排出成績表:
要求輸出格式為:"%ld\t%.0f\n"
提示信息為:“Sort in ascending order by number:\n”
5、按學(xué)號(hào)查詢學(xué)生信息及其考試成績(輸出學(xué)號(hào)與成績):
如果未查到此學(xué)號(hào)的學(xué)生,提示信息為:“Not found!\n”;
如果查詢到該學(xué)生,要求輸出格式為:"%ld\t%.0f\n"
6、按優(yōu)秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5個(gè)類別,統(tǒng)計(jì)每個(gè)類別的人數(shù)以及所占的百分比:
成績<60輸出提示格式為:"<60\t%d\t%.2f%%\n";
成績=100輸出格式為:"%d\t%d\t%.2f%%\n";
其他要求輸出百分比格式為:"%d-%d\t%d\t%.2f%%\n"
演示效果:
代碼:
#include<stdio.h> #include<stdlib.h> #include<conio.h> //宏定義最大學(xué)生人數(shù) #define stu_max 30 /*進(jìn)行函數(shù)的全局聲明*/ //獲取學(xué)生人數(shù) int stu_num(); //顯示菜單獲取用戶輸入 char menu_tips(); //獲取學(xué)生學(xué)號(hào),及本門考試成績 void stu_information(long num[],float score[],int n); //計(jì)算輸出課程的總分和平均分 void sum_aver(float score[],int n); //模塊功能:交換兩個(gè)長整型數(shù)據(jù) void exchange_long(long *a,long *b); //模塊功能:交換兩個(gè)浮點(diǎn)型數(shù)據(jù) void exchange_float(float *a,float *b); //按成績由高到低輸出名次表 void output_score(long num[],float score[],int n); //按學(xué)號(hào)從小到大排出成績表 void output_num(long num[],float score[],int n); //查詢輸出學(xué)生信息及考試成績: void query(long num[],float score[],int n); //分?jǐn)?shù)劃界處理并輸出 void score_pro(float score[],int n); //直接輸出對(duì)應(yīng)列表 void output(long num[],float score[],int n); //暫停清屏 void clean(); int main() { int n,i; long num[stu_max]; float score[stu_max]; n=stu_num(); while(1) { i=menu_tips(); switch(i) { case '1':printf("1"),stu_information(num,score,n),system("cls");break; case '2':printf("2"),sum_aver(score,n),clean();break; case '3':printf("3"),output_score(num,score,n),clean();break; case '4':printf("4"),output_num(num,score,n),clean();break; case '5':printf("5"),query(num,score,n),clean();break; case '6':printf("6"),score_pro(score,n),clean();break; case '7':printf("7"),output(num,score,n),clean();break; case '0':printf("0"),exit(0);break; default:printf("Input error!\n"),clean(); } } } /*以下為函數(shù)功能模塊*/ //獲取學(xué)生人數(shù) int stu_num() { int n; printf("Input student number(n<30):\n"); scanf("%d",&n); system("cls"); return n; } //顯示菜單獲取用戶輸入 char menu_tips() { printf(" -----------------------------------------------------------\n"); printf("| Management for Students' scores |\n"); printf(" -----------------------------------------------------------\n"); printf("| 1.Input record |\n"); printf("| 2.Calculate total and average score of course |\n"); printf("| 3.Sort in descending order by score |\n"); printf("| 4.Sort in ascending order by numbe |\n"); printf("| 5.Search by number |\n"); printf("| 6.Statistic analysis |\n"); printf("| 7.List record |\n"); printf("| 0.Exit |\n"); printf(" -----------------------------------------------------------\n"); printf("\nPlease Input your choice:\n"); char i; i=getch(); return i; } //獲取學(xué)生學(xué)號(hào),及本門考試成績 void stu_information(long num[],float score[],int n) { int i; printf("\nInput student's ID and score:\n"); for(i=0;i<n;i++) scanf("%ld%f",&num[i],&score[i]); } //計(jì)算輸出課程的總分和平均分 void sum_aver(float score[],int n) { int i; float sum,aver; for(i=0,sum=0;i<n;i++) sum+=score[i]; aver=sum/n; printf("\nsum=%.0f,aver=%.2f\n",sum,aver); } //模塊功能:交換兩個(gè)長整型數(shù)據(jù) void exchange_long(long *a,long *b) { long t; t=*a; *a=*b; *b=t; } //模塊功能:交換兩個(gè)浮點(diǎn)型數(shù)據(jù) void exchange_float(float *a,float *b) { float t; t=*a; *a=*b; *b=t; } //按成績由高到低輸出名次表 void output_score(long num[],float score[],int n) { int i,j; for(j=n-1;j>0;j--) { for(i=0;i<j;i++) if(score[i]<score[i+1]) { exchange_float(&score[i],&score[i+1]); exchange_long(&num[i],&num[i+1]); } } printf("\nSort in descending order by score:"); output(num,score,n); } //按學(xué)號(hào)從小到大排出成績表 void output_num(long num[],float score[],int n) { int i,j; for(j=n-1;j>0;j--) { for(i=0;i<j;i++) if(num[i]>num[i+1]) { exchange_float(&score[i],&score[i+1]); exchange_long(&num[i],&num[i+1]); } } output(num,score,n); } //查詢輸出學(xué)生信息及考試成績: void query(long num[],float score[],int n) { printf("\nEnter the ID to query:\n"); long temp; scanf("%ld",&temp); int i; for(i=0;i<n;i++) { if(num[i]==temp) { printf("%ld\t%.0f\n",num[i],score[i]); return; } } printf("\nNot found!\n"); } //分?jǐn)?shù)劃界處理并輸出 void score_pro(float score[],int n) { int t[6]={0,0,0,0,0,0}; /*前五個(gè)分別對(duì)應(yīng)優(yōu)秀、良好、中等、及格、不及格五個(gè)類別 第六位存儲(chǔ)100分的人數(shù)*/ int i,m; for(i=0;i<n;i++) { if(score[i]>=90&&score[i]<100) t[0]++; if(score[i]>=80&&score[i]<=89) t[1]++; if(score[i]>=70&&score[i]<=79) t[2]++; if(score[i]>=60&&score[i]<=69) t[3]++; if(score[i]>=0 &&score[i]<=59) t[4]++; if(score[i]==100) t[5]++; } //遍歷t數(shù)組,輸出對(duì)應(yīng)的數(shù)據(jù) for(i=0,m=9;i<6;i++) { if(i==4) printf("<60\t%d\t%.2f%%\n",t[4],(float)t[4]/n*100); if(i==5) printf("%d\t%d\t%.2f%%\n",100,t[5],(float)t[5]/n*100); if(i!=4&&i!=5) { if(i==0) printf("\n"); printf("%d-%d\t%d\t%.2f%%\n",m*10,m*10+9,t[i],(float)t[i]/n*100); m--; } } } //直接輸出對(duì)應(yīng)列表 void output(long num[],float score[],int n) { int i; for(i=0;i<n;i++) { if(i==0) printf("\n"); printf("%ld\t%.0f\n",num[i],score[i]); } } //暫停清屏 void clean() { system("pause"); system("cls"); }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++繼承中的對(duì)象構(gòu)造與析構(gòu)和賦值重載詳解
這篇文章主要為大家詳細(xì)介紹了C++繼承中的對(duì)象構(gòu)造與析構(gòu)和賦值重載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-03-03C語言數(shù)據(jù)結(jié)構(gòu)遞歸之斐波那契數(shù)列
這篇文章主要介紹了C語言數(shù)據(jù)結(jié)構(gòu)遞歸之斐波那契數(shù)列的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10