我以前的课程设计,你要的功能应该都有吧...至于其他的,你可以看情况自由修改.
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
#include "string.h"
struct student
{
int num;
char name[20];
float score1;
float score2;
float average;
};
struct student stu[50];
struct student avg;
int count=0,passwd=123;
int k=0;
void input();
void display();
void sort();
void sort_name();
void sort_score1();
void sort_score2();
void sort_average();
void query();
void query_num();
void query_name();
void update();
void update_num();
void update_name();
void re();
void re_num();
void re_name();
void renew();
void renew_num();
void renew_name();
void pa();
void s();
void main()
{
int p;
system("cls");
printf("\n\n\n\n\n\n\n\t\t\t请输入密码: ");
scanf("%d",&p);
if (p==passwd)
s();
else
{
printf("\n\n\n\n密码输入错误!任意键重新输入!");
getch();
main();
}
}
void s()
{
int select;
system("cls");
printf("----------------学生成绩管理系统----------------\n\n\n");
printf("1.录入\n2.显示\n3.排序\n4.查询\n5.修改\n6.删除\n7.恢复\n8.退出\n\n");
printf("请选择: ");
scanf("%d",&select);
switch(select)
{
case 1:
input();
break;
case 2:
display();
break;
case 3:
sort();
break;
case 4:
query();
break;
case 5:
update();
break;
case 6:
re();
break;
case 7:
renew();
break;
case 8:
break;
default:
printf("选择错误!");
break;
}
}
void input()
{
char select;
system("cls");
printf("学生成绩录入\n\n");
do
{
printf("\n请输入第%d个学生信息\n\n",count+1);
printf("学号: ");
scanf("%d",&stu[count].num);
printf("姓名: ");
scanf("%s",stu[count].name);
printf("成绩一:");
scanf("%f",&stu[count].score1);
printf("成绩二:");
scanf("%f",&stu[count].score2);
stu[count].average=(stu[count].score1+stu[count].score2)/2;
printf("是否继续输入(y/n): ");
fflush(stdin);
select=getchar();
count++;
}while(select=='y'||select=='Y');
if (select=='n'||select=='N')
{
s();
}
}
void display()
{
int i;
system("cls");
printf("学生成绩显示:\n\n");
printf("%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("%-8s%-12s%-12s%-12s%s\n","====","========","=======","========","========");
for (i=0;i<count;i++)
{
printf("%-8d%-12s%-12.2f%-12.2f%.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].average);
}
printf("任意键返回主菜单......");
getch();
s();
}
void sort()
{
int select;
system("cls");
printf("学生成绩排序:\n\n\n");
printf("\n\t\t\t1.按姓名排序\n\t\t\t2.按成绩一排序\n\t\t\t3.按成绩二排序\n\t\t\t4.按平均分排序\n\t\t\t5.返回\n\n");
printf("请选择: ");
scanf("%d",&select);
switch(select)
{
case 1:
sort_name();
break;
case 2:
sort_score1();
break;
case 3:
sort_score2();
break;
case 4:
sort_average();
break;
case 5:
s();
break;
default:
printf("输入错误!任意键返回主菜单!");
getch();
s();
break;
}
}
void sort_name()
{
int i;
struct student temp;
system("cls");
printf("按姓名排序: \n\n");
printf("%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("%-8s%-12s%-12s%-12s%s\n","====","========","=======","========","========");
for (i=0;i<count;i++)
{
if (strlen(stu[i].name)<strlen(stu[i+1].name))
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
for (i=0;i<count;i++)
{
printf("%-8d%-12s%-12.2f%-12.2f%.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].average);
}
printf("任意键返回......");
getch();
sort();
}
void sort_score1()
{
int i;
struct student temp;
system("cls");
printf("按成绩一排序: \n\n");
printf("%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("%-8s%-12s%-12s%-12s%s\n","====","========","=======","========","========");
for (i=0;i<count;i++)
{
if (stu[i].score1<stu[i+1].score1)
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
for (i=0;i<count;i++)
{
printf("%-8d%-12s%-12.2f%-12.2f%.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].average);
}
printf("任意键返回......");
getch();
sort();
}
void sort_score2()
{
int i;
struct student temp;
system("cls");
printf("按成绩一排序: \n\n");
printf("%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("%-8s%-12s%-12s%-12s%s\n","====","========","=======","========","========");
for (i=0;i<count;i++)
{
if (stu[i].score2<stu[i+1].score2)
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
for (i=0;i<count;i++)
{
printf("%-8d%-12s%-12.2f%-12.2f%.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].average);
}
printf("任意键返回......");
getch();
sort();
}
void sort_average()
{
int i;
struct student temp;
system("cls");
printf("按平均分排序: \n\n");
printf("%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("%-8s%-12s%-12s%-12s%s\n","====","========","=======","========","========");
for (i=0;i<count;i++)
{
if (stu[i].average<stu[i+1].average)
{
temp=stu[i];
stu[i]=stu[i+1];
stu[i+1]=temp;
}
}
for (i=0;i<count;i++)
{
printf("%-8d%-12s%-12.2f%-12.2f%.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].average);
}
printf("任意键返回......");
getch();
sort();
}
void query()
{
int select;
system("cls");
printf("学生成绩查询:");
printf("\n\n\n\t\t\t1.按学号查询\n\n\t\t\t2.按姓名查询\n\n\t\t\t3.返回");
printf("\n\n请选择: ");
scanf("%d",&select);
switch(select)
{
case 1:
query_num();
break;
case 2:
query_name();
break;
case 3:
s();
break;
default:
printf("输入错误!任意键返回主菜单!");
getch();
s();
}
}
void query_num()
{
int q,i;
system("cls");
printf("按学生学号查询:\n\n");
printf("请输入要查询学生的学号:");
scanf("%d",&q);
for (i=0;i<count;i++)
{
if (stu[i].num==q)
{
printf("\n%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("%-8s%-12s%-12s%-12s%s\n","====","========","=======","========","========");
printf("%-8d%-12s%-12.2f%-12.2f%.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].average);
printf("查询完毕,任意键返回!");
getch();
query();
break;
}
else
continue;
}
printf("对不起,您所查询的学生不存在!任意键返回!");
getch();
query();
}
void query_name()
{
int i,j;
char find[20];
system("cls");
printf("按学生姓名查询\n\n\n");
printf("输入要查询的学生的姓名: ");
scanf("%s",find);
for (i=0;i<count;i++)
{
j=strcmp(find,stu[i].name);
if (j==0)
{
printf("\n%-8s%-12s%-12s%-12s%s\n","学号","姓 名","成绩一","成绩二","平均成绩");
printf("%-8s%-12s%-12s%-12s%s\n","====","========","=======","========","========");
printf("%-8d%-12s%-12.2f%-12.2f%.2f\n",stu[i].num,stu[i].name,stu[i].score1,stu[i].score2,stu[i].average);
printf("\n\n查询完毕,任意键返回!");
getch();
query();
break;
}
else
continue;
}
printf("对不起,您所查询的学生不存在!任意键返回!");
getch();
query();
}
void update()
{
int select;
system("cls");
printf("修改学生信息:\n\n\n");
printf("\t\t\t1.按学号修改\n\n\t\t\t2.按姓名修改\n\n\t\t\t3.返回");
printf("\n\n请选择:");
scanf("%d",&select);
switch(select)
{
case 1:
update_num();
break;
case 2:
update_name();
break;
case 3:
s();
break;
default:
printf("输入错误!任意键返回!");
getch();
s();
break;
}
}
void update_num()
{
int i,find;
system("cls");
printf("按学生学号修改: \n\n");
printf("请输入要修改的学生的学号: ");
scanf("%d",&find);
for (i=0;i<count;i++)
{
if (stu[i].num==find)
{
printf("\n\n学号: ");
scanf("%d",&stu[i].num);
printf("姓名: ");
scanf("%s",stu[i].name);
printf("成绩一: ");
scanf("%f",&stu[i].score1);
printf("成绩二: ");
scanf("%f",&stu[i].score2);
printf("修改成功!任意键返回主菜单!");
getch();
s();
break;
}
else
continue;
}
printf("您所要修改的学生不存在,任意键返回主菜单!");
getch();
s();
}
void update_name()
{
int i,j=0;
char find[20];
system("cls");
printf("按学生姓名修改: \n\n");
printf("请输入要修改的学生的姓名: ");
scanf("%s",find);
for (i=0;i<count;i++)
{
j=strcmp(find,stu[i].name);
if (j==0)
{
printf("\n\n学号: ");
scanf("%d",&stu[i].num);
printf("姓名: ");
scanf("%s",stu[i].name);
printf("成绩一: ");
scanf("%f",&stu[i].score1);
printf("成绩二: ");
scanf("%f",&stu[i].score2);
printf("修改成功!任意键返回主菜单!");
getch();
s();
break;
}
else
continue;
}
printf("您所要修改的学生不存在,任意键返回主菜单!");
getch();
s();
}
void re()
{
int select;
system("cls");
printf("删除学生信息: \n\n\n");
printf("\t\t\t1.按学号删除\n\n\t\t\t2.按姓名删除\n\n\t\t\t3.返回\n\n");
printf("请选择: ");
scanf("%d",&select);
switch(select)
{
case 1:
re_num();
break;
case 2:
re_name();
break;
case 3:
s();
break;
default:
printf("输入错误!任意键返回!");
getch();
s();
}
}
void re_num()
{
int i,find,j;
system("cls");
printf("按学号删除学生信息: \n\n");
printf("请输入要删除的学生的学号: ");
scanf("%d",&find);
for (i=0;i<count;i++)
{
if (stu[i].num==find)
{
j=1;
k=i;
avg=stu[i];
break;
}
else
continue;
}
if (j!=1)
{
printf("您所删除的学生不存在!任意键返回主菜单!");
getch();
s();
}
else
for (i=k;i<count-1;i++)
{
stu[i]=stu[i+1];
}
printf("删除成功!任意键返回主菜单!");
count--;
getch();
s();
}
void re_name()
{
int i,j,m;
char find[20];
system("cls");
printf("按姓名删除学生信息: \n\n");
printf("请输入要删除的学生的姓名: ");
scanf("%s",find);
for (i=0;i<count;i++)
{
m=strcmp(find,stu[i].name);
if (m==0)
{
j=1;
k=i;
avg=stu[i];
break;
}
else
continue;
}
if (j!=1)
{
printf("您所删除的学生不存在!任意键返回主菜单!");
getch();
s();
}
else
for (i=k;i<count-1;i++)
{
stu[i]=stu[i+1];
}
printf("删除成功!任意键返回主菜单!");
count--;
getch();
s();
}
void renew()
{
int select;
system("cls");
printf("恢复学生信息: \n\n\n");
printf("\t\t\t1.按学号恢复\n\n\t\t\t2.按姓名恢复\n\n\t\t\t3.返回\n\n");
printf("请选择: ");
scanf("%d",&select);
switch(select)
{
case 1:
renew_num();
break;
case 2:
renew_name();
break;
case 3:
s();
break;
default:
printf("输入错误!任意键返回!");
getch();
s();
}
}
void renew_num()
{
int i,del;
system("cls");
printf("请输入要恢复的学生的学号: ");
scanf("%d",&del);
if (del==avg.num)
{
for (i=k;i<count;i++)
{
stu[i+1]=stu[i];
stu[i]=avg;
break;
}
}
else
{
printf("您要恢复的学生不存在,任意键返回主菜单!");
getch();
s();
}
count++;
printf("恢复成功!");
getch();
s();
}
void renew_name()
{
int i,j;
char del[20];
system("cls");
printf("请输入要恢复的学生的姓名: ");
scanf("%s",del);
j=strcmp(del,avg.name);
if (j==0)
{
for (i=k;i<count;i++)
{
stu[i+1]=stu[i];
stu[i]=avg;
break;
}
}
else
{
printf("您要恢复的学生不存在,任意键返回主菜单!");
getch();
s();
}
count++;
printf("恢复成功!");
getch();
s();
}