您好,登錄后才能下訂單哦!
這篇“怎么用C語言實現學生成績管理系統”文章的知識點大部分人都不太理解,所以小編給大家總結了以下內容,內容詳細,步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“怎么用C語言實現學生成績管理系統”文章吧。
1、數據結構:學生信息:學號、姓名、年齡、性別、3課成績
2、功能:
(1) 增加學生記錄
(2) 刪除學生記錄
(3) 查找學生信息(學號、姓名)
(4) 修改學生信息
(5) 按照成績排序、求平均值、最大值、最小值
3、用戶界面
主菜單
子菜單
4、 批量生成測試數據
// // main.c // Student System // // Created by ma c on 15/7/22. // Copyright (c) 2015年. All rights reserved. // 要求:編寫一個學生成績管理系統。 #include <stdio.h> #include<string.h> #include<stdlib.h> #define N 50 struct Student{ char name[20]; int sno; int age; char gender; float EnglishScore; float mathScore; float chineseScore; }stu[N]={{"zhao",1000,20,'M',98,99,97}, {"zhao",1001,21,'F',97,96,95}, {"qian",1002,23,'M',95,96,92}, {"hong",1003,22,'F',91,93,97}, {"zhou",1004,25,'M',90,90,90}, {"feng",1005,21,'F',96,93,96}, {"wang",1006,23,'M',97,91,90}, {"chen",1007,21,'F',94,92,91}, {"geng",1008,20,'F',90,99,91}, {"tang",1009,24,'M',99,99,99}}; //添加數據 void add(struct Student stu[],int pos,int nums); //刪除數據 void Delete_name(struct Student *stu,char Name[]);//(按姓名) void Delete_sno(struct Student *stu,int Sno);//(按學號) //修改數據 void update(struct Student stu[],int Sno,int len); //查詢子菜單 void menu(struct Student stu[],int m); void search(struct Student stu[],int n,char Name[]);//按姓名查詢 void search2(struct Student stu[],int n,int Num);//按學號查詢 void sort(struct Student stu[],int n); //按總分高低排序 void print(struct Student stu[],int n); void My_print_sum(struct Student stu[],int n); void max_min(struct Student stu[],int n); //主菜單 void PrintScreen() { printf("------------------\n"); printf("** 1.增加學生記錄 **\n"); printf("** 2.刪除學生記錄 **\n"); printf("** 3.查找學生記錄 **\n"); printf("** 4.修改學生記錄 **\n"); printf("** 0.退出管理系統 **\n"); printf("------------------\n"); } //刪除子菜單 void deleteScreen() { printf("------------------\n"); printf("** 0.按姓名刪除數據**\n"); printf("** 1.按學號刪除數據**\n"); printf("** 2.返回主菜單 **\n"); printf("------------------\n"); printf("please select 0-1:"); } //查找子菜單 void seekScreen() { printf("-------------------------\n"); printf("****** 1.按姓名查找信息 *\n"); printf("****** 2.按學號查找信息 *\n"); printf("****** 3.查看所有學生成績 *\n"); printf("****** 4.成績名次排序(總分)*\n"); printf("****** 5.查看成績最優最差 *\n"); printf("****** 6.返回主菜單 *\n"); printf("-------------------------\n"); printf("please you select 1-6:"); } //定義全局靜態變量,統計目前結構體數組中的人數 static int count = 10; //主函數 int main(int argc, const char * argv[]) { int nums,temp; int snos; char names[20]; while(1) { PrintScreen(); printf("please press enter_key continue!\n"); getchar(); printf("please select 0-4:"); char c = getchar(); switch(c) { case '1': printf("please student'numbers you want to add:"); scanf("%d",&nums); add(stu,count,nums); //添加數據 getchar(); break; case '2': deleteScreen(); scanf("%d",&temp); switch(temp) { case 0: printf("please input delete name:"); scanf("%s",names);; Delete_name(stu,names); //刪除數據(按姓名刪除) break; case 1: printf("please input delete sno:"); scanf("%d",&snos); Delete_sno(stu,snos); //刪除數據(按學號刪除) break; case 2: break; } getchar(); break; case '3': menu(stu,count);//查找數據 getchar(); break; case '4': printf("please input update sno:"); scanf("%d",&snos); update(stu,snos,count); //修改數據 break; case '0': exit(0); //退出系統 default: printf("data is illeagel!\n"); getchar(); break; //輸入非法 } } return 0; } //添加數據 void add(struct Student stu[],int pos,int nums)//開始位置、添加人數 { for(int i=pos;i<pos+nums;i++) { printf("please input name:"); scanf("%s",stu[i].name); int flag = 1,sno; while(flag) { printf("please input sno:"); scanf("%d",&sno); for(int j=0;j<pos;j++) { if(stu[j].sno==sno) { printf("sno is exist!\n"); break; } else { flag = 0; } } stu[i].sno = sno; } printf("please input age:"); scanf("%d",&stu[i].age); printf("please input gender:(f/m or F/M)"); getchar(); scanf("%c",&stu[i].gender); printf("please input EnglishScore:"); scanf("%f",&stu[i].EnglishScore); printf("please input mathScore:"); scanf("%f",&stu[i].mathScore); printf("please input ChineseScore:"); scanf("%f",&stu[i].chineseScore); printf("學生信息添加成功!\n"); } count = count + nums; } //按學號刪除 void Delete_sno(struct Student *stu,int Sno) { if(count==0) { printf("成員已為空!\n"); return; } int flag=0; for(int i=0;i<count;i++) { if((stu+i)->sno==Sno) { for(int j=i;j<count;j++) { *(stu+j)=*(stu+j+1); } printf("\n"); printf("學號為%d的學生已被刪除\n",Sno); printf("\n"); flag=1; count = count-1; break; } } if(flag==0) printf("學號%d不存在.\n",Sno); } //按姓名刪除 void Delete_name(struct Student *stu,char Name[]) { if(count==0) { printf("成員已為空!\n"); return; } int flag=0; int n=count; for(int i=0;i<n;i++) { if(strcmp((stu+i-flag)->name,Name)==0) { for(int j=i-flag;j<count;j++) { *(stu+j)=*(stu+j+1); } printf("\n"); printf("學生:%s 已被刪除.\n",Name); printf("\n"); flag=flag+1; count =count -1; } } if(flag==0) printf("學生:%s 不存在.\n",Name); } //修改數據 void update(struct Student stu[],int sno,int len) { char cs,cs1,cs2,cs3; char p[20]; int grade,i; for(i=0; i<len; i++) { if(sno==stu[i].sno) { printf("please ask update name?(y/n):"); getchar(); cs = getchar(); if(cs == 'y') { printf("please input a new name:"); scanf("%s",p); getchar(); strcpy(stu[i].name,p); printf("update is succeed!\n"); } printf("please ask update EnglishScore?(y/n):"); cs1 = getchar(); if(cs1 == 'y') { printf("please input a new grade:"); scanf("%d",&grade); stu[i].EnglishScore = grade; printf("update is succeed!\n"); } printf("please ask update mathScore?(y/n):"); getchar(); cs2 = getchar(); if(cs2 == 'y') { printf("please input a new grade:"); scanf("%d",&grade); stu[i].mathScore = grade; printf("update is succeed!\n"); } printf("please ask update chineseScore?(y/n):"); getchar(); cs3 = getchar(); if(cs3 == 'y') { printf("please input a new grade:"); scanf("%d",&grade); stu[i].chineseScore = grade; printf("update is succeed!\n"); break; } else { getchar(); break; } } else if(i==len-1) { printf("error,don't have the sno!"); break; } else { continue; } } } //查詢數據 void menu(struct Student stu[],int m) { int logel = 1; while(logel) { seekScreen(); int n; scanf("%d",&n); char name[20]; int num; switch(n) { case 1 : printf("請輸入同學的姓名: "); scanf("%s",name); search(stu,count,name); break; case 2 : printf("\n請輸入同學的學號: "); scanf("%d",&num); search2(stu,count,num); break; case 3: print(stu,count); break; case 4: sort(stu,count); print(stu,count); break; case 5: max_min(stu,count); break; case 6: logel = 0; break; default: logel = 0; printf("輸入數字有誤!\n"); break; } } } void search(struct Student stu[],int n,char Name[]) { char* p= Name; int flag = 0; for(int i=0;i<n;i++) { if(strcmp(stu[i].name,p)==0) { flag = 1; My_print_sum(stu,i); } } if(flag==0) { printf("the name is not exist!\n"); } } void search2(struct Student stu[],int n,int Num) { int flag = 0; for(int i=0;i<n;i++) { if(Num==stu[i].sno) { flag = 1; My_print_sum(stu,i); } } if(flag==0) { printf("the sno is not exist!\n"); } } void sort(struct Student stu[],int n) { float sum[N]; for(int i=0;i<n;i++) { sum[i]=stu[i].EnglishScore+stu[i].mathScore+stu[i].chineseScore; } for(int i=0;i<n-1;i++) { for(int j=0;j<n-1-i;j++) { if(sum[j]<sum[j+1]) { float temp1 = sum[j]; sum[j] = sum[j+1]; sum[j+1] = temp1; struct Student temp; temp=stu[j]; stu[j]=stu[j+1]; stu[j+1]=temp; } } } } void max_min(struct Student stu[],int n) { sort(stu,n); printf("成績最優的同學:"); My_print_sum(stu,0); printf("成績最差的同學:"); My_print_sum(stu,n-1); } void print(struct Student stu[],int n) { for(int i=0;i<n;i++) { My_print_sum(stu,i); } } void My_print_sum(struct Student stu[],int n) { printf("\n姓名:%s,學號:%d,年齡:%d,性別:%c,英語:%.2f,數學:%.2f,語文: %.2f,總分:%.2f\n", stu[n].name,stu[n].sno,stu[n].age,stu[n].gender, stu[n].EnglishScore,stu[n].mathScore,stu[n].chineseScore,(stu[n].EnglishScore+stu[n].mathScore+stu[n].chineseScore)); }
以上就是關于“怎么用C語言實現學生成績管理系統”這篇文章的內容,相信大家都有了一定的了解,希望小編分享的內容對大家有幫助,若想了解更多相關的知識內容,請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。