あるクラスは最大30人(具体的な人数はキーボードから入力)を超えないである課程の試験を受けて、第11週のオンライン試験の中で“学生成績管理システムV 2.0”を参考にして、2次元文字配列を関数パラメータとしてプログラミングして以下のメニュー駆動の学生成績管理システムを実現します:
19257 ワード
30 ( ) , 11 “ V2.0”, :
(1) 、 ;
(2) ;
(3) ;
(4) ;
(5) ;
(6) ;
(7) ;
(8) ;
(9) (90~100)、 (80~89)、 (70~79)、 (60~69)、 (0~59)5 , ;
(10) 、 、 。
, :
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please enter your choice:
, 。
#define MAX_LEN 10 /* */
#define STU_NUM 30 /* */
int Menu(void);
void ReadScore(long num[], char name[][MAX_LEN], float score[], int n);
void AverSumofScore(float score[], int n);
void SortbyScore(long num[], char name[][MAX_LEN], float score[], int n,
int (*compare)(float a, float b));
int Ascending(float a, float b);
int Descending(float a, float b);
void SwapFloat(float *x, float *y);
void SwapLong(long *x, long *y);
void SwapChar(char x[], char y[]);
void AsSortbyNum(long num[], char name[][MAX_LEN], float score[], int n);
void SortbyName(long num[], char name[][MAX_LEN], float score[], int n);
void SearchbyNum(long num[], char name[][MAX_LEN], float score[], int n);
void SearchbyName(long num[], char name[][MAX_LEN], float score[], int n);
void StatisticAnalysis(float score[], int n);
void PrintScore(long num[], char name[][MAX_LEN], float score[], int n) ;
:
Input student number(n<30):
6↙
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
1↙
Input student's ID, name and score:
11003001↙
lisi↙
87↙
11003005↙
heli↙
98↙
11003003↙
ludi↙
75↙
11003002↙
dumo↙
48↙
11003004↙
zuma↙
65↙
11003006↙
suyu↙
100↙
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
2↙
sum=473,aver=78.83
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
3↙
Sort in descending order by score:
11003006 suyu 100
11003005 heli 98
11003001 lisi 87
11003003 ludi 75
11003004 zuma 65
11003002 dumo 48
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
4↙
Sort in ascending order by score:
11003002 dumo 48
11003004 zuma 65
11003003 ludi 75
11003001 lisi 87
11003005 heli 98
11003006 suyu 100
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
5↙
Sort in ascending order by number:
11003001 lisi 87
11003002 dumo 48
11003003 ludi 75
11003004 zuma 65
11003005 heli 98
11003006 suyu 100
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
6↙
Sort in dictionary order by name:
11003002 dumo 48
11003005 heli 98
11003001 lisi 87
11003003 ludi 75
11003006 suyu 100
11003004 zuma 65
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
7↙
Input the number you want to search:
11003004↙
11003004 zuma 65
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
8↙
Input the name you want to search:
heli↙
11003005 heli 98
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
9↙
<60 1 16.67%
60-69 1 16.67%
70-79 1 16.67%
80-89 1 16.67%
90-99 1 16.67%
100 1 16.67%
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
10↙
11003002 dumo 48
11003005 heli 98
11003001 lisi 87
11003003 ludi 75
11003006 suyu 100
11003004 zuma 65
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
11↙
Input error!
Management for Students' scores
1.Input record
2.Caculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by score
5.Sort in ascending order by number
6.Sort in dictionary order by name
7.Search by number
8.Search by name
9.Statistic analysis
10.List record
0.Exit
Please Input your choice:
0↙
End of program!
:
( 1 ) :
** :"%d"
** :"Input student number(n<30):
"
( 2 ) 、 :
** :"%ld%s%f"
** :"Input student's ID, name and score:
"
:
:
** :"sum=%.0f,aver=%.2f
"
:
** :"%ld\t%s\t%.0f
"
** :"Sort in descending order by score:
"
:
** :"%ld\t%s\t%.0f
"
** :"Sort in ascending order by score:
"
:
** :"%ld\t%s\t%.0f
"
** :"Sort in ascending order by number:
"
** :"%ld\t%s\t%.0f
"
** :"Sort in dictionary order by name:
"
:
** , :"Not found!
";
** , :"%ld\t%s\t%.0f
"
;
** , :"Not found!
";
** , :"%ld\t%s\t%.0f
"
(90~100)、 (80~89)、 (70~79)、 (60~69)、 (0~59)5 , :
** <60 :"<60\t%d\t%.2f%%
";
** =100 :"%d\t%d\t%.2f%%
";
** :"%d-%d\t%d\t%.2f%%
"
、 、 ,
** :"%ld\t%s\t%.0f
"
( 0)
** :"End of program!"
( 0-10 )
** :"Input error!
"
#include
#include
#include
#define MAX_LEN 10 /* */
#define STU_NUM 30 /* */
int Menu(void);
void ReadScore(long num[], char name[][MAX_LEN], float score[], int n);
void AverSumofScore(float score[], int n);
void SortbyScore(long num[], char name[][MAX_LEN], float score[], int n,
int (*compare)(float a, float b));
int Ascending(float a, float b);
int Descending(float a, float b);
void SwapFloat(float *x, float *y);
void SwapLong(long *x, long *y);
void SwapChar(char x[], char y[]);
void AsSortbyNum(long num[], char name[][MAX_LEN], float score[], int n);
void SortbyName(long num[], char name[][MAX_LEN], float score[], int n);
void SearchbyNum(long num[], char name[][MAX_LEN], float score[], int n);
void SearchbyName(long num[], char name[][MAX_LEN], float score[], int n);
void StatisticAnalysis(float score[], int n);
void PrintScore(long num[], char name[][MAX_LEN], float score[], int n) ;
int main()
{
char ch;
int n = 0;
float score[STU_NUM];
long num[STU_NUM];
char name[STU_NUM][MAX_LEN];
printf("Input student number(n<30):
");
scanf("%d", &n);
while (1)
{
ch = Menu(); /* , */
switch (ch)
{
case 1:
ReadScore(num, name, score, n);
break;
case 2:
AverSumofScore(score, n);
break;
case 3:
SortbyScore(num, name, score, n, Descending);
printf("Sort in descending order by score:
");
PrintScore(num, name, score, n);
break;
case 4:
SortbyScore(num, name, score, n, Ascending);
printf("Sort in ascending order by score:
");
PrintScore(num, name, score, n);
break;
case 5:
AsSortbyNum(num, name, score, n);
printf("Sort in ascending order by number:
");
PrintScore(num, name, score, n);
break;
case 6:
SortbyName(num, name, score, n);
printf("Sort in dictionary order by name:
");
PrintScore(num, name, score, n);
break;
case 7:
SearchbyNum(num, name, score, n);
break;
case 8:
SearchbyName(num, name, score, n);
break;
case 9:
StatisticAnalysis(score, n);
break;
case 10:
PrintScore(num, name, score, n);
break;
case 0:
printf("End of program!");
exit(0);
default:
printf("Input error!
");
}
}
return 0;
}
/* : */
int Menu(void)
{
int itemSelected;
printf("Management for Students' scores
");
printf("1.Input record
");
printf("2.Caculate total and average score of course
");
printf("3.Sort in descending order by score
");
printf("4.Sort in ascending order by score
");
printf("5.Sort in ascending order by number
");
printf("6.Sort in dictionary order by name
");
printf("7.Search by number
");
printf("8.Search by name
");
printf("9.Statistic analysis
");
printf("10.List record
");
printf("0.Exit
");
printf("Please Input your choice:
");
scanf("%d", &itemSelected); /* */
return itemSelected;
}
/* : n */
void ReadScore(long num[], char name[][MAX_LEN], float score[], int n)
{
int i;
printf("Input student's ID, name and score:
");
for (i = 0; i < n; i++)
{
scanf("%ld%s%f", &num[i], name[i], &score[i]);
}
}
/* : */
void AverSumofScore(float score[], int n)
{
int i;
float sum = 0;
for (i = 0; i < n; i++)
{
sum = sum + score[i];
}
printf("sum=%.0f,aver=%.2f
", sum, n > 0 ? sum / n : 0);
}
/* : score */
void SortbyScore(long num[], char name[][MAX_LEN], float score[], int n,
int (*compare)(float a, float b))
{
int i, j, k;
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if ((*compare)(score[j], score[k])) k = j;
}
if (k != i)
{
SwapFloat(&score[k], &score[i]); /* */
SwapLong(&num[k], &num[i]); /* */
SwapChar(name[k], name[i]); /* */
}
}
}
/* */
int Ascending(float a, float b)
{
return a < b; /* , a b; /* , a>b, */
}
/* */
void SwapFloat(float *x, float *y)
{
float temp;
temp = *x;
*x = *y;
*y = temp;
}
/* */
void SwapLong(long *x, long *y)
{
long temp;
temp = *x;
*x = *y;
*y = temp;
}
/* */
void SwapChar(char x[], char y[])
{
char temp[MAX_LEN];
strcpy(temp, x);
strcpy(x, y);
strcpy(y, temp);
}
/* : num */
void AsSortbyNum(long num[], char name[][MAX_LEN], float score[], int n)
{
int i, j, k;
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
{
if (num[j] < num[k]) k = j;
}
if (k != i)
{
SwapFloat(&score[k], &score[i]); /* */
SwapLong(&num[k], &num[i]); /* */
SwapChar(name[k], name[i]); /* */
}
}
}
/* : */
void SortbyName(long num[], char name[][MAX_LEN], float score[], int n)
{
int i, j;
for (i = 0; i < n - 1; i++)
{
for (j = i + 1; j < n; j++)
{
if (strcmp(name[j], name[i]) < 0)
{
SwapFloat(&score[i], &score[j]); /* */
SwapLong(&num[i], &num[j]); /* */
SwapChar(name[i], name[j]); /* */
}
}
}
}
/* : */
void SearchbyNum(long num[], char name[][MAX_LEN], float score[], int n)
{
long number;
int i;
printf("Input the number you want to search:
");
scanf("%ld", &number);
for (i = 0; i < n; i++)
{
if (num[i] == number)
{
printf("%ld\t%s\t%.0f
", num[i], name[i], score[i]);
return;
}
}
printf("Not found!
");
}
/* : */
void SearchbyName(long num[], char name[][MAX_LEN], float score[], int n)
{
char x[MAX_LEN];
int i;
printf("Input the name you want to search:
");
scanf("%s", x);
for (i = 0; i < n; i++)
{
if (strcmp(name[i], x) == 0)
{
printf("%ld\t%s\t%.0f
", num[i], name[i], score[i]);
return;
}
}
printf("Not found!
");
}
/* : */
void StatisticAnalysis(float score[], int n)
{
int i, total, t[6] = {0, 0, 0, 0, 0, 0};
for (i = 0; i < n; i++)
{
if (score[i] >= 0 && score[i] < 60)t[0]++;
else if (score[i] < 70) t[1]++;
else if (score[i] < 80) t[2]++;
else if (score[i] < 90) t[3]++;
else if (score[i] < 100) t[4]++;
else if (score[i] == 100) t[5]++;
}
for (total = 0, i = 0; i <= 5; i++)
{
total = total + t[i];
}
for (i = 0; i <= 5; i++)
{
if (i == 0) printf("<60\t%d\t%.2f%%
", t[i], (float)t[i] / n * 100);
else if (i == 5) printf("%d\t%d\t%.2f%%
",
(i + 5) * 10, t[i], (float)t[i] / n * 100);
else printf("%d-%d\t%d\t%.2f%%
",
(i + 5) * 10, (i + 5) * 10 + 9, t[i], (float)t[i] / n * 100);
}
}
/* : */
void PrintScore(long num[], char name[][MAX_LEN], float score[], int n)
{
int i;
for (i = 0; i < n; i++)
{
printf("%ld\t%s\t%.0f
", num[i], name[i], score[i]);
}
}