int main() { system("mode con cols=120"); //设定窗口大小 //passwordcheck("613613613"); //密码验证 FILE *studenttxt = openfile(); //打开student.txt文件 x.inputFromFile(studenttxt); //txt储存信息读入内存 printinstructions(); //打印操作提示信息 char cmd[100]; //接受模式选择命令 while (scanf("%s", cmd)) { if (strcmp(cmd, "0") == 0) break; else if (strcmp(cmd, "1") == 0) //添加学生,添加完学生立刻更新txt以防信息丢失 { x.addStudent(); x.outPutToFile(studenttxt); } else if (strcmp(cmd, "2") == 0) //查看单个学生 { x.outPutToScreenByStdnum(); } else if (strcmp(cmd, "3") == 0) //输出所有学生所有信息到屏幕 { printf("按照什么顺序排序?\n"); printf(("0——默认顺序 1——按学号排序 2——GPA顺序\n")); int flag; scanf("%d", &flag); if (flag == 1) x.sortByStdnum(); else if (flag == 2) x.sortByGPA(); x.outPutToScreen(); } else if (strcmp(cmd, "4") == 0) //输出基本信息到屏幕 { printf("按照什么顺序排序?\n"); printf(("0——默认顺序 1——按学号排序 2——GPA顺序\n")); int flag; scanf("%d", &flag); if (flag == 1) x.sortByStdnum(); else if (flag == 2) x.sortByGPA(); x.outputBaseInformatioonToScreen(); } else if (strcmp(cmd, "5") == 0) //输出成绩到屏幕 { printf("按照什么顺序排序?\n"); printf(("0——默认顺序 1——按学号排序 2——GPA顺序\n")); int flag; scanf("%d", &flag); if (flag == 1) x.sortByStdnum(); else if (flag == 2) x.sortByGPA(); x.outPutScoresToScreen(); } else if (strcmp(cmd, "6") == 0) //输出体测结果到屏幕 { printf("按照什么顺序排序?\n"); printf(("0——默认顺序 1——按学号排序 2——GPA顺序\n")); int flag; scanf("%d", &flag); if (flag == 1) x.sortByStdnum(); else if (flag == 2) x.sortByGPA(); x.outPutSportsmarkToScreen(); } else if (strcmp(cmd, "7") == 0) //改 { x.changeStudent(); } else if (strcmp(cmd, "8") == 0) //删 { x.deleteStudentByStdnum(); } else if (strcmp(cmd, "9") == 0) //清空 { x.empty(); } system("PAUSE"); printf("\n"); printinstructions(); //每次做完一个操作都再输出一次提示信息 } x.outPutToFile(studenttxt); //输出到文件保存信息 fclose(studenttxt); //关闭文件 return 0; }
int main() { int quit = 0; while (quit == 0) { string input; string textInput; string textInput2; string textInput3 = ""; string textInput4 = ""; string textInput5 = ""; int numericInput = -1; stringstream ss; cout << "tables> "; getline(cin, input); ss << input; ss >> textInput >> textInput2 >> numericInput >> textInput3 >> textInput4 >> textInput5; if (textInput == "students") { if (textInput2 == "add") { if (numericInput != -1 && textInput3 != "" && textInput4 != "") { stuNode *s = new stuNode(numericInput, textInput3, textInput4); st_Students.addStudent(s); } else { cout << "Error: Student Must Have A Name" << endl; } } else if (textInput2 == "delete") { if (numericInput != -1) { st_Students.deleteS(numericInput); } else { cout << "Error: Must Include Student ID Number" << endl; } } else if (textInput2 == "display") { st_Students.print(); cout << endl; } else { cout << "Error: Unrecognized Student Command" << endl; } } else if (textInput == "grades") { if (textInput2 == "add") { if (numericInput != -1 && textInput3 != "" && textInput4 != "") { if (textInput5 != "") { cout << "Error: Cannot Add Multiple Grades At Once" << endl; } else { gt_Grades.addGrade(numericInput, textInput3, textInput4); } } else { cout << "Error: Must Include Course And Grade" << endl; } } else if (textInput2 == "delete") { if (numericInput != -1) { gt_Grades.deleteG(numericInput); } else { cout << "Error: Must Include Student ID Number" << endl; } } else if (textInput2 == "display") { gt_Grades.print(); cout << endl; } else { cout << "Error: Unrecognized Grade Command" << endl; } } else if (textInput == "quit") { quit = 1; } else { cout << "Error: Unrecognized Command" << endl; } //quit = 1; } // THIS WORKS //stuNode *s = new stuNode(5, "alan", "macon"); //st_Students.studentTable[0] = s; //st_Students.studentTable[0]->print(); //cout << endl; /*for (int i = 0; i < 4; i++) { // ADD STUDENTS stuNode *s = new stuNode(i, "ALAN", "MACON"); st_Students.addStudent(s); graNode *g = new graNode(i, "COMPUTER", "A"); gt_Grades.addGrade(g); } // PRINT STUDENTS st_Students.print(); cout << endl; // PRINT GRADES gt_Grades.print(); cout << endl; // PRINT SPECIFIC GRADE gt_Grades.print(2); cout << endl; // DELETE STUDENTS st_Students.deleteS(2); st_Students.print(); cout << endl; gt_Grades.print(2); cout << endl;*/ // BEGIN SAMPLE INPUT //students add 123 josh smith /*stuNode *s = new stuNode(123, "josh", "smith"); st_Students.addStudent(s); //students add 111 jim jones stuNode *q = new stuNode(111, "jim", "jones"); st_Students.addStudent(q); gt_Grades.addGrade(123, "computers", "A"); gt_Grades.addGrade(123, "biology", "C"); gt_Grades.addGrade(123, "chemistry", "B"); //grades display gt_Grades.print(); // These should also be sorted by class name, somehow. cout << endl; //students display st_Students.print(); cout << endl; //students delete 123 st_Students.deleteS(123); //grades display gt_Grades.print(); cout << endl; //students delete 111 st_Students.deleteS(111); //students display st_Students.print(); cout << endl; // END SAMPLE INPUT system("PAUSE");*/ }