Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #include #include using namespace std; / / Tour Package class class TourPackage { public: string name; string location; double price; map reservations;

#include
#include
#include
#include
#include
using namespace std;
// Tour Package class
class TourPackage {
public:
string name;
string location;
double price;
map reservations; // date -> number of seats reserved
TourPackage(string name, string location, double price)
: name(name), location(location), price(price){}
void addReservation(string date, int seats){
if (reservations.find(date)!= reservations.end()){
reservations[date]+= seats;
} else {
reservations[date]= seats;
}
}
void deleteReservation(string date, int seats){
if (reservations.find(date)!= reservations.end()){
if (reservations[date]>= seats){
reservations[date]-= seats;
if (reservations[date]==0){
reservations.erase(date);
}
} else {
throw runtime_error("Not enough seats reserved for deletion");
}
} else {
throw runtime_error("No reservation found for deletion");
}
}
bool isSeatsAvailable(string startDate, string endDate, int seats){
for (auto it = reservations.begin(); it != reservations.end(); ++it){
if (it->first >= startDate && it->first <= endDate){
if (it->second >= seats){
return false;
}
}
}
return true;
}
};
// Tourism Company class
class TourismCompany {
public:
vector tourPackages;
void addTourPackage(string name, string location, double price){
tourPackages.push_back(TourPackage(name, location, price));
}
void viewTourPackages(){
for (auto it = tourPackages.begin(); it != tourPackages.end(); ++it){
cout << "Name: "<< it->name <<", Location: "<< it->location <<", Price: "<< it->price << endl;
}
}
void updateTourPackage(string name, string location, double price){
for (auto it = tourPackages.begin(); it != tourPackages.end(); ++it){
if (it->name == name){
it->location = location;
it->price = price;
return;
}
}
throw runtime_error("Tour package not found for update");
}
void deleteTourPackage(string name){
for (auto it = tourPackages.begin(); it != tourPackages.end(); ++it){
if (it->name == name){
tourPackages.erase(it);
return;
}
}
throw runtime_error("Tour package not found for deletion");
}
void addReservation(string packageName, string date, int seats){
for (auto it = tourPackages.begin(); it != tourPackages.end(); ++it){
if (it->name == packageName){
it->addReservation(date, seats);
return;
}
}
throw runtime_error("Tour package not found for reservation");
}
void viewReservations(string packageName){
for (auto it = tourPackages.begin(); it != tourPackages.end(); ++it){
if (it->name == packageName){
for (auto it2= it->reservations.begin(); it2!= it->reservations.end(); ++it2){
cout << "Date: "<< it2->first <<", Seats: "<< it2->second << endl;
}
return;
}
}
throw runtime_error("Tour package not found for viewing reservations");
}
void deleteReservation(string packageName, string date, int seats){
for (auto it = tourPackages.begin(); it != tourPackages.end(); ++it){
if (it->name == packageName){
it->deleteReservation(date, seats);
return;
}
}
throw runtime_error("Tour package not found for reservation deletion");
}
bool isSeatsAvailable(string packageName, string startDate, string endDate, int seats){
for (auto it = tourPackages.begin(); it != tourPackages.end(); ++it){
if (it->name == packageName){
return it->isSeatsAvailable(startDate, endDate, seats);
}
}
throw runtime_error("Tour package '"+ packageName +"' not found for reservation");
}
};
int main(){
TourismCompany company;
while (true){
cout <<"1. Add Tour Package" << endl;
cout <<"2. View Tour Packages" << endl;
cout <<"3. Update Tour Package" << endl;
cout <<"4. Delete Tour Package" << endl;
cout <<"5. Add Reservation" << endl;
cout <<"6. View Reservations" << endl;
cout <<"7. Delete Reservation" << endl;
cout <<"8. Check Seat Availability" << endl; show me the erros

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions