用C++做学生证管理系统,哪位高手帮我做一下,急啊,谢啦。

2024-12-13 20:01:06
推荐回答(2个)
回答1:

你太强了,悬赏分为0还想做,别个出几百分都没人做。百度知道一般是给别人回答一些技术问题,你这个问题是很难有答复的。

回答2:

#include
#include
#include
#include
#define N 100
typedef struct
{int num;
char name[10];
char sex;
char addr[10];
float score[5];
float average;
float sum;
}STU;
int i=0;
STU stu[N]={0};
FILE *fp;
void openfile();
void savefile();
void editmenu();
void findmenu();
void sort();
void stat();
void add();
void dele();
void modify();
void look();

float aver(STU *);
void main()
{char choose;

do
{
system("cls");

printf("\n\n\n\n\n\n\n");
printf(" |******Student Grade Management System******|\n");
printf(" |-------------------------------------------|\n");
printf(" | Please input option(0-9): |\n");
printf(" |-------------------------------------------|\n");
printf(" | 1--Open file |\n");
printf(" | 2--save file |\n");
printf(" | 3--Edit |\n");
printf(" | 4--View find a student |\n");
printf(" | 5--Sort information |\n");
printf(" | 6--Great student |\n");
printf(" | 0--Exit |\n");
printf(" |-------------------------------------------|\n");
printf(" | software test class2 No.38 张苒 |\n");
printf(" |-------------------------------------------|\n");
fflush(stdin);
scanf ("%c",&choose);
switch(choose)
{case '1':openfile();break;
case '2':savefile();break;
case '3':editmenu();break;
case '4':findmenu();break;
case '5':sort(); break;
case '6':stat(); break;
case '0': exit(0);
default :printf("Input error.Please again.");
}

}while(1);

}
void editmenu()
{char choose;

do
{system("cls");
printf("\n\n\n\n\n\n\n\n\n\n");
printf(" |-----------------------------------------------|\n");
printf(" | Please input option(0-3): |\n");
printf(" |-----------------------------------------------|\n");
printf(" | 1---Add record |\n");
printf(" | 2---Dele record |\n");
printf(" | 3---Modify record |\n");
printf(" | 4---look add number |\n");
printf(" | 0---Return |\n");
printf(" |-----------------------------------------------|\n");

scanf(" %c",&choose);
switch (choose)
{
case'1':add();break;
case'2':dele();break;
case'3':modify();break;
case'4':look();break;
case'0':return;
default:printf("Input error.Please again.\n");
}
} while(1);
}
void add()
{char ch;

int m;
do
{printf("please input num:");
fflush(stdin);
scanf("%d",&stu[i].num);
fflush(stdin);
printf("please input name:");
scanf("%s",stu[i].name);
fflush(stdin);
printf("please input sex:");
scanf("%c",&stu[i].sex);
fflush(stdin);
printf("please input addr:");
scanf("%s",stu[i].addr);
fflush(stdin);
printf("please input score:");
scanf("%f%f%f%f%f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2],&stu[i].score[3],&stu[i].score[4]);
fflush(stdin);
stu[i].sum=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4];
printf("sum is %.2f\n",stu[i].sum);
stu[i].average=stu[i].sum/5;
printf("average is %.2f\n",stu[i].average);
i++;
printf("if you will continue please print y else print n:\n");
fflush(stdin);
scanf("%c",&ch);
}while (ch!='n'&&ch!='N');
printf("num name sex addr score1 score2 score3 score4 score5 average sum\n");fflush(stdin);
for (m=0;m printf("%d %s %c %s %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",stu[m].num,stu[m].name,stu[m].sex,stu[m].addr,stu[m].score[0],stu[m].score[1],stu[m].score[2],stu[m].score[3],stu[m].score[4],stu[m].average,stu[m].sum);getch();
}
void look()
{

printf("you have add %d record",i);
getch();

}
void openfile()
{
if((fp=fopen("d:\\1.dat","r"))==NULL)
{
printf("cannot open infile\n");
return;
}

while (i{
fscanf(fp,"%d%s%c%s%f%f%f%f%f%f%f",&stu[i].num,stu[i].name,&stu[i].sex,stu[i].addr,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2],&stu[i].score[3],&stu[i].score[4],&stu[i].average,&stu[i].sum);
printf("%d %s %c %s %-.2f %-.2f %-.2f %-.2f %-.2f %-.2f %-.2f",stu[i].num,stu[i].name,stu[i].sex,stu[i].addr,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4],stu[i].average,stu[i].sum);
i++;
}
}
void savefile()
{int j;
FILE * fp;

}

void findmenu()
{
int n,m;
printf("please input the student number which you want to find:");
scanf("%d",&n);getchar();
for(m=0;m{if(n==stu[m].num)
printf("num:%d name:%s sex:%c addr:%s score1:%.2f score2:%.2f score3:%.2f score4:%.2f score5:%.2f average:%.2f sum:%.2f\n",stu[m].num,stu[m].name,stu[m].sex,stu[m].addr,stu[m].score[0],stu[m].score[1],stu[m].score[2],stu[m].score[3],stu[m].score[4],stu[m].average,stu[m].sum);}
getch();
}

void sort()
{ int j,m;char ch;
STU t;
printf("\naverage rank please print (a),sum rank please print (b):\n");
fflush(stdin);
scanf("%c",&ch);getchar();
if(ch=='a')
{ for (m=0;m {
for(j=0;j if(stu[j].average {
t=stu[j];
stu[j]=stu[j+1];
stu[j+1]=t;
}
}
printf("num name sex addr score1 score2 score3 score4 score5 average\n");
for(m=0;m printf("%d %s %c %s %.2f %.2f %.2f %.2f %.2f %.2f\n",stu[m].num,stu[m].name,stu[m].sex,stu[m].addr,stu[m].score[0],stu[m].score[1],stu[m].score[2],stu[m].score[3],stu[m].score[4],stu[m].average);getchar();
}
if(ch=='b')
{for(m=0;m {
for(j=m+1;j if(stu[j-1].sum {
t=stu[j];
stu[j]=stu[j-1];
stu[j-1]=t;
}
}
printf("num name sex addr score1 score2 score3 score4 score5 sum\n");
for(m=0;m printf("%d %s %c %s %.2f %.2f %.2f %.2f %.2f %.2f\n",stu[m].num,stu[m].name,stu[m].sex,stu[m].addr,stu[m].score[0],stu[m].score[1],stu[m].score[2],stu[m].score[3],stu[m].score[4],stu[m].sum);getchar();
}
}
void stat()
{
for(i=0;i<3;i++)

{
printf("num name sex addr score1 score2 score3 score4 score5 average sum\n");fflush(stdin);
printf("%d %s %c %s %-.2f %-.2f %-.2f %-.2f %-.2f %-.2f %-.2f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].addr,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4],stu[i].average,stu[i].sum);
}getchar();

}
void dele()
{int m,n;

printf("please input the student number which you want to dele:");
scanf("%d",&n);

for(m=0; m while(n==stu[m].num)
{

stu[m].num=stu[m+1].num;
strcpy(stu[m].name,stu[m+1].name);
stu[m].sex= stu[m+1].sex;
strcpy(stu[m].addr,stu[m+1].addr);
stu[m].score[0]=stu[m+1].score[0];
stu[m].score[1]=stu[m+1].score[1];
stu[m].score[2]=stu[m+1].score[2];
stu[m].score[3]=stu[m+1].score[3];
stu[m].score[4]=stu[m+1].score[4];
stu[m].average=stu[m+1].average;
stu[m].sum=stu[m+1].sum;

}

i=i-1;
}
void modify()
{ int n,m,j;
char ch;

printf("please input the student number which you want to modify:");
scanf("%d",&n);
for(m=0;m { if(n==stu[m].num)
{ printf("num:%d name:%s sex:%c addr:%s score1:%.2f score2:%.2f score3:%.2f score4:%.2f score5:%.2f average:%.2f sum:%.2f\n",stu[m].num,stu[m].name,stu[m].sex,stu[m].addr,stu[m].score[0],stu[m].score[1],stu[m].score[2],stu[m].score[3],stu[m].score[4],stu[m].average,stu[m].sum);

printf("please input (y/n):");
scanf(" ch=%c",&ch);
while(ch!='n'&&ch!='N')
{
printf("num:\n");
fflush(stdin);
scanf("%d",&stu[m].num);
fflush(stdin);
printf("name:\n");
fflush(stdin);
scanf("%s",stu[m].name);
printf("sex:\n");
fflush(stdin);
scanf("%c",&stu[m].sex);
printf("addr:\n");
fflush(stdin);
scanf("%s",stu[m].addr);
printf("input score1,score2,score3,score4,score5:\n");
for(j=0;j<5;j++)
scanf("%f",&stu[m].score[j]);
printf("average is :%.2f\n",aver(&stu[m]));

stu[m].sum=stu[m].score[0]+stu[m].score[1]+stu[m].score[2]+stu[m].score[3]+stu[m].score[4];
printf("sum is %.2f\n",stu[m].sum);fflush(stdin);
printf("if you will remodify please print [y] else print [n]:\n");
fflush(stdin);
scanf("%c",&ch);

}

}
}
}
float aver(STU *stu1)
{int j;float sum=0,average;
for(j=0;j<5;j++)
sum=sum+stu1->score[j];
average=sum/5;
return average;
}