c语言代码、求解释。
#include<stdio.h> 头文件包含输入输出头文件stdio.h#include<string.h> 头文件包含输入输出头文件string.h
#include<stdlib.h> 头文件包含输入输出头文件stdlib.h
#include<conio.h> 头文件包含输入输出头文件conio.h
struct student 自定义学生类型
{ char num[10]; 定义
char name[12];
int age;
int grade[3];
}stu[50];
int k=0;
void input();
void outputgrade();
void change();
void del();
void allgrade();
void paixu();
void main()
{
int a;
do
{
printf("\n\n ******************************************************************\n");
printf(" *"); printf("\t\twelcome enter the student management system"); printf("\t*");
printf("\n ******************************************************************\n");
printf(" *"); printf("\t 1.Access student information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 2.Change student information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 3.Delete student information"); printf("\t\t\t\t*\n");
printf(" *"); printf("\t 4.Show all student grade and sum grade"); printf("\t\t*\n");
printf(" *"); printf("\t 5.By num Sort student information and output"); printf("\t\t*\n");
printf(" *"); printf("\t 6. exit "); printf("\t\t\t\t\t*\n");
printf(" ******************************************************************\n");
printf(" Enter you choice : ");
scanf("%d",&a);
switch(a)
{
case 1:printf("\n");input();break;
case 2:printf("\n");change();break;
case 3:printf("\n");del();break;
case 4:printf("\n");allgrade();break;
case 5:printf("\n");paixu();break;
case 6:printf("\n");exit(0);break;
default:printf("\nThe choice is between 1 to 6.\n");
}
}while(a!=0);
}
void input()
{ int j;
char ch[20];
printf("\nenter student information:\n");
do
{ printf("\nnum: ");
scanf("%s",stu[k].num);
printf("name: ");
scanf("%s",stu[k].name);
printf("\nage: ");
scanf("%d",&stu[k].age);
for(j=0;j<3;j++)
{ printf("\ngrade%d: ",j+1);
scanf("%d",&stu[k].grade[j]); }
k++;
printf("\nif want continue input student information(y/n): ");
scanf("%s",ch);
}while(strcmp(ch,"y")==0||strcmp(ch,"Y")==0);
outputgrade();
}
void outputgrade()
{ int i;
printf(" the student information is:\n");
for(i=0;i<k;i++)
{ printf("\t%s \t%s \t%d \t%d \t%d \t%d",stu[i].num,stu[i].name,stu[i].age,stu[i].grade[0],stu[i].grade[1],stu[i].grade[2]);
printf("\n"); }
}
void change()
{
int i,j;
char a[20],ch[10];
printf("\nenter you want change student num:");
scanf("%s",a);
for(i=0;i<k;i++)
{
if(strcmp(stu[i].num,a)==0)
{ printf("\nyou sure want change student num(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nnum:"); scanf("%s",stu[i].num);}
printf("\nyou sure want change student name(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nname"); scanf("%s",stu[i].name);}
printf("\nyou sure want change student grade(y/n): ");
scanf("%s",ch);
printf("\n");
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
for(j=0;j<3;j++)
{ printf("grade%d:",j+1); scanf("%d",&stu[i].grade[j]); printf("\n"); }
}
}
outputgrade();
}
void del()
{
int i,j;
char c[20];
printf("\nenter you want delete num :\n");
printf("num:");
scanf("%s",&c);
for(i=0;i<3;i++)
if(strcmp(c,stu[i].num)==0) break;
for(j=i;j<=2;j++)
stu[j]=stu[j+1];
printf("\t\t\tyou had delete %s\n",c);
k--;
outputgrade();
}
void allgrade()
{ int i; float sum=0;
for(i=0;i<k;i++)
{ printf("\t%d \t%d \t%d\n",stu[i].grade[0],stu[i].grade[1],stu[i].grade[2]);
sum=sum+stu[i].grade[0]+stu[i].grade[1]+stu[i].grade[2] ; }
printf("the sum grade is %f",sum);
}
void paixu()
{ struct student temp;
int i,j;
for(i=0;i<k-1;i++)
{
for(j=i+1;j<k;j++)
{
if(stu[i].num<stu[j].num)
{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
} }
outputgrade();
}
追问:我不懂的,
能否帮忙解释下呗。
就像这样子的
#include<stdio.h> // 头文件包含输入输出头文件stdio.h
主要的是我们老师要求每句都要解释下。