This repository was archived by the owner on Dec 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1_main.cpp
89 lines (82 loc) · 2.43 KB
/
p1_main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//============================================================================
// Name : p1_main.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : C++ project part I for CSCE 121 and IF4093
//============================================================================
//
#include "Menu.h"
using namespace std;
int main() {
try {
Menu m;
int option;
bool exit = false; ////Boolean Variable to check whether user really want to exit M.O. A.1
m.display_main_menu();
do {
cout << "> ";
while (!(cin >> option) || option < Menu::Info || option > Menu::Exit) {
if (cin.fail()) { // we found something that wasn’t an integer
cin.clear(); // enable us to look at the characters
char ch;
while (cin>>ch && !isdigit(ch)) {
cerr << "Invalid input; please try again" << endl;
cout << "> ";
}
cin.unget();
} else { // option < Menu::Info || option > Menu::Exit */
cerr << "Invalid input; please try again" << endl;
cout << "> ";
}
}
switch(option) {
case Menu::Info:
m.display_info();//display assignment info & your names plus "Project 1"
break;
case Menu::Read:
try {
m.read();
} catch (const Menu::InvalidFile& excp) {
cerr << excp.what() << endl;
} catch (const Menu::InvalidData& excp) {
cerr << excp.what() << endl;
}
break;
case Menu::Find:
m.find();
break;
case Menu::Show:
m.show();
break;
case Menu::Update:
m.update();
break;
case Menu::Exit: //Author : M.O.-A.1 //Checking the user input to exit
{
char ex; //variable for contain user answer(M.O.)
do
{
cout<< "Are You Sure? (Y/N)" <<endl; //Asking user for input(M.O.)
cin>> ex;
if ((ex == 'Y') || (ex == 'y'))
exit = true; //Change exit value to true and exit the program (M.O.)
else if ((ex == 'N') || (ex == 'n')) {}
else
cerr << "Invalid input; please try again" << endl;
}
while ((ex != 'Y') && (ex != 'y') && (ex != 'N') && (ex != 'n'));
break;
}
}
//m.display_main_menu(); Delete because already done at the beginning and doesn't need to be done when exit M.O. A.1
} while (exit == false); //M.O.-A.1 //Change the loop condition from option!=Menu::Exit to exit==false
return 0;
}
catch (exception& e) {
cerr << e.what() << endl;
}
catch (...) {
cerr << "unknown exception\n";
}
}