A class of up to no more than 30 people (the specific number of keyboard input) to take a course examination. Using one-dimensional array as function parameter programming to achieve the following student achievement management system:
(1) entry of each student number and test results;
(2) Calculating the total score and average score of the course;
(3) According to the results from high to low discharge ranking table;
(4) According to the school number by the small large discharge table;
(5) According to the number of students to check the ranking and examination results;
The number and percentage of each category are counted according to the 5 categories of excellent (90~100), Good (80~89), Medium (70~79), passing (60~69) and failing (0~59).
1, source code
#include <stdio.h> #include <stdlib.h> #define STU_NUM 30/* Maximum number of students */int Menu (void);
/*menu () function is a prototype that displays the menu/void Readscore (Long num[],float score [],int N);
void Aversumofscore (float score[],int N);
void Desortbyscore (Long num[],float [],int N);
void Assortbynum (Long num[],float score[],int N);
void Searchbynum (Long num[],float score[],int N);
void Statisticanalysis (float score[],int N);
void Printscore (Long num[],float score[],int N); int main () {char itemselected; /* Character variable itemselected for menu option */int n=0; /*n for the actual number of students, by the user input * * float score[stu_num]; /* A set of array score, the length is stu_num, for storing student achievement * * long num[stu_num]; /* A set of array NUM, length stu_num, for storing student achievement * * while (1) {itemselected=menu (); /* Display menu, and read user input/switch (itemselected)/* According to the menu options to execute the appropriate program * * * * Enter the number of students, to the array num and score order Input n student number and a
The results of the course/Case 1:printf ("Input student Number (n<%d):", stu_num); ScANF ("%d", &n);
Readscore (Num,score,n);
Break
* * Calculate the whole class total score and the average score/Case 2:aversumofscore (score,n);
Break
/* Press the selection method to sort the elements of the array score from high to low/Case 3:desortbyscore (num,score,n);
printf ("\nsort in descending order by score:\n");
Printscore (Num,score,n);
Break
/* Press the selection method to sort the elements of the array num from large to small 4:assortbynum (num,score,n);
printf ("\nsort in ascending order by score:\n");
Printscore (Num,score,n);
Break
* * According to the school number to find students ' scores and display search results/Case 5:searchbynum (num,score,n);
Break
* * Statistics of the number and percentage of students in each score section/Case 6:statisticanalysis (score,n);
Break
/* Print student score/Case 7:printscore (num,score,n);
Break /* Exit program/Case 0:printf ("Exit program.")
\ n "); Exit (0); default:printf ("Input option error.")
");
} return 0;
/* Function function: Display menu and read the user's keyboard input options */int menu (void) {int itemselected;/* integer variable itemselected for menu options/printf ("\ n student performance management system you \ \ \ \ n");
printf ("1. Enter student score \ n");
printf ("2. Calculate the total score and average score of the class");
printf ("3. Sort the score from high to Low");
printf ("4. Sort the number from big to small");
printf ("5. Check student's score by school number");
printf ("6. Statistical score \ n");
printf ("7. Score list \ n");
printf ("0. exit \ n");
printf ("Please enter your choice:"); scanf ("%d", &itemselected);
* * Read user input/return itemselected;
/* Function function: Input n Student's course result/void Readscore (Long num[],float score [],int n) {int i;
printf ("Input student ' s id,name and score:\n");
for (i=0;i<n;i++) {scanf ("%ld%f", &num[i],&score[i]);
}/* Function function: Calculates the class total score and the average score/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\n", sum,n>0?sum/n:0); ///////function: Score the element values of the array to order from high to low according to the selection method/void Desortbyscore (Long num[],float score[],int n) {int i,j,k;
float Temp1;
Long Temp2;
for (i=0;i<n-1;i++) {k=i;
for (j=i+1;j<n;j++) {if (score[j]>score[k]) k=j;
} if (k!=i) {/* Exchange score/TEMP1=SCORE[K];SCORE[K]=SCORE[I];SCORE[I]=TEMP1;
/* Exchange to learn * * TEMP2=NUM[K];NUM[K]=NUM[I];NUM[I]=TEMP2;
}//* Function function: By selection, the element values of the array num are sorted from small to large/void Assortbynum (Long num[],float score[],int n) {int i,j,k;
float Temp1;
Long Temp2;
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) {/* Exchange score/TEMP1=SCORE[K];SCORE[K]=SCORE[I];SCORE[I]=TEMP1;
/* Exchange to learn * * TEMP2=NUM[K];NUM[K]=NUM[I];NUM[I]=TEMP2;
}//* Function function: Find student scores by school number and display lookup results/void Searchbynum (Long num[],float score[],int n) {long;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%.0f\n", Num[i],score[i]);
Return
} printf ("\nnot found!\n");
/* Function function: Statistics of the number and percentage of students in each section/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%%\n", T[i), (float) t[i]/n*10
0); else if (i==5) {printf ("%d\t%d\t%.2f%%\n", (i+5) *10,t[i], (float) t[i]/n*100);
else {printf ("%d-%d\t%d\t.2f%%\n", (i+5) *10, (i+5) *10+9,t[i], (float) t[i]/n*100);
}}/* Function function: Print student score/void Printscore (Long num[],float score[],int n) {int i;
for (i=0;i<n;i++) {printf ("%ld\t%.0f\n", Num[i],score[i]); }
}
2. Operation Result