Professional Documents
Culture Documents
#include <stdio.h>
long BG[SIZE][2]={0};
int students=0;
//定义数组 BG 为全局变量形数组以便于所有函数都可以操作该数组
//定义 students 统计实际学生人数
/////////////////////////////////////////////////////////////
void INPUT (BG[][2]);
void AVERAGE (BG[][2]);
void SORT (BG[][2]);
void NUMBER_SORT (BG[][2]);
void SEARCH (BG[][2]);
void STATISTICS (BG[][2]);
void OUTPUT (BG[][2]);
///////////////////////////////
int main()
{
char choice;
START:
printf("1.Input record\n");
printf("2.Caculate total and average score of course\n");
printf("3.Sort in descending order by score\n");
printf("4.Sort in ascending order by number\n");
printf("5.Search by number\n");
printf("7.List record\n");
printf("0.Exit\n");
//向用户展示系统界面
do{
printf("Please enter your choice: ");
scanf("%c",&choice);
}while(choice>=48 && choice <=57);
//处理非法输入
switch(choice){
case '1':goto function_1;
case '2':goto function_2;
case '3':goto function_3;
case '4':goto function_4;
case '5':goto function_5;
case '6':goto function_6;
case '7':goto function_7;
case '0':return 0;
default:return 0;}
//使用结构清晰的 goto 语句以跳转至不同功能
function_1:
INPUT(BG[SIZE][2]);
printf("\n");
goto START;/*录入每个学生的学号和分数*/
function_2:
AVERAGE(BG[SIZE][2]);
printf("\n");
goto START;/*求总分和平均分*/
function_3:
SORT(BG[SIZE][2]);
printf("\n");
goto START;
function_4:
NUMBER_SORT([SIZE][2]);
printf("\n");
goto START;
function_5:
SEARCH(BG[SIZE][2]);
printf("\n");
goto START;
function_6:
STATISTICS(BG[SIZE][2]);
printf("\n");
goto START;
function_7:
OUTPUT(BG[SIZE][2]);
printf("\n");
goto START;
function_0:
return 0;
}
///////////////////////////////////////////////////////////
void INPUT (BG[][2])
{
int c,r;//计数用变量
long number,score;//学号和分数变量;
printf("Function_1:Input score\n");
printf("Please input number and score,and input '0,0' to exit this
function.\n");
printf("The BG is 'number with 6 bytes,score with 2~3 bytes' .\n");
for(c=0;c<SIZE;c++)
{
scanf("&ld,&ld",&number,%score);
if(number==0 && score==0) break;//处理退出请求
BG[c][0]=number;
BG[c][1]=score;
}
}
///////////////////////////////////////////////////////////
void AVERAGE (BG[][2])
{
int c,r;//计数用变量
int sum=0;
int students=0;
int average=0;
for(c=0;c<SIZE;c++)
{
if(BG[c][0] != 0)
students++;
if(BG[c][0] == 0)
break;
}//计算实际学生总数
for(c=0;c<SIZE;c++)
{
sum=sum+BG[c][1];
}//计算所有学生总分
average=sum/students;
numbertemp=BG[c][0];
BG[c][0]=BG[c+1][0];
BG[c+1][0]=numbertemp;
}
}
}
}
}
}
///////////////////////////////////////////////////////////
void NUMBER_SORT (BG[][2])
{
{
int c,r;//计数变量
int temp;
int numbertemp;
int times;
char choice;
numbertemp=BG[c][1];
BG[c][1]=BG[c+1][1];
BG[c+1][1]=numbertemp;
}
}
}
numbertemp=BG[c][1];
BG[c][1]=BG[c+1][1];
BG[c+1][1]=numbertemp;
}
}
}
}
}
///////////////////////////////////////////////////////////
void SEARCH (BG[][2])
{
int c,r;
long number;
char flag;
first:
for(c=0;c<SIZE;c++)
{
if(BG[c][0] == number)
{
printf("The number is %ld ,and the scores are %ld
\n",BG[c][0],BG[c][0]);
break;
}
}
}
///////////////////////////////////////////////////////////
void STATISTICS (BG[][2])
{
int a=0,b=0,c=0,d=0,f=0;
int c,r;
for(c=0;c<SIZE;c++)
{
if(BG[c][1]<=100 && BG[c][1]>=90)
a++;
else if(BG[c][1]>=80 && BG[c][1]<=89)
b++;
else if(BG[c][1]>=79 && BG[c][1]<=79)
c++;
else if(BG[c][1]>=60 && BG[c][1]<=69)
d++;
else if(BG[c][1]<=59)
f++;
}
printf("优秀的人数是:%d\n",a);
printf("良好的人数是:%d\n",b);
printf("中等的人数是:%d\n",c);
printf("及格的人数是:%d\n",d);
printf("不及格的人数是:%d\n",f);
}
/////////////////////////////////////////////////////////////////////////////
void OUTPUT (BG[][2])
{
int c,r;
for(c=0;c<SIZE;c++)
{
printf("%ld-----%ld",BG[c][0],BG[c][1]);
}
}
///////////////////////////////////////////////////////////////////////////////
/