-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.hpp
59 lines (51 loc) · 1.79 KB
/
menu.hpp
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
/*********************************************************************
** Program name: menu.hpp
** Author: Andrew Ngo
** Date: 03/09/2018
** Description: Header for a Menu class that can be reused for any
* type of text-based menu that accepts numerical input. Private data
* members are ints for the range of valid input, and additional
* vars for user choice, used to verify if the input is valid and pass
* the valid user choice into a main program.
*********************************************************************/
#include <string>
#ifndef MENU_HPP
#define MENU_HPP
/*********************************************************************
** Description: menuChoice is an enumerated variable used for quickly
* associating an action to an input variable.
*********************************************************************/
enum menuChoice {DEBUG, PLAY, QUIT};
class Menu
{
private:
int start = 0;
int end = 0;
int choice = 0;
int menuChoice = 0;
bool validChoice = false;
public:
Menu(int start, int end);
void displayMenu();
// getters and setters
void setStart(int);
void setEnd(int);
void setChoice(int);
void setMenuChoice(int);
void setValidChoice(bool);
int getMenuChoice();
int getStart();
int getEnd();
int getChoice();
bool getValidChoice();
// validation functions
bool checkValidChoice(int start, int end, int choice);
int validatePosInt(int num, std::string request);
int ensureLessThan(int, int, std::string, std::string);
int ensureMoreThan(int, int, std::string, std::string);
bool validInt(std::string check);
int requestIntInput(std::string request);
int requestPosIntInput(std::string request);
int requestPosIntInputBetween(std::string request, int low, int high);
};
#endif