-
Notifications
You must be signed in to change notification settings - Fork 0
/
ticket.cpp
211 lines (167 loc) · 6.88 KB
/
ticket.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* ***************************************************************
* Objectives/Description: A ticket management system that could be an alternative to one used in Fresh Food Company at the USM.
* Supports two plans currently: Unlimited Plan and Limited Plan. Plan features might not be what Fresh Food offer.
* Input: student or guest check-in. Student Id for students and card details for outsiders.
* Output: Status of the account for students. Confirmation for purchase or entrance, or denial of entrance.
* ***************************************************************
*/
#include "ticket.h"
#include <fstream>
#include <sstream>
using namespace std;
void student_entrance();
void guest_entrance();
vector <vector <string>> read_csv(string filename);
void save_csv(vector<vector<string>>& data, string filename);
/* *************************************************
* Function Name: main
* Function Description: Shows the menu for students and guests.
* Function Parameters: NA
* What is returned, if anything: NA
* *************************************************
*/
int main(){
char response = 'q';
cout <<
" ██████╗ ███████╗████████╗████████╗███████╗██████╗ ███████╗██████╗ ███████╗███████╗██╗ ██╗\n"
" ██╔══██╗██╔════╝╚══██╔══╝╚══██╔══╝██╔════╝██╔══██╗ ██╔════╝██╔══██╗██╔════╝██╔════╝██║ ██║\n"
" ██████╔╝█████╗ ██║ ██║ █████╗ ██████╔╝ █████╗ ██████╔╝█████╗ ███████╗███████║\n"
" ██╔══██╗██╔══╝ ██║ ██║ ██╔══╝ ██╔══██╗ ██╔══╝ ██╔══██╗██╔══╝ ╚════██║██╔══██║\n"
" ██████╔╝███████╗ ██║ ██║ ███████╗██║ ██║ ██║ ██║ ██║███████╗███████║██║ ██║\n"
" ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝ ╚═╝\n"
<< endl;
do
{
cout << "Enter s for student, g for guest, & q to quit:";
cin >> response;
if (response == 's'){
student_entrance();
}
else if(response == 'g'){
guest_entrance();
}
}
while(response!='q');
return 0;
}
/* *************************************************
* Function Name: student_entrance
* Function Description: allows students to enter their details and use or deny their swipes
* Function Parameters: NA
* What is returned, if anything: NA
* *************************************************
*/
void student_entrance(){
string wid;
cout << "Enter Your Student ID: ";
cin >> wid;
vector<vector<string>> student_data;
student_data = read_csv("student_data.csv");
string name, plan, weekly_available, daily_available, guest_swipes, dining_dollars, last_swipe;
int student_index;
for (int i=0; i< size(student_data); i++){
if (student_data[i][0] == wid){
student_index = i;
break;
}
else{
student_index = -1;
}
}
if (student_index != -1){
vector<string> row = student_data[student_index];
wid = row[0];
name = row[1];
plan = row[2];
weekly_available = row[3];
daily_available = row[4];
guest_swipes = row[5];
dining_dollars = row[6];
last_swipe = row[7];
Student student = Student( wid,
name,
plan,
weekly_available,
daily_available,
guest_swipes,
dining_dollars,
last_swipe);
student.swipe();
student.get_status();
row = student.vectorize();
student_data.at(student_index) = row;
save_csv(student_data, "student_data.csv");
}
else{
cout << "Student is not in the database." << endl;
}
}
/* *************************************************
* Function Name: guest_entrance
* Function Description: allows guests to enter the Fresh using their payment card.
* Function Parameters: NA
* Paramter type, name and use: NA
* What is returned, if anything: NA
* *************************************************
*/
void guest_entrance(){
long number;
string uname;
cout << "Enter Your Card Number: ";
cin >> number;
cout << "Enter Your Name: ";
cin >> uname;
Outsider(number,uname).make_purchase();
}
/* *************************************************
* Function Name: read_csv
* Function Description: reads the given csv file into a 2D vector.
* Function Parameters: filename
* Paramter type, name and use: string
* What is returned, if anything: vector
* *************************************************
*/
vector<vector<string>> read_csv(string filename){
ifstream input_file(filename);
if (!input_file) {
cout << "Failed to open the file." << endl;
}
vector<vector<string>> data;
string line;
while (getline(input_file, line)) {
istringstream iss(line);
vector<string> lineData;
string item;
while(getline(iss, item, ',')) {
lineData.push_back(item);
}
data.push_back(lineData);
}
input_file.close();
return data;
}
/* *************************************************
* Function Name: save_csv
* Function Description: saves the given 2D vector into csv file
* Function Parameters: data, filename
* Paramter type, name and use: vector data, string filename
* What is returned, if anything: NA
* *************************************************
*/
void save_csv(vector<vector<string>>& data, string filename) {
ofstream output_file(filename);
if (!output_file) {
cout << "Failed to open the file for writing." << endl;
return;
}
for (const auto& line : data) {
for (auto it = line.begin(); it != line.end(); ++it) {
output_file << *it;
if (it != line.end() - 1) {
output_file << ",";
}
}
output_file << endl;
}
output_file.close();
}