Created
December 7, 2011 14:50
-
-
Save lepture/1443085 to your computer and use it in GitHub Desktop.
forget c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<stdlib.h> | |
| #define MAX 100 | |
| int choice=1, count=0; | |
| double scores[MAX][6]; | |
| int notify() { | |
| printf("\nYou can do:\n [1]: Input a Student Score\t[2]: Print Students Scores\t[3]: Sort Students Scores\t[4]:Exit\n>>> "); | |
| scanf("%d", &choice); | |
| return 1; | |
| } | |
| int inputScore() { | |
| if(count >= MAX) { | |
| printf("Sorry, you need buy a larger storage. Will you buy it?"); | |
| return 0; | |
| } | |
| printf("Student NO: "); | |
| scanf("%lf", &scores[count][0]); | |
| printf("Chinese Score: "); | |
| scanf("%lf", &scores[count][1]); | |
| printf("Math Score: "); | |
| scanf("%lf", &scores[count][2]); | |
| printf("Computer Score: "); | |
| scanf("%lf", &scores[count][3]); | |
| scores[count][4] = scores[count][1] + scores[count][2] + scores[count][3]; | |
| scores[count][5] = scores[count][4] / 3; | |
| count += 1; | |
| return 1; | |
| } | |
| void printScore() { | |
| int i = 0; | |
| printf("NO.\tChinese\t\tMath\t\tComputer\tTotal\t\tAverage\n"); | |
| while (i < count) { | |
| printf("%0.0f\t%0.1f\t\t%0.1lf\t\t%0.1lf\t\t%0.1lf\t\t%0.1lf\n", scores[i][0], scores[i][1], scores[i][2], scores[i][3], scores[i][4], scores[i][5]); | |
| i += 1; | |
| } | |
| } | |
| void sortScore() { | |
| int sortIndex[count]; | |
| int i, j, tmp; | |
| for (i=0; i < count; i++) { | |
| sortIndex[i] = i; | |
| } | |
| // bubble sort | |
| for (i=0; i < count; i++) { | |
| for(j=0; j < count-1; j++) { | |
| if(scores[j][5] < scores[j+1][5]) { | |
| tmp = sortIndex[j+1]; | |
| sortIndex[j+1] = sortIndex[j]; | |
| sortIndex[j] = tmp; | |
| } | |
| } | |
| } | |
| printf("NO.\tChinese\t\tMath\t\tComputer\tTotal\t\tAverage\n"); | |
| j = 0; | |
| while (j < count) { | |
| i = sortIndex[j]; | |
| printf("%0.0f\t%0.1f\t\t%0.1lf\t\t%0.1lf\t\t%0.1lf\t\t%0.1lf\n", scores[i][0], scores[i][1], scores[i][2], scores[i][3], scores[i][4], scores[i][5]); | |
| j += 1; | |
| } | |
| } | |
| int main() { | |
| printf("Welcome to Student Score System\n"); | |
| while (choice != 4) { | |
| notify(); | |
| if (choice == 1) { | |
| inputScore(); | |
| } else if (choice == 2) { | |
| printScore(); | |
| } else if (choice == 3) { | |
| sortScore(); | |
| } | |
| } | |
| printf("\nThanks, goodbye. Have a nice day."); | |
| return choice; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For whom was this homework written ? ;p