设计一个学生的学分管理程序
发布网友
发布时间:2022-05-26 21:26
我来回答
共3个回答
热心网友
时间:2023-11-05 09:47
大一时自己写的一个东西。。。很简单的一个,不要笑。。你的那个太难了。。
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
struct student{
int num;
char name[10];
int yuwen;
int shuxue;
int yingyu;
int kexue;
int sum;
}record[50];
void readin();
void display();
void find();
void order();
void add();
void del();
int menu_select();
int m=5;
extern float sum1 =0;
extern float sum2=0;
extern float sum3=0;
extern float sum4 =0;
extern int w = 0;
void main()
{
for(;;){
switch(menu_select()){
case 1:
readin();
break;
case 2:
display();
break;
case 3:
order();
break;
case 4:
find();
break;
case 5:
add();
break;
case 6:
del();
break;
case 7:
printf("Goodbye!\n");
exit(0);
}
}
}
//菜单选择
int menu_select()
{
char s;
int cn;
printf("1.输入5个人的数据\n");
printf("2.显示数据\n");
printf("3.数据排序\n");
printf("4.查询数据\n");
printf("5.增加数据\n");
printf("6.删除数据\n");
printf("7.Goodbye\n");
printf("Input 1-7:");
do{
s=getchar();
cn=int(s)-48;
}while(cn<0||cn>7);
return cn;
}
//显示数据
void display()
{
char *c[7]={"学号","姓名","语文","数学","英语","科学","总成绩"};
char *d[1]={"平均成绩"};
int i;
printf("\n%8s\t%8s\t%4s\t%4s\t%4s\t%4s\t%4s\n",c[0],c[1],c[2],c[3],c[4],c[5],c[6]);
sum1 = 0;
sum2 = 0;
sum3 = 0;
sum4 = 0;
for(i=0;i<50;i++)
{
record[i].sum=0;
record[i].sum=record[i].sum+record[i].yuwen+record[i].shuxue+record[i].yingyu+record[i].kexue;
if(record[i].sum==0) break;
printf("\n%8d\t%8s\t%4d\t%4d\t%4d\t%4d\t%4d",record[i].num,record[i].name,record[i].yuwen,record[i].shuxue,record[i].yingyu,record[i].kexue,record[i].sum);
sum1=sum1+record[i].yuwen;
sum2=sum2+record[i].shuxue;
sum3=sum3+record[i].yingyu;
sum4=sum4+record[i].kexue;
}
w = i+1;
record[i+1].sum = 0;
printf("\n%8s\t\t\t %3.1f %3.1f %3.1f %3.1f",d[0],sum1/m,sum2/m,sum3/m,sum4/m);
printf("\n");
}
//输入数据
void readin()
{
char ch[10];
int i;
printf("输入数据\n");
for(i=0;i<5;i++)
{
printf("学号:");
scanf("%d",&record[i].num);
printf("姓名:");
getchar();
gets(ch);
strcpy(record[i].name,ch);
printf("语文:");
scanf("%d",&record[i].yuwen);
printf("数学:");
scanf("%d",&record[i].shuxue);
printf("英语:");
scanf("%d",&record[i].yingyu);
printf("科学:");
scanf("%d",&record[i].kexue);
}
printf("输入结束!\n");
}
//排序
void order()
{
struct student t;
int i,j;
char *c[7]={"学号","姓名","语文","数学","英语","科学","总成绩"};
char *d[1]={"平均成绩"};
for(i=0;i<50;i++)
{
record[i].sum=record[i].yuwen+record[i].shuxue+record[i].yingyu+record[i].kexue;
if(record[i].sum==0) break;
}
for(i=0;i<w;i++)
{
if(record[i].sum==0) break;
for(j=0;j<50;j++){
if(record[i].sum>record[j].sum)
{
t=record[i];
record[i]=record[j];
record[j]=t;
}
}
}
printf("\n");
printf("\n%8s\t%8s\t%4s\t%4s\t%4s\t%4s\t%4s\n",c[0],c[1],c[2],c[3],c[4],c[5],c[6]);
for(i=0;i<50;i++)
{
printf("\n%8d\t%8s\t%4d\t%4d\t%4d\t%4d\t%4d",record[i].num,record[i].name,record[i].yuwen,record[i].shuxue,record[i].yingyu,record[i].kexue,record[i].sum);
if(record[i+1].sum==0) break;
}
printf("\n%8s\t\t\t %3.1f %3.1f %3.1f %3.1f",d[0],sum1/m,sum2/m,sum3/m,sum4/m);
printf("\n");
}
//查询
void find()
{
int i;
char na[10];
printf("\n查询姓名:");
gets(na);
gets(na);
for(i=0;i<50;i++)
{
if(record[i].sum == 0)
break;
if(strcmp(na,record[i].name)==0)
printf("\n%8d\t%8s\t%4d\t%4d\t%4d\t%4d\t%4d\n",record[i].num,record[i].name,record[i].yuwen,record[i].shuxue,record[i].yingyu,record[i].kexue,record[i].sum);
}
}
//删除
void del()
{
int i,j;
char ma[10];
char *c[7]={"学号","姓名","语文","数学","英语","科学","总成绩"};
char *d[1]={"平均成绩"};
printf("请输入要删除的姓名:");
gets(ma);
gets(ma);
for(j=0;j<50;j++)
{
if(strcmp(ma,record[j].name)==0)
{ m=m-1;
if(m<=0) break;
for(i=j;i<50;i++)
{
record[i].num=record[i+1].num;
strcpy(record[i].name,record[i+1].name);
record[i].yuwen=record[i+1].yuwen;
record[i].shuxue=record[i+1].shuxue;
record[i].yingyu=record[i+1].yingyu;
record[i].kexue=record[i+1].kexue;
record[i].sum=record[i+1].sum;
}
}
}
sum1 =0;
sum2 =0;
sum3 =0;
sum4 =0;
printf("\n%8s\t%8s\t%4s\t%4s\t%4s\t%4s\t%4s\n",c[0],c[1],c[2],c[3],c[4],c[5],c[6]);
for(i=0;i<50;i++)
{
record[i].sum=0;
record[i].sum=record[i].sum+record[i].yuwen+record[i].shuxue+record[i].yingyu+record[i].kexue;
if(record[i].sum==0) break;
printf("\n%8d\t%8s\t%4d\t%4d\t%4d\t%4d\t%4d",record[i].num,record[i].name,record[i].yuwen,record[i].shuxue,record[i].yingyu,record[i].kexue,record[i].sum);
sum1=sum1+record[i].yuwen;
sum2=sum2+record[i].shuxue;
sum3=sum3+record[i].yingyu;
sum4=sum4+record[i].kexue;
}
printf("\n%8s\t\t\t %3.1f %3.1f %3.1f %3.1f",d[0],sum1/m,sum2/m,sum3/m,sum4/m);
printf("\n");
}
//增加
void add()
{
int i,k;
char ch[20];
char *c[7]={"学号","姓名","语文","数学","英语","科学","总成绩"};
char *d[1]={"平均成绩"};
printf("你要增加的人数:");
scanf("%d",&k);
for(i=0;i<k;i++)
{
printf("学号:");
scanf("%d",&record[m+i].num);
printf("姓名:");gets(ch);
strcpy(record[m+i].name,gets(ch));
printf("语文:");
scanf("%d",&record[m+i].yuwen);
printf("数学:");
scanf("%d",&record[m+i].shuxue);
printf("英语:");
scanf("%d",&record[m+i].yingyu);
printf("科学:");
scanf("%d",&record[m+i].kexue);
}
m=m+k;
w = w+k;
printf("\n%8s\t%8s\t%4s\t%4s\t%4s\t%4s\t%4s\n",c[0],c[1],c[2],c[3],c[4],c[5],c[6]);
sum1 =0;
sum2 =0;
sum3 =0;
sum4 =0;
for(i=0;i<50;i++)
{
record[i].sum=record[i].yuwen+record[i].shuxue+record[i].yingyu+record[i].kexue;
if(record[i].sum==0) break;
printf("\n%8d\t%8s\t%4d\t%4d\t%4d\t%4d\t%4d",record[i].num,record[i].name,record[i].yuwen,record[i].shuxue,record[i].yingyu,record[i].kexue,record[i].sum);
sum1=sum1+record[i].yuwen;
sum2=sum2+record[i].shuxue;
sum3=sum3+record[i].yingyu;
sum4=sum4+record[i].kexue;
}
printf("\n%8s\t\t\t %3.1f %3.1f %3.1f %3.1f",d[0],sum1/m,sum2/m,sum3/m,sum4/m);
printf("\n");
}
热心网友
时间:2023-11-05 09:47
这个是个毕业设计的项目吧!
数据库用SQL还是其他的,你都没说明啊。
如果是WinFrom的项目几天就可以完成。
悬赏分太少了。
热心网友
时间:2023-11-05 09:48
好难啊,分数好少啊