📄 zong wu项.c
字号:
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 math ");
wenttoxy(28,8);printf("4. top three of chemistry ");
wenttoxy(28,9);printf("5. top three of physic ");
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--;
getch( );
wenttoxy(5,21);printf("anykey to see the result");
PrintInfo( stu, counts, page,0,-1);
}
}
/*读取信息*/
int load_message()
{
int i,j,k; char filename[18];
FILE *fp;
i=0;
k=0;
do
{
k=0;
wenttoxy(36,5);
printf(" ");
wenttoxy(36,5);
gotstring(filename,18);
name_kongge(filename);
j=strlen(filename);
for(i=j-1;filename[i]!='\\' && i>0;i--)
{
if(filename[i]=='|'||filename[i]=='/'||filename[i]==':'||filename[i]=='?')
k=1;
}
if(!isalpha(filename[0]) || filename[1]!=':' || filename[2]!='\\')
{
wenttoxy(5,21);
printf(" ");
wenttoxy(5,21);
printf("The magic figure is incorrect!");
}
else if(k)
{
wenttoxy(5,21);
printf(" ");
wenttoxy(5,21);
printf("the name of file is wrong");
}
else if(j-i>8)
{
wenttoxy(5,21);
printf(" ");
wenttoxy(5,21);
printf("the name of file over the lenth of 8");
}
else
break;
}while(1);
if((fp=fopen(filename,"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();
}
else
{
wenttoxy(5,21);
printf("the file is empty,any key contiue");
getch();
}
}
/*保存信息*/
int save(int counts,int k)
{
char filename[18];
FILE *fp;
int i,j,m;
do
{
m=0;
wenttoxy(36,5);
printf(" ");
wenttoxy(36,5);
gotstring(filename,18);
name_kongge(filename);
j=strlen(filename);
for(i=j-1;filename[i]!='\\' && i>0;i--)
{
if(filename[i]=='|'||filename[i]=='/'||filename[i]==':'||filename[i]=='?')
k=1;
}
if(!isalpha(filename[0]) || filename[1]!=':' || filename[2]!='\\')
{
wenttoxy(5,21);
printf(" ");
wenttoxy(5,21);
printf("The magic figure is incorrect!");
}
else if(m)
{
wenttoxy(5,21);
printf(" ");
wenttoxy(5,21);
printf("the name of file is wrong");
}
else if(j-i>8)
{
wenttoxy(5,21);
printf(" ");
wenttoxy(5,21);
printf("the name of file over the lenth of 8");
}
else
break;
}while(1);
if((fp=fopen(filename,"w+"))==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,6);printf("like this:d:\\dsfdf\wu.txt");
}
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:d:\\dsfdf\wu.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 + -