-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
124 lines (110 loc) · 2.1 KB
/
Copy pathMenu.cpp
File metadata and controls
124 lines (110 loc) · 2.1 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Citationand Sources...
Final Project Milestone ?
Module : Status
Filename : Status.cpp
Version 1.0
Author John Doe
Revision History
Name : Shayan Chabook
student ID : 159844208
email address : schabook@myseneca.ca
---------------------------------------------------------- -
Date 4 / 10 / 2022
---------------------------------------------------------- -
I have done all the coding by myself and only copied the code
that my professor provided to complete my workshops and assignments.
---------------------------------------------------------- - */
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <ctime>
#include <cstring>
#include <string>
#include "Utils.h"
#include "Status.h"
#include "Menu.h"
using namespace std;
namespace sdds {
Menu::Menu()
{
option = nullptr;
optnAvlb = -1;
}
Menu::Menu(unsigned int numOfOptn, const char* optn)
{
if (numOfOptn < 15 && optn != nullptr)
{
optnAvlb = numOfOptn;
ut.alocpy(option, optn);
}
else
{
operator bool();
}
}
Menu::~Menu()
{
delete[] option;
option = nullptr;
}
unsigned int Menu::run()
{
int number = -100, count = -1;
unsigned int i;
int flag = 0;
for (i = 0; i < strlen(option); i++)
{
if (option[i] != '\n')
{
cout << option[i];
}
else
{
cout << '\n';
count += 1;
}
}
cout << "0- Exit" << endl;
cout << "> ";
do
{
cin >> number;
flag = 0;
if (number < 0 || number > count)
{
cout << "Value out of range [0<=val<=" << count << "]: ";
}
else if (!cin)
{
cout << "Invalid Integer, retry: ";
cin.clear();
cin.ignore(1000, '\n');
flag = 1;
}
} while (number < 0 || number > count || flag == 1);
return number;
}
Menu::operator bool() const
{
if (optnAvlb > 15 || option == nullptr)
return false;
else
return true;
}
void Menu::setMenu(const char* optn)
{
ut.alocpy(option, optn);
}
void Menu::menuSet(const char* option, int number)
{
if (number < 15 || option != nullptr)
{
optnAvlb = number;
ut.alocpy(this->option, option);
}
else
{
this->option = nullptr;
optnAvlb = 0;
}
}
}