-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBookingSystem.cpp
50 lines (44 loc) · 1.38 KB
/
BookingSystem.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
#include "BookingSystem.h"
#include <fstream>
#include <sstream>
#include <iostream>
void BookingSystem::addVenue(const std::string& name) {
venues[name] = Venue(name);
}
void BookingSystem::addDateToVenue(const std::string& venueName, const std::string& date) {
venues[venueName].addDate(date);
}
bool BookingSystem::bookVenue(const std::string& venueName, const std::string& date) {
return venues[venueName].bookDate(date);
}
void BookingSystem::loadFromCSV(const std::string& filename) {
std::ifstream file(filename);
std::string line;
while (getline(file, line)) {
std::istringstream ss(line);
std::string venueName, date;
getline(ss, venueName, ',');
addVenue(venueName);
while (getline(ss, date, ',')) {
addDateToVenue(venueName, date);
}
}
}
void BookingSystem::saveToCSV(const std::string& filename) {
std::ofstream file(filename);
for (const auto& pair : venues) {
file << pair.first;
for (const auto& date : pair.second.availableDates) {
file << "," << date;
}
file << "\n";
}
}
void BookingSystem::printVenues() {
for (const auto& pair : venues) {
std::cout << "Venue: " << pair.first << "\nAvailable Dates:\n";
for (const auto& date : pair.second.availableDates) {
std::cout << " " << date << "\n";
}
}
}