forked from ChurchillV/Hotel-Management-Application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
99 lines (94 loc) · 3.24 KB
/
test.cpp
File metadata and controls
99 lines (94 loc) · 3.24 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
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <vector>
using namespace std;
vector<string> split(string text, char delimiter);
string ROOM_DATA = "data/Room_Details.csv";
string GUEST_DATA = "data/Guest_Data.csv";
const int a = 97;
const int z = 122;
const int ESC = 27;
int main() {
ifstream file;
string data;
vector<string> row;
cout << "HOTEL MANAGEMENT APPLICATION";
bool exit_program = false; // This will end the programme
while(!exit_program) {
bool back_to_menu = false; //This will take the user back to the main menu
cout << "\n\na - Display all room data\n"
<< "z - Display all guest data\n"
<< "Esc - Exit program\n"
<< "Option: ";
fflush(stdin);
int option = getch();
while(!back_to_menu) {
switch (option) {
case a:
file.open(ROOM_DATA);
while(getline(file, data)) {
row.push_back(data);
}
for (int i = 0; i < row.size(); i++) {
vector<string> data = split(row[i], ',');
cout << "\n--------------\n"
<< "Room " << i+1 << endl
<< "Room Id: " << data[0] << endl
<< "Room Type: " << data[1] << endl
<< "Room Price: " << data[2] << endl
<< "Status: " << data[4] << endl
<< "Occupant Count: " << data[3];
}
back_to_menu = true;
file.close();
break;
case z:
file.open(GUEST_DATA);
while(getline(file,data)) {
row.push_back(data);
}
for (int i = 0; i < row.size(); i++) {
vector<string> data = split(row[i], ',');
cout << "\n--------------\n"
<< "Guest Id: " << data[0] << endl
<< "Guest Name: " << data[1] << endl
<< "Contact: " << data[2] << endl
<< "Residency Status: " << data[3] << endl
<< "Room Id: " << data[4];
}
back_to_menu = true;
file.close();
break;
case ESC:
exit_program = true;
back_to_menu = true;
break;
default:
//There's actually no need for a default function
break;
}
}
}
return 0;
}
//Function to separate the data obtained from each row
vector<string> split(string text, char delimiter){
//Vector to store the individual data
vector<string> tokens;
string token;
int i = 0;
while (i < text.length()) {
if(text[i] == delimiter) {
//Add the token to the tokens vector when a delimiter is found
tokens.push_back(token);
token = ""; //Reset the token to an empty string
}
else token += text[i];
i++;
}
//When we reach the end of a row, add the last value to the vector
if(token.length() > 0) tokens.push_back(token);
return tokens;
};