Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "gradeBook.h"
- #include "gradeBookHandle.h"
- using namespace std;
- int main()
- {
- gradeBook database[256];
- int ix = 0;//Current index of input to database
- bool runProgram = true;//Flag to keep running program
- while (runProgram) {
- int choice;//User input from menu
- cout << "1. Input new gradebook into system\nType 0 to quit\n";//Print menu
- cin >> choice;//Accept input
- if (choice == 0) //If choice == 0, exit program
- {
- runProgram = false;
- }
- if (choice == 1) //If choice == 1, prompt user for inputs to create new gradebook
- {
- gradeBook newbook;
- gradeBookHandle handler;//New gradebook to input to database
- bool nameVal = false;//Flag to check if input of name was accepted
- string name;
- bool emailVal = false;//Flag to check if input of email was accepted
- string email;
- bool idVal = false;//Flag to check if input of id was accepted
- string id;
- cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');//Ignores previous cin method to prevent error with getline
- while (!nameVal) //Ask for user input until input is in valid form
- {
- cout << "Input name: ";
- getline(cin, name);//Using getline to prevent input from being cut off at a whitespace
- nameVal = handler.setName(name, newbook);
- }
- while (!emailVal) {
- cout << "Input email: ";
- getline(cin, email);
- emailVal = handler.setEmail(email, newbook);
- }
- while (!idVal) {
- cout << "Input ID: ";
- getline(cin, id);
- idVal = handler.setID(id, newbook);
- }
- for (int i = 0; i < 3; i++) //Asks for 3 mark values and checks if each is valid before continuing to next one
- {
- bool markValid = false;
- int mark;
- while (!markValid) {
- cout << "Input mark: ";
- cin >> mark;
- markValid = handler.addMark(mark, newbook);
- }
- }
- database[ix] = newbook;//Adds new gradebook into database
- ix += 1;//Increment index
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement