Advertisement
Guest User

AJSDASD

a guest
Dec 7th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include "gradeBook.h"
  4. #include "gradeBookHandle.h"
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. gradeBook database[256];
  10.  
  11. int ix = 0;//Current index of input to database
  12.  
  13. bool runProgram = true;//Flag to keep running program
  14. while (runProgram) {
  15.  
  16. int choice;//User input from menu
  17.  
  18. cout << "1. Input new gradebook into system\nType 0 to quit\n";//Print menu
  19.  
  20. cin >> choice;//Accept input
  21.  
  22. if (choice == 0) //If choice == 0, exit program
  23. {
  24. runProgram = false;
  25. }
  26.  
  27. if (choice == 1) //If choice == 1, prompt user for inputs to create new gradebook
  28. {
  29. gradeBook newbook;
  30. gradeBookHandle handler;//New gradebook to input to database
  31. bool nameVal = false;//Flag to check if input of name was accepted
  32. string name;
  33. bool emailVal = false;//Flag to check if input of email was accepted
  34. string email;
  35. bool idVal = false;//Flag to check if input of id was accepted
  36. string id;
  37. cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');//Ignores previous cin method to prevent error with getline
  38. while (!nameVal) //Ask for user input until input is in valid form
  39. {
  40. cout << "Input name: ";
  41. getline(cin, name);//Using getline to prevent input from being cut off at a whitespace
  42. nameVal = handler.setName(name, newbook);
  43. }
  44. while (!emailVal) {
  45. cout << "Input email: ";
  46. getline(cin, email);
  47. emailVal = handler.setEmail(email, newbook);
  48. }
  49. while (!idVal) {
  50. cout << "Input ID: ";
  51. getline(cin, id);
  52. idVal = handler.setID(id, newbook);
  53. }
  54.  
  55. for (int i = 0; i < 3; i++) //Asks for 3 mark values and checks if each is valid before continuing to next one
  56. {
  57. bool markValid = false;
  58. int mark;
  59. while (!markValid) {
  60. cout << "Input mark: ";
  61. cin >> mark;
  62. markValid = handler.addMark(mark, newbook);
  63. }
  64. }
  65.  
  66. database[ix] = newbook;//Adds new gradebook into database
  67. ix += 1;//Increment index
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement