我真的很想帮你,但是我没有时间,我建议你还是自己做一做
这里是我以前刚学C语言时的一个学员管理系统
有人员信息的增删改查,可以用两中不同方法排序数据
退出时自动保存数据,保存在C盘根目录下
分两级菜单,是中文的,使用方便
代码共500行左右,记得当时只用了几小时时间,为了省事
没有分文件,也没有加注释,但是这些问题不大
基本上你这个题目要求的功能我都实现了
你只要自己修改一下就可以了
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
typedef struct
{
double chinese;
double math;
double english;
double history;
double aveScore;
}score;
typedef struct
{
int num;
char name[10];
char sex[10];
score myscore;
}student;
student students[30];
int number=0;
int sortbyscore=0;
void sortByNum()
{
int i,j;
student stu;
for(i=number;i>0;i--)
{
for(j=0;j<i-1;j++)
{
if(students[j].num>students[j+1].num)
{
stu=students[j];
students[j]=students[j+1];
students[j+1]=stu;
}
}
}
}
void sortByScore()
{
int i,j;
student stu;
for(i=number;i>0;i--)
{
for(j=0;j<i-1;j++)
{
if(students[j].myscore.aveScore<students[j+1].myscore.aveScore)
{
stu=students[j];
students[j]=students[j+1];
students[j+1]=stu;
}
}
}
}
void setupSort()
{
int select;
system("cls");
//setupMenu();
printf("请选择学员排序方式:\n");
printf("1.按学号排序\n");
printf("2.按平均成绩排序\n");
printf("请选择:");
scanf("%d",&select);
switch(select)
{
case 1:
sortbyscore=0;
break;
case 2:
sortbyscore=1;
break;
default:
printf("输入有误,按任意键重新输入!");
getch();
break;
}
}
void setupMenu()
{
int select;
system("cls");
printf(" **********************************\n");
printf(" * 系统设置 *\n");
printf(" **********************************\n");
printf(" * 1.设置排序方式 *\n");
printf(" * 2.分数显示方式 *\n");
printf(" **********************************\n");
printf("请选择功能:");
scanf("%d",&select);
switch(select)
{
case 1:
setupSort();
break;
case 2:
default:
break;
}
}
void inputScore()
{
double sum=0;
printf("请输入语文成绩:");
scanf("%lf",&students[number].myscore.chinese);
sum+=students[number].myscore.chinese;
printf("请输入数学成绩:");
scanf("%lf",&students[number].myscore.math);
sum+=students[number].myscore.math;
printf("请输入英语成绩:");
scanf("%lf",&students[number].myscore.english);
sum+=students[number].myscore.english;
printf("请输入历史成绩:");
scanf("%lf",&students[number].myscore.history);
sum+=students[number].myscore.history;
students[number].myscore.aveScore=sum/4;
}
void display()
{
int i;
if(sortbyscore)
sortByScore();
else
sortByNum();
system("cls");
for (i=0;i<number;i++)
{
printf("学号:%d\n",students[i].num);
printf("姓名:%s\n",students[i].name);
printf("性别:%s\n",students[i].sex);
printf("语文:%.2f\n",students[i].myscore.chinese);
printf("数学:%.2f\n",students[i].myscore.math);
printf("英语:%.2f\n",students[i].myscore.english);
printf("历史:%.2f\n",students[i].myscore.history);
if (i==number-1)
break;
printf("\v\n");
}
if (number==0)
printf("没有学员信息!\n");
printf("按任意键返回主菜单!\n");
fflush(stdin);
getch();
}
int isItNumber(char num[20])
{
int i;
for(i=0;i<(signed)strlen(num);i++)
{
if(!isdigit(num[i]))
return 1;
}
return 0;
}
int stringToNumber(char string[20])
{
int num=1;
int sum=0;
int i;
for(i=strlen(string)-1;i>=0;i--)
{
sum+=((int)string[i]-48)*num;
num*=10;
}
return sum;
}
void inputnum()
{
char num[20];
int NaN;
int i;
int j;
do
{
j=0;
system("cls");
printf("请输入学号:");
fflush(stdin);
scanf("%s",num);
NaN=isItNumber(num);
if(NaN)
{
j=1;
printf("只能输入数字!按任意键重新输入!\n");
getch();
continue;
}
students[number].num=stringToNumber(num);
for(i=0;i<number;i++)
{
if(students[number].num==students[i].num)
{
printf("这个学号已经有人用了!\n");
printf("按任意键重新输入!");
getch();
j=1;
}
}
}while(j);
}
void inputname()
{
int i;
do
{
printf("请输入姓名:");
fflush(stdin);
gets(students[number].name);
for(i=0;i<(signed)strlen(students[number].name);i++)
{
if(isdigit(students[number].name[i]))
{
printf("姓名中不能有数字,请重新输入!\n");
break;
}
}
}while(i!=(signed)strlen(students[number].name));
}
void input()
{
char sel;
do
{
if (number==30)
{
printf("\n数量已满!");
break;
}
inputnum();
inputname();
printf("请输入性别:");
fflush(stdin);
scanf("%s",students[number].sex);
inputScore();
++number;
do
{
printf("是否继续输入(y/n):");
fflush(stdin);
sel=getchar();
if (sel!='Y' && sel!='y' && sel!='N' && sel!='n')
printf("输入有误,请重新输入!\n");
else
break;
}while (1);
if (sel=='N' || sel=='n')
break;
}while (1);
}
int haveOrNot()
{
if (number==0)
{
system("cls");
printf("没有学员信息!");
printf("\n按任意键返回主菜单!\n");
fflush(stdin);
getch();
return 0;
}
return 1;
}
int searchStudent(int search)
{
int i;
for(i=0;i<number;i++)
{
if(search==students[i].num)
{
printf("\n你想删除的学员是:\n");
printf("学号:%d\n",students[i].num);
printf("姓名:%s\n",students[i].name);
printf("性别:%s\n",students[i].sex);
return i;
}
}
return -1;
}
int makeSelect()
{
int select;
while (1)
{
fflush(stdin);
printf("\n接下来你要做什么?");
printf("\n1.返回主菜单。");
printf("\n2.继续删除学员。");
printf("\n请选择:");
scanf("%d",&select);
if (select!=1 && select!=2)
{
printf("\n输入有误,请重新输入!");
continue;
}
break;
}
if(select==1)
return 1;
else
return 0;
}
void delstudent()
{
int haveRecord;
int key;
int i;
int del;
char select;
do
{
haveRecord=haveOrNot();
if(!haveRecord)
break;
system("cls");
printf("请输入你要删除的学员的学号:");
scanf("%d",&del);
i=searchStudent(del);
while(i!=-1)
{
printf("是否确认删除(y/n):");
fflush(stdin);
select=getchar();
if (select=='Y' || select=='y')
{
for(i+=1;i<=number;i++)
{
students[i-1]=students[i];
}
number -= 1;
break;
}
else if(select=='N' || select=='n')
break;
else
{
printf("\n输入有误,请重新输入!\n");
continue;
}
}
if(i==-1)
printf("\n对不起,没有找到你要删除的学员!");
key=makeSelect();
}while(!key);
}
void save()
{
FILE *fp1,*fp2;
if((fp1=fopen("C:\\studentnum.dat","wb"))!=NULL)
{
fwrite(&number,sizeof(int),1,fp1);
fclose(fp1);
}
if((fp2=fopen("C:\\students.dat","wb"))!=NULL)
{
fwrite(students,sizeof(student),number,fp2);
fclose(fp2);
}
}
void load()
{
FILE *fp1,*fp2;
if((fp1=fopen("C:\\studentnum.dat","rb"))!=NULL)
{
fread(&number,sizeof(int),1,fp1);
fclose(fp1);
}
if((fp2=fopen("C:\\students.dat","rb"))!=NULL)
{
fread(students,sizeof(student),number,fp2);
fclose(fp2);
}
}
void main()
{
int select;
load();
do
{
fflush(stdin);
system("cls");
printf(" **********************************\n");
printf(" * 欢迎使用学员管理系统 *\n");
printf(" **********************************\n");
printf(" * 1.添加新学员 *\n");
printf(" * 2.显示学员信息 *\n");
printf(" * 3.删除学员信息 *\n");
printf(" * 4.系统设置 *\n");
printf(" * 0.退出 *\n");
printf(" **********************************\n");
printf("请选择功能:");
scanf("%d",&select);
switch (select)
{
case 1:
input();
break;
case 2:
display();
break;
case 3:
delstudent();
break;
case 4:
//setup();
setupMenu();
break;
case 0:
save();
exit(0);
default:
printf("输入有误,按任意键重新输入!");
getch();
}
}while(1);
}
温馨提示:答案为网友推荐,仅供参考