C语言程序设计实训.docx
《C语言程序设计实训.docx》由会员分享,可在线阅读,更多相关《C语言程序设计实训.docx(30页珍藏版)》请在冰豆网上搜索。
![C语言程序设计实训.docx](https://file1.bdocx.com/fileroot1/2023-1/27/2fa73a9b-e528-4ece-82cd-0294da555fad/2fa73a9b-e528-4ece-82cd-0294da555fad1.gif)
C语言程序设计实训
#include
#include
#include
#include
#defineN100
#defineM20
/*函数的声明*/
voidmenu();
voidmenu1();
structstudent/*定义学生信息的结构体类型*/
{
charnum[20];/*学号*/
charname[20];/*姓名*/
charsex[20];/*性别*/
charclas[20];//班级
intenglish;/*英语成绩*/
intshudian;/*数电成绩*/
intmodian;/*模电成绩*/
inttiyu;//体育成绩(0/1)
floataver;/*平均成绩*/
floatsum;/*总成绩*/
}stu[N];
intn;/*声明一个全局变量*/
/*登录函数*/
intLogon()
{
charusername[M],password[M];
printf("\n请输入用户名:
");
scanf("%s",username);
printf("\n请输入密码(最多15位):
");
intj=0;
while((j>=0)&&(password[j++]=getch())!
=13)//条件i>=0是用于限制退格的范围
{
if(password[j-1]=='\b')//对退格键的处理
{
printf("%c%c%c",'\b','\0','\b');
j=j-2;
}
else
printf("*");
}
password[--j]='\0';
if(!
strcmp(username,"zhang")&&!
strcmp(password,"123"))
{
printf("\n登录成功!
");
return1;
}
else
{printf("\n登录失败,请重新输入!
\n");
return0;}
}
/*学生登陆函数*/
intLogon1()
{
charusername[M],password[M];
printf("\n请输入用户名:
");
scanf("%s",username);
printf("\n请输入密码(最多15位):
");
intj=0;
while((j>=0)&&(password[j++]=getch())!
=13)//条件i>=0是用于限制退格的范围
{
if(password[j-1]=='\b')//对退格键的处理
{
printf("%c%c%c",'\b','\0','\b');
j=j-2;
}
else
printf("*");
}
password[--j]='\0';
if(!
strcmp(username,"zhang")&&!
strcmp(password,"123"))
{
printf("\n登录成功!
");
return1;
}
else
{printf("\n登录失败,请重新输入!
\n");
return0;}
}
/*输入学生信息函数*/
voidtype()
{inti=0;
intx=0;
printf("\t\t输出你想输入的学生信息个数:
");
scanf("%d",&n);
for(i=0;i{
printf("\n\t\t\t----------------\n");
printf("\t\t\t学号:
");
scanf("%s",&stu[i].num);/*输入学号*/
for(x=0;x
if(strcmp(stu[i].num,stu[x].num)==0)
{printf("\t\t此人已经存在,请输入不同的学号\n");
printf("\t\t\t学号:
");
scanf("%s",&stu[i].num);/*输入学号*/
}
printf("\t\t\t姓名:
");
scanf("%s",&stu[i].name);/*输入姓名*/
printf("\t\t\t性别:
");
scanf("%s",&stu[i].sex);/*输入性别*/
printf("\t\t\t班级:
");
scanf("%s",&stu[i].clas);//输入班级
printf("\t\t\t英语:
");
scanf("%d",&stu[i].english);/*输入英语成绩*/
printf("\t\t\t数电:
");
scanf("%d",&stu[i].shudian);/*输入数电成绩*/
printf("\t\t\t模电:
");
scanf("%d",&stu[i].modian);/*输入模电成绩*/
printf("\t\t\t体育:
");
scanf("%d",&stu[i].tiyu);//输入体育成绩
stu[i].sum=(float)stu[i].english+(float)stu[i].shudian+(float)stu[i].modian+(float)stu[i].tiyu;/*计算总成绩*/
stu[i].aver=stu[i].sum/4;/*计算平均成绩*/
printf("\t\t\t总成绩=%4.1f\n",stu[i].sum);/*输出总成绩*/
printf("\t\t\t平均成绩=%4.1f\n",stu[i].aver);/*输出平均成绩*/
}
}
/*退出函数*/
voidexit()
{exit(0);
}
/*查询函数*/
voidsearch()
{inti=0;
intmethod;//查询方式
charnum[20],name[20];//用来查询的关键字
while
(1)
{
printf("\t\t\t*请选择查询方式*\n\n\n");
printf("\t\t\t*****************\n");
printf("\t\t\t*1.按学号查询*\n");
printf("\t\t\t*2.按姓名查询*\n");
printf("\t\t\t*3.返回主菜单*\n");
printf("\t\t\t*****************\n");
scanf("%d",&method);
switch(method)
{
case1:
system("CLS");printf("\n请输入要查询的学号:
");
scanf("%s",num);
for(i=0;i{if(strcmp(stu[i].num,num)==0)
{
printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
printf("\t\t学号:
%s姓名:
%s性别:
%s班级:
%s\n\t\t英语:
%3d数电:
%3d模电:
%3d体育:
%3d平均分:
%4.2f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver);
printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
break;
}
}
if(i==n)
printf("暂无此人信息!
\n");
break;
case2:
system("CLS");printf("\n请输入要查询的姓名:
");
scanf("%s",name);
for(i=0;i{
if(strcmp(stu[i].name,name)==0)
{
printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
printf("\t\t学号:
%s姓名:
%s性别:
%s班级:
%s\n\t\t英语:
%3d数电:
%3d模电:
%3d体育:
%3d平均分:
%4.2f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver);
printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
break;
}
}
if(i==n)
printf("暂无此人信息!
\n");
break;
case3:
system("CLS");menu();break;
default:
printf("抱歉,暂无此查询方式!
\n");break;
}
}
}
voidsearch1()//查询学生信息
{inti=0;
intmethod;//查询方式
charnum[20],name[20];//用来查询的关键字
while
(1)
{
printf("\t\t\t*请选择查询方式*\n\n\n");
printf("\t\t\t*****************\n");
printf("\t\t\t*1.按学号查询*\n");
printf("\t\t\t*2.按姓名查询*\n");
printf("\t\t\t*3.返回主菜单*\n");
printf("\t\t\t*****************\n");
scanf("%d",&method);
switch(method)
{
case1:
system("CLS");printf("\n请输入要查询的学号:
");
scanf("%s",num);
for(i=0;i{if(strcmp(stu[i].num,num)==0)
{
printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
printf("\t\t学号:
%s姓名:
%s性别:
%s班级:
%s\n\t\t英语:
%3d数电:
%3d模电:
%3d体育:
%3d平均分:
%4.2f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver);
printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
break;}
}
if(i==n)
printf("暂无此人信息!
\n");
break;
case2:
system("CLS");printf("\n请输入要查询的姓名:
");
scanf("%s",name);
for(i=0;i{
if(strcmp(stu[i].name,name)==0)
{printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
printf("\t\t学号:
%s姓名:
%s性别:
%s班级:
%s\n\t\t英语:
%3d数电:
%3d模电:
%3d体育:
%3d平均分:
%4.2f\n",stu[i].num,stu[i].name,stu[i].sex,stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver);
printf("\t\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
break;
}
}
if(i==n)
printf("暂无此人信息!
\n");
break;
case3:
system("CLS");menu1();break;
default:
printf("抱歉,暂无此查询方式!
\n");break;
}
}
}
/*排序函数*/
voidorder()
{
inti,j;
intmethod;
structstudenttemp;
while
(1)
{
printf("\t\t\t\t*请选择排序方式*\n\n\n");
printf("\t\t\t\t*****************\n");
printf("\t\t\t\t*1.按英语排序*\n");
printf("\t\t\t\t*2.按数电排序*\n");
printf("\t\t\t\t*3.按模电排序*\n");
printf("\t\t\t\t*4.按体育排序*\n");
printf("\t\t\t\t*5.按均分排序*\n");
printf("\t\t\t\t*0.返回主菜单*\n");
printf("\t\t\t\t*****************\n");
scanf("%d",&method);
switch(method)
{
case1:
system("cls");
printf("\t\t\t\6\6*英语成绩排名*\6\6\n\n\n");
printf("学号姓名性别班级英语数电模电体育平均成绩总成绩\n");
for(i=0;i{
for(j=i+1;jif(stu[i].english{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
printf("%11s%7s%2s%4s%4d%4d%4d%4d%6.1f%7.1f\n",stu[i].num,stu[i].name,stu[i].sex,
stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver,stu[i].sum);
}break;
case2:
system("cls");
printf("\t\t\t\6\6*数电成绩排名*\6\6\n\n\n");
printf("学号姓名性别班级英语数电模电体育平均成绩总成绩\n");
for(i=0;i{
for(j=i+1;jif(stu[i].shudian{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
printf("%11s%7s%2s%4s%4d%4d%4d%4d%6.1f%7.1f\n",stu[i].num,stu[i].name,stu[i].sex,
stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver,stu[i].sum);
}break;
case3:
system("cls");
printf("\t\t\t\6\6*模电成绩排名*\6\6\n\n\n");
printf("学号姓名性别班级英语数电模电体育平均成绩总成绩\n");
for(i=0;i{
for(j=i+1;jif(stu[i].modian{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
printf("%11s%7s%2s%4s%4d%4d%4d%4d%6.1f%7.1f\n",stu[i].num,stu[i].name,stu[i].sex,
stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver,stu[i].sum);
}break;
case4:
system("cls");
printf("\t\t\t\6\6*体育成绩排名*\6\6\n\n\n");
printf("学号姓名性别班级英语数电模电体育平均成绩总成绩\n");
for(i=0;i{
for(j=i+1;jif(stu[i].tiyu{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
printf("%11s%7s%2s%4s%4d%4d%4d%4d%6.1f%7.1f\n",stu[i].num,stu[i].name,stu[i].sex,
stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver,stu[i].sum);
}break;
case5:
system("CLS");
printf("\t\t\t\6\6*平均成绩排名*\6\6\n\n\n");
printf("学号姓名性别班级英语数电模电体育平均成绩总成绩\n");
for(i=0;i{
for(j=i+1;jif(stu[i].aver{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
printf("%11s%7s%2s%4s%4d%4d%4d%4d%6.1f%7.1f\n",stu[i].num,stu[i].name,stu[i].sex,
stu[i].clas,stu[i].english,stu[i].shudian,stu[i].modian,stu[i].tiyu,stu[i].aver,stu[i].sum);
}break;
case0:
system("cls");
menu();break;
}
}
}
/*学生排序函数*/
voidorder1()
{
inti,j;
intmethod;
structstudenttemp;
while
(1)
{
printf("\t\t\t\t*请选择排序方式*\n\n\n");
printf("\t\t\t\t*****************\n");
printf("\t\t\t\t*1.按英语排序*\n");
printf("\t\t\t\t*2.按数电排序*\n");
printf("\t\t\t\t*3.按模电排序*\n");
printf("\t\t\t\t*4.按体育排序*\n");
printf("\t\t\t\t*5.按均分排序*\n");
printf("\t\t\t\t*0.返回主菜单*\n");
printf("\t\t\t\t*****************\n");
scanf("%d",&method);
switch(method)
{
case1:
system("cls");
printf("\t\t\t\6\6*英语成绩排名*\6\6\n\n\n");
printf("学号姓名性别班级英语数电模电体育平均成绩总成绩