網(wǎng)站首頁 編程語言 正文
本文實例為大家分享了C語言學(xué)生成績管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
效果如下:
代碼如下:
#include#include #include struct student{ ? ? ? ? int num; ? ? ? ? char name[20]; ? ? ? ? float score1; ? ? ? ? float score2; ? ? ? ? float score3; ? ? ? ? double total; }stu[4]; void a(); void b(); void c(); void d(); void e(); int main(void) { ? ? //printf("Hello World!\n"); ? ? ? ?int n; ? ? ? ?while(n!=6){ ? ? ? ? ? ?printf("\t student score manage system\n"); ? ? ? ? ? ?printf("1-input all student's score!\n"); ? ? ? ? ? ?printf("2-show all student's score!\n"); ? ? ? ? ? ?printf("3-output student's average score!\n"); ? ? ? ? ? ?printf("4-output student's score and rank!\n"); ? ? ? ? ? ?printf("5-result output txt file!\n"); ? ? ? ? ? ?printf("6-exit!\n"); ? ? ? ? ? ?scanf("%d",&n); ? ? ? ? ? ?switch(n){ ? ? ? ? ? ? ? ?case 1:a();break; ? ? ? ? ? ? ? ?case 2:b();break; ? ? ? ? ? ? ? ?case 3:c();break; ? ? ? ? ? ? ? ?case 4:d();break; ? ? ? ? ? ? ? ?case 5:e();break; ? ? ? ? ? ? ? ?case 6:printf("******ByeBye******");break; ? ? ? ? ? ?} ? ? ? ?} ? ? return 0; } //輸入成績 void a(){ ? ? int i; ? ? for(i=0;i<4;i++){ ? ? ? ? printf("input num name score1 score2 score3: "); ? ? ? ? scanf("%d%s%f%f%f",&stu[i].num,stu[i].name,&stu[i].score1,&stu[i].score2,&stu[i].score3); ? ? } ? ? for(i=0;i<4;i++){ ? ? ? ? stu[i].total=stu[i].score1+stu[i].score2+stu[i].score3; ? ? } } //輸出成績 void b(){ ? ? int i; ? ? printf("num \t name \t score1 \t score2 \t score3 \t total \n"); ? ? for(i=0;i<4;i++){ ? ? ? ? printf("%d \t %s \t %f \t %f \t %f \t %f \n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total); ? ? } } //求平均成績 void c(){ ? ? double total=0; ? ? double avg; ? ? int i; ? ? for(i=0;i<4;i++){ ? ? ? ? total+=stu[i].total; ? ? } ? ? avg=total/4.0; ? ? printf("avg is :%f \n",avg); } //按照總成績排序 void d(){ ? ? struct student temp; ? ? int i,j; ? ? for(i=0;i<4;i++){ ? ? ? ? for(j=i+1;j<4;j++){ ? ? ? ? ? ? temp=stu[i]; ? ? ? ? ? ? stu[i]=stu[j]; ? ? ? ? ? ? stu[j]=temp; ? ? ? ? } ? ? } ? ? printf("num \t name \t score1 \t score2 \t score3 \t total \n"); ? ? for(i=0;i<4;i++){ ? ? ? ? printf("%d \t %s \t %f \t %f \t %f \t %f \n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total); ? ? } } // 保存數(shù)據(jù)到文件 void e(){ ? ? int i; ? ? FILE *fp; ? ? fp=fopen("E:/result.txt","w"); ? ? fprintf(fp,"num \t name \t score1 \t score2 \t score3 \t total \n"); ? ? for(i=0;i<4;i++){ ? ? ? ? fprintf(fp,"%d \t %s \t %f \t %f \t %f \t %f \n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].total); ? ? } ? ? printf(" save success! \n "); }
原文鏈接:https://blog.csdn.net/chendongpu/article/details/121816378
相關(guān)推薦
- 2022-05-11 使用kettle的數(shù)據(jù)庫增量備份與全量備份
- 2022-10-22 Go語言數(shù)據(jù)結(jié)構(gòu)之單鏈表的實例詳解_Golang
- 2022-08-27 基于Redis實現(xiàn)延時隊列的優(yōu)化方案小結(jié)_Redis
- 2022-01-07 thymeleaf中th:include, th:insert, th:replace的區(qū)別
- 2022-03-26 C語言宏定義#define的使用_C 語言
- 2022-06-06 微信小程序動態(tài)綁定class
- 2021-07-18 vscode sftp no such file 解決辦法
- 2023-03-16 Android藍牙服務(wù)啟動流程分析探索_Android
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支