C语言实现学生成绩管理系统项目
程序员文章站
2022-06-15 15:01:25
本文实例为大家分享了c语言实现学生成绩管理系统项目,供大家参考,具体内容如下1、数据结构:学生信息:学号、姓名、年龄、性别、3课成绩2、功能:(1) 增加学生记录(2) 删除学生记录(3) 查找学生信...
本文实例为大家分享了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)); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。