Advertisement
Guest User

final cpp

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