#include
#include
#include
#include
#include
#include
#pragma comment(lib,"winmm,lib")
#define N 13//学生姓名的最大位数
#define STU struct student
#define M 30//暂时拟定的最大学生数
struct student
{
long studentID;
char studentName[N];
int score[5];
};
int Menu(void);
void InputData(STU *p,int n);
void Calculatecourse(STU *p,int n);
void Calculatestudent(STU *p,int n);
void Descendingtotal(STU *p,int n);
void Ascendingtotal(STU *p,int n);
void Sortnumber(STU *p,int n);
void Sortname(STU *p,int n);
void SearchstudentID(STU *p,int n);
void SearchstudentName(STU *p,int n);
void Analysiscourse(STU *p,int n);
void Listrecord(STU *p,int n);
void WritetoFile(STU *p,int n);
void ReadfromFile(STU *p,int n);
int main()
{
//PlaySound(TEXT("D:\\xuexi\\C Primer Plus\\shiyandazuoye\\2.wav"),NULL,SND_FILENAME | SND_ASYNC | SND_LOOP);
//下载wav文件后请将上述路径改为电脑中.wav所在路径
Sleep(0);
system("color F9");//更改控制台窗口的背景和字体颜色0 = 黑色 8 = 灰色
/*1 = 蓝色 9 = 淡蓝色
2 = 绿色 A = 淡绿色
3 = 湖蓝色 B = 淡浅绿色
4 = 红色 C = 淡红色
5 = 紫色 D = 淡紫色
6 = 黄色 E = 淡黄色
7 = 白色 F = 亮白色
0 = 黑色 */
int i;
char c;//功能1下判断Y/N
int count=0;//用来统计功能1下用户成功输入的学生人数
STU stu[M];
END:i = Menu();
switch (i)
{
case 0:
printf("Welcome back next time.\n");
return 0;
case 1:
printf("Do you want to input a record?(Y/N)\n");
scanf(" %c",&c);
while(c=='Y'||c=='y')
{
InputData(stu,count);
count++;
printf("Do you want to input another record?(Y/N)\n");
scanf(" %c",&c);
}
printf("%d new records have been added.",count);
system("pause");
system("cls");
goto END;
case 2:
Calculatecourse(stu,count);
system("pause");
system("cls");
goto END;
case 3:
Calculatestudent(stu,count);
system("pause");
system("cls");
goto END;
case 4:
Descendingtotal(stu,count);
system("pause");
system("cls");
goto END;
case 5:
Ascendingtotal(stu,count);
system("pause");
system("cls");
goto END;
case 6:
Sortnumber(stu,count);
system("pause");
system("cls");
goto END;
case 7:
Sortname(stu,count);
system("pause");
system("cls");
goto END;
case 8:
SearchstudentID(stu,count);
system("pause");
system("cls");
goto END;
case 9:
SearchstudentName(stu,count);
system("pause");
system("cls");
goto END;
case 10:
Analysiscourse(stu,count);
system("pause");
system("cls");
goto END;
case 11:
Listrecord(stu,count);
system("pause");
system("cls");
goto END;
case 12:
WritetoFile(stu,count);
printf("The operation is over.\n");
system("pause");
system("cls");
goto END;
case 13:
ReadfromFile(stu,count);
printf("The operation is over.\n");
system("pause");
system("cls");
goto END;
}
}
int Menu(void)
{
int i;
printf(" **************************************************************\n");
printf(" * Welcome to the Student Achievement Managment System\n");
printf(" * Please select one of the following features\n");
printf(" * 1.Input record\n");
printf(" * 2.Calculate total and average score of every course\n");
printf(" * 3.Calculate total and average score of every student\n");
printf(" * 4.Sort in descending order by total score of every student\n");
printf(" * 5.Sort in ascending order by total score of every student\n");
printf(" * 6.Sort in ascending order by number\n");
printf(" * 7.Sort in dictionary order by name\n");
printf(" * 8.Search by number\n");
printf(" * 9.Search by name\n");
printf(" * 10.Statistic analysis for every course\n");
printf(" * 11.List record\n");
printf(" * 12.Write to a file\n");
printf(" * 13.Read from a file\n");
printf(" * 0.Exit\n");
printf(" * Please enter your choice:\n");
printf(" **************************************************************\n");
scanf("%d", &i);
return i;
}
void InputData(STU *p ,int n)
{
int j;//用来输入各科成绩
printf("Please enter in the following order:studentID,studentName(not more than 13),\n");
printf("score(Maths,English,Chinese,Physics,Chemistry\n");
scanf("%ld",&p[n].studentID);
scanf("%s",p[n].studentName);
for(j=0;j<5;j++)
{
scanf("%d",&p[n].score[j]);
}
}
void Calculatecourse(STU *p,int n)
{
int j;//给学科排序
int i;//用来确定某个学生
int sum[5];//计算每一个科目的总分
float aver[5];//计算每一个科目的平均分
char sub[5][10]={"Maths","English","Chinese","Physics","Chemistry"};
for(j=0;j<5;j++)
{
sum[j] = 0;
for(i=0;isum[j+1])
{
temp1 = sum[j+1];
sum[j+1] = sum[j];
sum[j] = temp1;
temp2 = p[j+1];
p[j+1] = p[j];
p[j] = temp2;
}
}
}
printf("Students are sorted in ascending order by grade as follows:\n");
putchar('\n');
for(i=0;ip[j+1].studentID)
{
temp = p[j+1];
p[j+1] = p[j];
p[j]= temp;
}
}
}//将结构体数组按学号从小到大重新赋予顺序*/
printf("Students are sorted in ascending order by studentID as follows:\n");
putchar('\n');
for(i=0;i0)
{
temp = p[j+1];
p[j+1] = p[j];
p[j]= temp;
}
}
}//冒泡排序
printf("Students are sorted in ascending order by studentName as follows:\n");
putchar('\n');
for(i=0;i=0&&p[i].score[j]<=59)
{
analysis[j][0]++;
}
else if(p[i].score[j]<69)
{
analysis[j][1]++;
}
else if(p[i].score[j]<79)
{
analysis[j][2]++;
}
else if(p[i].score[j]<89)
{
analysis[j][3]++;
}
else
{
analysis[j][4]++;
}
}
}
for(j=0;j<5;j++)
{
for(i=0;i<5;i++)
{
percentage[j][i] = 100*(float)analysis[j][i]/n;
}
}
for(j=0;j<5;j++)
{
printf("The analysis of %s are as follows:\n",sub[j]);
putchar('\n');
putchar('\n');
printf("不及格人数为: %-4d 所占比例为:%.2f%%\n",analysis[j][0],percentage[j][0]);
putchar('\n');
printf("及格人数为: %-4d 所占比例为:%.2f%%\n",analysis[j][1],percentage[j][1]);
putchar('\n');
printf("中等人数为: %-4d 所占比例为:%.2f%%\n",analysis[j][2],percentage[j][2]);
putchar('\n');
printf("良好人数为: %-4d 所占比例为:%.2f%%\n",analysis[j][3],percentage[j][3]);
putchar('\n');
printf("优秀人数为: %-4d 所占比例为:%.2f%%\n",analysis[j][4],percentage[j][4]);
putchar('\n');
putchar('\n');
}
}
void Listrecord(STU *p,int n)
{
int i;
int j;
int sum[5];//计算每一个科目的总分
float aver[5];//计算每一个科目的平均分
char sub[5][10]={"Maths","English","Chinese","Physics","Chemistry"};
for(i=0;i