C語言實現(xiàn)學生成績管理系統(tǒng)項目
更新時間:2022年01月31日 12:45:16 作者:XYQ全哥
這篇文章主要為大家詳細介紹了C語言實現(xiàn)學生成績管理系統(tǒng)項目,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C語言實現(xiàn)學生成績管理系統(tǒng)項目,供大家參考,具體內(nèi)容如下
1、數(shù)據(jù)結構:學生信息:學號、姓名、年齡、性別、3課成績
2、功能:
(1) 增加學生記錄
(2) 刪除學生記錄
(3) 查找學生信息(學號、姓名)
(4) 修改學生信息
(5) 按照成績排序、求平均值、最大值、最小值
3、用戶界面
主菜單
子菜單
4、 批量生成測試數(shù)據(jù)
// // ?main.c // ?Student System // // ?Created by ma c on 15/7/22. // ?Copyright (c) 2015年. All rights reserved. // ?要求:編寫一個學生成績管理系統(tǒng)。 #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}}; //添加數(shù)據(jù) void add(struct Student stu[],int pos,int nums); //刪除數(shù)據(jù) void Delete_name(struct Student *stu,char Name[]);//(按姓名) void Delete_sno(struct Student *stu,int Sno);//(按學號) //修改數(shù)據(jù) 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 search1(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.退出管理系統(tǒng) **\n"); ? ? printf("------------------\n"); } //刪除子菜單 void deleteScreen() { ? ? printf("------------------\n"); ? ? printf("** 0.按姓名刪除數(shù)據(jù)**\n"); ? ? printf("** 1.按學號刪除數(shù)據(jù)**\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.查看成績最優(yōu)最差 ?*\n"); ? ? printf("****** 6.返回主菜單 ? ? ? *\n"); ? ? printf("-------------------------\n"); ? ? printf("please you select 1-6:"); } //定義全局靜態(tài)變量,統(tǒng)計目前結構體數(shù)組中的人數(shù) static int count = 10; //主函數(shù) 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); ? ? ?//添加數(shù)據(jù) ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? break; ? ? ? ? case '2': ? ? ? ? ? ? ? deleteScreen(); ? ? ? ? ? ? ? scanf("%d",&temp); ? ? ? ? ? ? ? switch(temp) ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? case 0: ? ? ? ? ? ? ? ? ? ? ? printf("please input delete name:"); ? ? ? ? ? ? ? ? ? ? ? scanf("%s",names);; ? ? ? ? ? ? ? ? ? ? ? Delete_name(stu,names); ?//刪除數(shù)據(jù)(按姓名刪除) ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? case 1: ? ? ? ? ? ? ? ? ? ? ? printf("please input delete sno:"); ? ? ? ? ? ? ? ? ? ? ? scanf("%d",&snos); ? ? ? ? ? ? ? ? ? ? ? Delete_sno(stu,snos); //刪除數(shù)據(jù)(按學號刪除) ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? case 2: ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? } ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? break; ? ? ? ? case '3': ? ? ? ? ? ? ? menu(stu,count);//查找數(shù)據(jù) ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? break; ? ? ? ? case '4': ? ? ? ? ? ? ? printf("please input update sno:"); ? ? ? ? ? ? ? scanf("%d",&snos); ? ? ? ? ? ? ? update(stu,snos,count); ? ? //修改數(shù)據(jù) ? ? ? ? ? ? ? break; ? ? ? ? case '0': ? ? ? ? ? ? ? exit(0); ? ? ? ? ? ? ? ? ? ?//退出系統(tǒng) ? ? ? ? default: ? ? ? ? ? ? ? printf("data is illeagel!\n"); ? ? ? ? ? ? ? getchar(); ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ?//輸入非法 ? ? } ?} ?return 0; } //添加數(shù)據(jù) void add(struct Student stu[],int pos,int nums)//開始位置、添加人數(shù) { ? ? 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); } //修改數(shù)據(jù) 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; ? ? ? ? } ? ? } } //查詢數(shù)據(jù) 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); ? ? ? ? ? ? ? ? search1(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("輸入數(shù)字有誤!\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 search1(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("成績最優(yōu)的同學:"); ? ? 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,數(shù)學:%.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)); }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C語言實現(xiàn)學生信息管理系統(tǒng)開發(fā)
這篇文章主要為大家詳細介紹了C語言實現(xiàn)學生信息管理系統(tǒng)開發(fā),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-08-08C語言實現(xiàn)訪問及查詢MySQL數(shù)據(jù)庫的方法
這篇文章主要介紹了C語言實現(xiàn)訪問及查詢MySQL數(shù)據(jù)庫的方法,涉及C語言基于libmysql.lib實現(xiàn)訪問MySQL數(shù)據(jù)庫的相關操作技巧,需要的朋友可以參考下2018-01-01