📄 复件 wu项.c
字号:
case '2':if(page<totpage)
page++;
break;
case '3':page=1;break;
case '4': page=totpage;break;
case '5': {
wenttoxy(30,19);
printf("please enter a chararcat:");
while(1)
{ page=getche();
page=page-48;
if(!(1<=page && page <=totpage))
{
wenttoxy(30,19);
printf("The figure that you import is illegal!");
}
else
break;
}
break;
}
}
if( select=='6')
{
printf("dou you want to delete the record");
a=getche();
if(a=='Y'||a=='y') del(s);
else Main_Menu();
}
}
}
/********************************************************************************************
按学号排序
k等于1表示降序排列
************************************************************************************************/
void OrderBySno(int k)
{
int i;char c;
struct student temp;
int flag;
if(k==1)
{
do
{
flag=1;
for(i=0;i<=counts-1;i++)
if(strcmp(stu[i+1].sno,stu[i].sno)>0)
{
temp=stu[i];stu[i]=stu[i+1];stu[i+1]=temp;
flag=0;
}
}while(! flag);
system("cls");
printf("sort is successd,will you want to sort of information?[y/Y]");
while(1)
{
c=getche();
if(c=='y'||c=='Y')
{
PrintInfo( stu, counts, page,0,-1);
break;
}
else
Sort_Stu_Info();
}
}
else
{
if(k==-1)
do
{
flag=1;
for(i=0;i<=counts-1;i++)
if(strcmp(stu[i+1].sno,stu[i].sno)<0)
{
temp=stu[i];stu[i]=stu[i+1];stu[i+1]=temp;
flag=0;
}
}
while(!flag);
}
system("cls");
wenttoxy(5,3);
printf("sort is successd,will you want to printf the sort of information?[y\Y]");
while(1)
{
c=getche();
if(c=='y'||c=='Y')
{
PrintInfo( stu, counts, page,0,-1);
break;
}
else
Sort_Stu_Info();
}
}
/***********************************************************************************************
按总分排序
************************************************************************************************/
void OrderByTotscore(int k)
{
struct student temp;char c;
double totscore[50]={0};
int i,j,min;
for(i=0;i<=counts-1;i++)
{
stu[i].totscore=stu[i].score[0]+stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+stu[i].score[4];
}
if(k==1)
{
for(i=0;i<counts;i++)
{ min=i;
for(j=i+1;j<counts;j++)
{ if(stu[min].totscore>stu[j].totscore)
{ min=j;
}
}
if(min!=i)
{ temp=stu[min];
stu[min]=stu[i];
stu[i]=temp;
}
}
printf("sort is successd,will you want to printf the sort of information?[y\Y]");
while(1)
{
c=getche();
if(c=='y'||c=='Y')
{
system("cls");
PrintInfo( stu, counts, page,0,-1);
break;
}
else
Sort_Stu_Info();
}
}
else
{
if(k==-1)
{
for(i = 0;i <counts-1;i++)
for(j = i+1;j <=counts-1;j++)
{ if(stu[i].totscore <stu[j].totscore)
{ temp = stu[j];
stu[j] = stu[i];
stu[i] = temp;
}
}
}
printf("sort is successd,will you want to printf the sort of information?[y\Y]");
while(1)
{
c=getche();
if(c=='y'||c=='Y')
{
system("cls");
PrintInfo( stu, counts, page,0,-1);
break;
}
else
Sort_Stu_Info();
}
}
}
/*********************************************************************************************
统计平均分
*********************************************************************************************/
void tongjiavg()
{
int i;double avg,tot;tot=0;
if(counts!=0)
{
for(i=0;i<=counts-1;i++)
{
tot+=stu[i].score[0];
}
avg=tot/5.0;
wenttoxy(20,3);
printf("Chinese:%.1f",avg);
tot=0;
for(i=0;i<=counts-1;i++)
{
tot+=stu[i].score[1];
}
avg=tot/5.0;
wenttoxy(20,4);
printf("English:%.1f",avg);
tot=0;
for(i=0;i<=counts-1;i++)
{
tot+=stu[i].score[2];
}
avg=tot/5.0;
wenttoxy(20,5);
printf("Physics:%.1f",avg);
tot=0;
for(i=0;i<=counts-1;i++)
{
tot+=stu[i].score[3];
}
avg=tot/5.0;wenttoxy(20,6);
printf("Chemistry:%.1f",avg);
tot=0;
for(i=0;i<=counts-1;i++)
{
tot+=stu[i].score[4];
}
avg=tot/5.0;wenttoxy(20,7);
printf("Math:%.1f",avg);
}
else
{
wenttoxy(5,21);
printf("counts is empty");
}
}
/*******************************k表示第k门课程********************************************/
void count(int k)
{ struct student temp;
int i,j;int m=0;
if(counts!=0)
{
for(i=0;i<=counts-2;i++)
for(j=i+1;j<=counts-1;j++)
if(stu[i].score[k]<stu[j].score[k])
{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
if(0<counts && counts<=3)
PrintInfo( stu, counts,1,0);
else
{
for(i=3;i<=counts-1;i++)
{
if(stu[2].score[k]==stu[i].score[k])
m++;
}
m=m+3;
PrintInfo( stu, m, 1, 0,1);
}
}
else
{
wenttoxy(5,21);
printf("the record is empty,any key to Main_Menu");
getch();
Main_Menu();
}
}
/**********************************************************************************************/
/**********************************总分前三甲**************************************************/
/**********************************************************************************************/
void Allscore()
{
struct student temp;
int i,j,k;
k=0;
if(counts!=0)
{
for(j=0;j<=counts-1;j++)
{
stu[j].totscore=(stu[j].score[0]+stu[j].score[1]+stu[j].score[2]+stu[j].score[3]+stu[j].score[4]);
}
for(i=0;i<=counts-2;i++)
for(j=i+1;j<=counts-1;j++)
{
if(stu[i].totscore<stu[j].totscore)
{
temp=stu[i];
stu[i]=stu[j];
stu[j]=temp;
}
}
if(0<counts && counts<=3)
PrintInfo(stu,counts,1,0,1);
else
{
for(i=3;i<=counts-1;i++)
if(stu[2].totscore==stu[i].totscore)
k++;
}
k=k+3;
PrintInfo( stu, k, 1, 0,1);
}
else
{
wenttoxy(5,21);
printf("counts is empty,anykey to Main_Menu()");
}
}
/*********************************************************************************************/
/*************************** 统计学生单科和总分前三甲和平均分***********************************/
/*********************************************************************************************/
void Static()
{ char c;
system("cls");
wenttoxy(28,0);printf("****************************\n");
wenttoxy(28,1);printf("* Static Stu Data *\n");
wenttoxy(28,2);printf("****************************\n");
wenttoxy(28,3);
tongjiavg();
wenttoxy(28,7);printf("anykey to continue");getch();
system("cls");
wenttoxy(28,5);printf("1. top three of chinese ");
wenttoxy(28,6);printf("2. top three of english ");
wenttoxy(28,7);printf("3. top three of physic ");
wenttoxy(28,8);printf("4. top three of chemistry ");
wenttoxy(28,9);printf("5. top three of math ");
wenttoxy(28,10);printf("6.top three of allscore");
while(1)
{ c=getche();
if(!('0'<=c && c<='6'))
{
wenttoxy(5,18);printf("your puts is wrong");
}
else
break;
}
switch(c)
{
case '1':system("cls");count(0);break;
case '2':system("cls");count(1);break;
case '3':system("cls");count(2);break;
case '4':system("cls");count(3);break;
case '5':system("cls");count(4);break;
case '6':system("cls");Allscore();break;
case '0':Main_Menu();break;
}
}
/*********************************************************************************************
删除学生记录函数 s为学生的学号
**********************************************************************************************/
void del(char s[4])
{ int i,j;
for(i=0;i<=counts-1;i++)
if(strcmp(stu[i].sno,s)==0 )
{
j=i+1;
memcpy(&stu[i],&stu[j],sizeof(struct student));
for(j=i+1;j<=counts-1;j++)
{
memcpy(&stu[j],&stu[j+1],sizeof(struct student));
}
printf("delete is secceed!!");
counts--;
}
}
void FilenameVerifies(char filename[18])
{
do
{
wenttoxy(36,5);
gotstring(filename,18);
name_kongge(filename);
}while(1);
}
/*读取信息*/
int load_message()
{
char filename[18];
int i,j,k;
FILE *fp;
i=0;
k=0;
//filename
if((fp=fopen("wu.txt","rb+"))==NULL)
{
wenttoxy(5,21);
printf("Cann't open the file..press any key exit!");
getch();
exit(1);
}
for(i=0;;i++)//逐个读取学生信息
{
if(fread(&stu[i],sizeof(struct student),1,fp)!=1)
{
break;
}
}
counts=i;
fclose(fp);//关闭文件
if(counts)
{
wenttoxy(5,21);
printf("load seccess,any key to main_menu!\n");
getch();
Main_Menu();
}
}
/*保存信息*/
int save(int counts,int k)
{
FILE *fp;
int i;
wenttoxy(35,5);
if((fp=fopen("wu.txt","wt"))==NULL)
{
printf("Read the document mistake!\n");
getch();
exit(1);
}
for(i=0;i<counts;i++)
{
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
{
fsave=0;
wenttoxy(5,21);
printf("Write the document mistake!\n");
break;
}
else
{
fsave=1;
}
}
if(fsave)
{
wenttoxy(5,21);
printf("You are secceed,any key to Main_Memu!");
}
rewind(fp);
fclose(fp);
if(k==0)
{
getch();
Main_Menu();
}
return i;
}
/**********************************************************************************************
保存学生纪录的菜单
*********************************************************************************************/
void Save_Stu_Data()
{
system("cls");
wenttoxy(28,0);printf("****************************\n");
wenttoxy(28,1);printf("* SAVE *\n");
wenttoxy(28,2);printf("****************************\n");
wenttoxy(28,5);printf("PATH:");
wenttoxy(29,5);printf("like this:stu.txt");
wenttoxy(35,5);
}
void Load_Stu_Data()
{
system("cls");
wenttoxy(28,0);printf("****************************\n");
wenttoxy(28,1);printf("* LOAD *\n");
wenttoxy(28,2);printf("****************************\n");
wenttoxy(28,5);printf("PATH:");
wenttoxy(28,6);printf("like this:stu.txt");
}
/********************************************************************************************/
/************************************主菜单界面**********************************************/
/********************************************************************************************/
void Main_Menu()
{ char a;
system("cls");
nowtime();
wenttoxy(28,0);printf("****************************\n");
wenttoxy(28,1);printf("* Main Menu *\n");
wenttoxy(28,2);printf("****************************\n");
wenttoxy(28,3);printf("1.Add Stu Info\n");
wenttoxy(28,4);printf("2.Sort Stu Info\n");
wenttoxy(28,5);printf("3.Print Stu Info\n");
wenttoxy(28,6);printf("4.Save Stu Data\n");
wenttoxy(28,7);printf("5.Load Stu Data\n");
wenttoxy(28,8);printf("6.Search Stu Info\n");
wenttoxy(28,9);printf("7.Static Stu Data\n");
wenttoxy(28,10);printf("0.Exit System\n");
wenttoxy(5,18);printf("please enter a number[0-7]:");
wenttoxy(0,24);printf("---Author:WuQianLiang---");
while(1)
{
a=getche();
if(a<'0' || a>'7')
{
wenttoxy(5,19);
printf("your puts is wrong ,please try again");
getch();
}
switch(a)
{
case '0':Exit_System(); getch();out();
case '1':add() ; getch(); break;
case '2':Sort_Stu_Info(); getch() ;break;
case '3':print();PrintInfo( stu, counts, 1,0,1);getch();
case '4':Save_Stu_Data();save(counts,0);break;
case '5':Load_Stu_Data();load_message();break;
case '6':Search_Stu_Info();getch(); break;
case '7':Static();break;
}
}
}
main()
{
system("color 2e");
//Enter();
Main_Menu();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -