C语言如何设计学生成绩管理系统

这是我们最后要做的作业...
2024-12-17 04:21:57
推荐回答(2个)
回答1:

/* Note:Your choice is C IDE */
#include "stdio.h"
#include "string.h"
#include "windows.h"
void input ();
void menu ();
void error ();
void output ();
void find ();
void sort ();
void insert ();
void del ();
void exit ();
int a,i,j,s=2;
struct stu
{
int code;
char name[20];
char type[10];
int age;
float chinese;
float english;
float math;
float computer;
float total;
float avg;
} studen[100],temp;
void main()
{
menu ();
}
void menu()
{
printf (" 学院信息管理系统\n");
printf ("***************************\n");
printf (" 【1】输入数据\n");
printf (" 【2】查找数据\n");
printf (" 【3】插入数据\n");
printf (" 【4】删除数据\n");
printf (" 【5】输出数据\n");
printf (" 【6】排序数据\n");
printf (" 【7】退出程序\n");
printf ("***************************\n");
printf ("请输入你的选择(1~7)");
scanf ("%d",&a);
system ("cls");
switch (a)
{
case 1:input ();break;
case 2:find ();break;
case 3:insert ();break;
case 4:del ();break;
case 5:output ();break;
case 6:sort ();break;
case 7:exit (0);break;
default: error ();
}
}
void input () //输入函数
{
for (i=0;i {
printf ("请输入第%d个学生学号:",i+1);
scanf ("%d",&studen[i].code);
printf ("请输入第%d个学生姓名:",i+1);
fflush (stdin);
gets (studen[i].name);
printf ("请输入第%d个学生性别:",i+1);
gets (studen[i].type);
printf ("请输入第%d个学生年龄:",i+1);
scanf ("%d",&studen[i].age);
printf ("请输入第%d个学生英文成绩:",i+1);
scanf ("%f",&studen[i].english);
printf ("请输入第%d个学生语文成绩:",i+1);
scanf ("%f",&studen[i].chinese);
printf ("请输入第%d个学生电脑成绩:",i+1);
scanf ("%f",&studen[i].computer);
printf ("请输入第%d个学生数学成绩:",i+1);
scanf ("%f",&studen[i].math);
studen[i].total+=studen[i].english+studen[i].chinese+studen[i].computer+studen[i].math;
studen[i].avg=studen[i].total/4;
printf ("***************************\n");
printf ("\n");
printf ("***************************\n");
}
system ("cls");
printf ("按回车返回主界面...");
fflush (stdin);
getchar ();
menu ();
}
void del () //删除函数
{
printf ("请输入学号:");
scanf ("%d",&a);
for (i=0;i {
if (studen[i].code==a)
{
for (j=i;j {
studen[j]=studen[j+1];
}
}

}
s--; //s=4,返回给输出函数,此时s=4
system ("cls");
printf ("删除数据成功!\n");
printf ("按回车返回主界面...");
fflush (stdin);
getchar ();
menu ();
}
void insert () //插入函数
{
system ("cls");
printf ("请输入要插入学生的信息:\n");
printf ("请输入学生学号:");
scanf ("%d",&temp.code);
printf ("请输入学生姓名:");
fflush (stdin);
gets (temp.name);
printf ("请输入学生性别:");
gets (temp.type);
printf ("请输入学生年龄:");
scanf ("%d",&temp.age);
printf ("请输入英文成绩:");
scanf ("%f",&temp.english);
printf ("请输入语文成绩:");
scanf ("%f",&temp.chinese);
printf ("请输入电脑成绩:");
scanf ("%f",&temp.computer);
printf ("请输入数学成绩:");
scanf ("%f",&temp.math);
temp.total+=temp.english+temp.chinese+temp.computer+temp.math;
temp.avg=temp.total/4;
studen[s]=temp; //将插入的新学员赋给studen[s]即studen[5],是第六个元素
s++; //s=6,返回给输出函数,此时s=6
/*for(i=0;i {
for(j=0;j {
if(studen[j].code>studen[j+1].code)
{
temp=studen[j];
studen[j]=studen[j+1];
studen[j+1]=temp;
}
}

}*/
system ("cls");
printf ("插入数据成功!\n");
printf ("按回车返回主界面...");
fflush (stdin);
getchar ();
menu ();
}

void sort () //排序函数
{
for (i=0;i {
for (j=i+1;j {
if (studen[i].avg {
temp=studen[i];
studen[i]=studen[j];
studen[j]=temp;
}
}
}
printf ("排序成功!\n");
printf ("请按回车返回主界面...");
fflush (stdin);
getchar ();
system ("cls");
menu ();
}

void find () //查找函数
{
int n,h;
char k[20];
system ("cls");
printf ("按学号查找(按1):\n");
printf ("按姓名查找(按2):\n");
printf ("请选择:");
scanf ("%d",&n);
if (n==1)
{
printf ("请输入学号:");
scanf ("%d",&h);
for (i=0;i {
if (h==studen[i].code)
break;
}
printf ("*********************\n");
printf ("学号:%d\n",studen[i].code);
printf ("姓名:%s\n",studen[i].name);
printf ("性别:%s\n",studen[i].type);
printf ("语文:%.2f\n",studen[i].chinese);
printf ("数学:%.2f\n",studen[i].math);
printf ("英语:%.2f\n",studen[i].english);
printf ("计算机:%.2f\n",studen[i].computer);
printf ("平均分:%.2f\n",studen[i].avg);
printf ("总分:%.2f\n",studen[i].total);
printf ("*********************\n");
printf ("请按回车返回主界面...");
fflush (stdin);
getchar ();
system ("cls");
menu ();
}
else if (n==2)
{
printf ("请输入姓名:");
scanf ("%s",k);
for (i=0;i {
if (strcmp (studen[i].name,k)==0)
{
printf ("*********************\n");
printf ("学号:%d\n",studen[i].code);
printf ("姓名:%s\n",studen[i].name);
printf ("性别:%s\n",studen[i].type);
printf ("语文:%.2f\n",studen[i].chinese);
printf ("数学:%.2f\n",studen[i].math);
printf ("英语:%.2f\n",studen[i].english);
printf ("计算机:%.2f\n",studen[i].computer);
printf ("平均分:%.2f\n",studen[i].avg);
printf ("总分:%.2f\n",studen[i].total);
printf ("*********************\n");
}
}
printf ("请按回车返回主界面...");
fflush (stdin);
getchar ();
system ("cls");
menu ();
}
else
{

}
}

void output () //输出函数
{
for (i=0;i {
printf ("*********************\n");
printf ("学号:%d\n",studen[i].code);
printf ("姓名:%s\n",studen[i].name);
printf ("性别:%s\n",studen[i].type);
printf ("语文:%.2f\n",studen[i].chinese);
printf ("数学:%.2f\n",studen[i].math);
printf ("英语:%.2f\n",studen[i].english);
printf ("计算机:%.2f\n",studen[i].computer);
printf ("平均分:%.2f\n",studen[i].avg);
printf ("总分:%.2f\n",studen[i].total);
printf ("*********************\n");
}
printf ("请按回车返回主界面...");
fflush (stdin);
getchar ();
system ("cls");
menu ();
}

void error () //报错函数
{
printf ("输入错误,请输入(1~7):\n");
printf ("请按回车继续...");
fflush (stdin);
getchar ();
system ("cls");
menu ();
}

回答2:

1_2缘分 的代码确实很牛。前几天我做了个通讯录的系统,不过不如人家的代码好。楼主好好看看吧。我也把这个代码收藏了。