diff --git a/step4.cpp b/step4.cpp new file mode 100644 index 0000000..b5a1b6c --- /dev/null +++ b/step4.cpp @@ -0,0 +1,106 @@ +#include + +#define COL 6 +#define GRADEBINGIN 2 + +int studentMember = 0; +double storeInformation[100][COL]; + +void inputStudentInformation(double store[][COL]) +{ + double* p; + int i = 0, j = 0; + while (1) { + p = &store[i][j]; + double temp; + scanf("%lf", &temp); + *p = temp; + j++; + if (j == COL - 1) { + *(p + 1) = 0; + printf("One student's information has been, input 0 or 1 to quit or continue.\n"); + int ch; + scanf("%d", &ch); + if (ch == 0) { break; } + else if (ch == 1) + { + j = 0; + i++; + studentMember++; + } + else { + printf("WRONG INPUT,aoto quit\n"); + break; + } + } + } +} + +double sumScore(double store[][COL], int n) { + double sum = 0; + for (int i = GRADEBINGIN; i < COL - 1; i++) { + sum += store[n][i]; + } + return sum; +} + +void printStudentOriginalScore(double store[][COL]) +{ + for (int i = 0; i <= studentMember; i++) { + printf("%5d %d %.1f %.1f %.1f %.1f %s\n", (int)store[i][0], (int)store[i][1], store[i][2], store[i][3], store[i][4], sumScore(store, i), store[i][6] == 1? "":"inserted"); + } +} + +void printstep2(double store[][COL]) { + for (int i = 0; i <= studentMember; i++) { + printf("%5d,%.1f,%.1f\n", (int)storeInformation[i][0], sumScore(storeInformation, i), sumScore(storeInformation, i) / 3); + } +} + +void insertedNew() { + printf("The new student information\n"); + studentMember++; + double* p; + for (int i = 0; i < COL - 1; i++) { + p = &storeInformation[studentMember][i]; + double temp = 0; + scanf("%lf", &temp); + *p = temp; + } + *(p + 1) = 1; +} + +void manage() +{ + printf(" 1.Input\n"); + printf(" 2.Output\n"); + printf(" 3.Order\n"); + printf(" 4.Quit\n"); + char keywords; + keywords = getchar(); + switch (keywords) { + case 'i': + printf("Please input info of the three students\n"); + inputStudentInformation(storeInformation); + break; + case 'o': + printf("You are trying to Output info\n"); + break; + case 'm': + printf("You are trying to Make things ordered\n"); + break; + case 'q': + printf("You are about to Quit\n"); + break; + default: + printf("Wrong input\n"); + break; + } +} +int main() +{ + manage(); + insertedNew(); + printStudentOriginalScore(storeInformation); + return 0; +} \ No newline at end of file