// advance the game to the next turn, // assuming that the dice has just been rolled and produced diceScore // the game starts in turn -1 (we call this state "Terra Nullis") and // moves to turn 0 as soon as the first dice is thrown. // determines which region contains the diceValue of the diceScore // determines who gets what void throwDice (Game g, int diceScore) { // advances the game to next turn g->currentTurn++; // to obtain the regionID/location of the diceScore/diceValue int i = 0; int regionID = 0; while (i < NUM_REGIONS) { if (diceScore == getDiceValue(g, i)) { regionID = i; addStudents (g, regionID); } i++; } // whenever a 7 is thrown, immediately after any new students are produced, // all MTV and MMONEY students of all universities decide to switch to ThD's. int curPlayer = 0; if (diceScore == 7) { curPlayer = UNI_A; while (curPlayer < NO_PLAYERS) { g->uni[curPlayer].numStudents[STUDENT_THD] += g->uni[curPlayer].numStudents[STUDENT_MTV] + g->uni[curPlayer].numStudents[STUDENT_MMONEY]; g->uni[curPlayer].numStudents[STUDENT_MTV] = 0; g->uni[curPlayer].numStudents[STUDENT_MMONEY] = 0; curPlayer++; } } }
bool showMenu() { cout << "Welcome to Student Performance Management System (SPMS)." << "\n"; cout << "\n"; cout << "1 - Add" << "\n"; cout << "2 - Remove" << "\n"; cout << "3 - Query" << "\n"; cout << "4 - Show ranking" << "\n"; cout << "5 - Show Statistics" << "\n"; cout << "0 - Exit" << "\n"; cout << "\n"; int n; cin >> n; switch ( n ) { case 1: while ( addStudents() ); break; case 2: while ( deleteStudents() ); break; case 3: while ( queryStudents() ); break; case 4: cout << "Showing the ranklist hurts students' self-esteem. Don't do that." << "\n"; break; case 5: showStatistics(); break; case 0: return false; } return true; }
//DONE void throwDice (Game g, int diceScore) { //function protection assert(g != NULL); assert(diceScore >= 2 && diceScore <= 12); //store dicescore //increase turn //next player //increment students //^convert if number = 7 to scrub students g->diceScore = diceScore; g->currentTurn++; nextPlayer(g); addStudents(g); }
/* * * * * * * * * * * * * * * * * * * * * * * * * Main Program: Display menu, get and run user choice. * * * * * * * * * * * * * * * * * * * * * * * * */ int main() { int choice = 0; // store user selection int quit = 0; // flag to end program // print the menu, loop until user quits do { printf("\n\nWelcome to STUDENTS!\n===================\n\n" "There are currently %d students in memory.\n\n" "1. Add New Student(s)\n" "2. Find Student by Last Name\n" "3. List All Students\n" "4. Sort Database\n" "5. Load Students File (./students.dat)\n" "6. Save Students File (./students.dat)\n" "7. Clear Memory (New Database)\n" "8. Quit\n\n", numStudents); // input the user selection choice = inputInteger("Choice: "); printf("\n"); // run the appropriate function based on user choice switch (choice) { case 1: // add addStudents(); break; case 2: // find findStudent(); break; case 3: // list listStudents(); break; case 4: // sort sortStudents(); break; case 5: // load if (numStudents == 0 || confirm("LOAD file and LOSE all students in memory (y/n) ? ")) loadStudents(); break; case 6: // save (only if students[] is not empty) if (numStudents == 0) printf("There are no students to save yet!\n"); else if (confirm("OVERWRITE the file (y/n) ? ")) saveStudents(); break; case 7: // new if (confirm("DELETE all students from memory (y/n) ? ")) clearStudents(); break; case 8: // quit default: // quit if (confirm("QUIT and LOSE all data in memory (y/n) ? ")) { printf("\nThank you and goodbye!\n\n"); quit = 1; } break; } } while (quit == 0); // keep repeating until user chooses to quit // quit = 1: end program successfully #ifdef _MSC_VER getchar(); getchar(); #endif return 0; }