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 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.退出管理系统 **\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); 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("输入数字有误!\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("成绩最优的同学:"); 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)); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
赞 (0)