Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <map>
- using namespace std;
- class Tourist
- {
- protected: string name; int id, contactNo, noOfPeople;
- public: Tourist(); Tourist(string, int, int, int); void showTourist(); int getID();
- bool operator < (const Tourist &TA) const
- {
- return (this->id < TA.id);
- }
- bool operator == (const Tourist &TouristA) const
- {
- if (this -> name == TouristA.name && this->id == TouristA.id)
- return true;
- else
- return false;
- }
- };
- Tourist :: Tourist()
- {
- name = ""; id = 0; contactNo = 0; noOfPeople = 0;
- }
- Tourist :: Tourist (string a, int b, int c, int d)
- {
- name = a; id = b; contactNo = c; noOfPeople = d;
- }
- int Tourist :: getID ()
- {
- return id;
- }
- void Tourist :: showTourist()
- {
- cout << "Name: " << name << endl;
- cout << "ID: " << id << endl;
- cout << "Contact No: " << endl;
- cout << "No of People: " << noOfPeople << endl;
- }
- class TourPackage
- {
- friend ostream& operator << (ostream &, const TourPackage&);
- private: int pid; string pName; double price; string desc, startingDate; int duration;
- public: TourPackage(); TourPackage(int, string, double, string, string, int);
- bool operator < (const TourPackage &TPA) const
- {
- return (this->pid < TPA.pid);
- }
- bool operator == (const TourPackage &TourPackageA) const
- {
- return (this->pid == TourPackageA.pid);
- }
- };
- ostream& operator << (ostream &out, const TourPackage & tourP)
- {
- out << "Package ID: " << tourP.pid << "\nPackage Name: " << tourP.pName << "\nPackage Price: " << tourP.price <<
- "\nPackage Desc: " << tourP.desc << "\nStarting-Date: " << tourP.startingDate << "\nDuration: " << tourP.duration << endl;
- return out;
- }
- TourPackage :: TourPackage ()
- {
- pid = 0; pName = ""; price = 0; desc = ""; startingDate = ""; duration = 0;
- }
- TourPackage :: TourPackage (int a, string b, double c, string d, string e, int f)
- {
- pid = a; pName = b; price = c; desc = d; startingDate = e; duration = f;
- }
- template <class T>
- T getNthElementFromSet(set<T> &searchSet, int SelectedIndex)
- {
- T a;
- int index(0);
- for (T elem: searchSet)
- {
- index++;
- if(index == SelectedIndex)
- {
- a=elem;
- break;
- }
- }
- return a;
- }
- int main ()
- {
- int option1, option2, trNo;
- bool check1;
- vector <Tourist> myTourist;
- string name; int id, contactNo, noOfPeople;
- set <TourPackage> myTourPackage;
- int pid; string pName; double price; string desc, startingDate; int duration;
- multimap <TourPackage, Tourist> myTourList;
- do
- {
- cout << "1. Add a new tour package" << endl;
- cout << "2. Register a tourist to a package" << endl;
- cout << "3. Show all tourists registered" << endl;
- cout << "4. Show all packages available" << endl;
- cout << "5. Show the total tourist registered for a particular package and the number of availability" << endl;
- cout << "Option: ";
- cin >> option1;
- switch (option1)
- {
- case 1:
- {
- cout << "Enter Package ID: ";
- cin >> pid;
- cout << "Enter Package Name: ";
- cin >> pName;
- cout << "Enter Package Price: ";
- cin >> price;
- cout << "Enter Package Description: ";
- cin >> desc;
- cout << "Enter the Starting-Date: ";
- cin >> startingDate;
- cout << "Enter the Package Duration: ";
- cin >> duration;
- TourPackage p1(pid, pName, price, desc, startingDate, duration);
- myTourPackage.insert(p1);
- }
- break;
- case 2:
- {
- check1 = false;
- cout << "Enter Name: ";
- cin >> name;
- cout << "Enter ID: ";
- cin >> id;
- for (int i = 0; i < myTourist.size(); i++)
- {
- if (id == myTourist[i].getID())
- {
- trNo = i;
- cout << "ID has been registered before!" << endl;
- check1 = true;
- break;
- }
- }
- if (check1 == false)
- {
- trNo = myTourist.size();
- cout << "Enter Contact No: ";
- cin >> contactNo;
- cout << "Enter No-of-People: ";
- cin >> noOfPeople;
- Tourist t1(name, id, contactNo, noOfPeople);
- myTourist.push_back(t1);
- cout << endl;
- }
- do
- {
- cout << "--------------------------------------" << endl;
- set <TourPackage, less <TourPackage> > :: iterator p = myTourPackage.begin();
- while (p!= myTourPackage.end())
- {
- cout << *p << endl;
- p++;
- cout << endl;
- }
- cout << "Which package would you like to select?: ";
- cin >> option2;
- }while (option2 < 1 || option2 > myTourPackage.size());
- myTourList.insert(pair<TourPackage,Tourist> (getNthElementFromSet(myTourPackage, option2), myTourist[trNo]));
- cout << "Successfully Registered for tour. " << endl;
- }
- break;
- case 3:
- {
- int maxx = myTourist.size();
- int counter = 0;
- while (counter != maxx)
- {
- myTourist.at(counter).showTourist();
- counter++;
- }
- }
- break;
- case 4:
- {
- set <TourPackage, less <TourPackage> > :: iterator p = myTourPackage.begin();
- while (p!= myTourPackage.end())
- {
- cout << *p << endl;
- p++;
- }
- }
- break;
- case 5:
- {
- }
- break;
- default:
- break;
- }
- }while (option1 != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement