Advertisement
Guest User

123

a guest
Jun 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. using namespace std;
  6.  
  7. class Tourist
  8. {
  9. protected: string name; int id, contactNo, noOfPeople;
  10. public: Tourist(); Tourist(string, int, int, int); void showTourist(); int getID();
  11.  
  12. bool operator < (const Tourist &TA) const
  13. {
  14. return (this->id < TA.id);
  15. }
  16.  
  17. bool operator == (const Tourist &TouristA) const
  18. {
  19. if (this -> name == TouristA.name && this->id == TouristA.id)
  20. return true;
  21. else
  22. return false;
  23. }
  24. };
  25.  
  26. Tourist :: Tourist()
  27. {
  28. name = ""; id = 0; contactNo = 0; noOfPeople = 0;
  29. }
  30.  
  31. Tourist :: Tourist (string a, int b, int c, int d)
  32. {
  33. name = a; id = b; contactNo = c; noOfPeople = d;
  34. }
  35.  
  36. int Tourist :: getID ()
  37. {
  38. return id;
  39. }
  40.  
  41. void Tourist :: showTourist()
  42. {
  43. cout << "Name: " << name << endl;
  44. cout << "ID: " << id << endl;
  45. cout << "Contact No: " << endl;
  46. cout << "No of People: " << noOfPeople << endl;
  47. }
  48.  
  49. class TourPackage
  50. {
  51. friend ostream& operator << (ostream &, const TourPackage&);
  52.  
  53. private: int pid; string pName; double price; string desc, startingDate; int duration;
  54. public: TourPackage(); TourPackage(int, string, double, string, string, int);
  55.  
  56. bool operator < (const TourPackage &TPA) const
  57. {
  58. return (this->pid < TPA.pid);
  59. }
  60.  
  61. bool operator == (const TourPackage &TourPackageA) const
  62. {
  63. return (this->pid == TourPackageA.pid);
  64. }
  65. };
  66.  
  67. ostream& operator << (ostream &out, const TourPackage & tourP)
  68. {
  69. out << "Package ID: " << tourP.pid << "\nPackage Name: " << tourP.pName << "\nPackage Price: " << tourP.price <<
  70. "\nPackage Desc: " << tourP.desc << "\nStarting-Date: " << tourP.startingDate << "\nDuration: " << tourP.duration << endl;
  71.  
  72. return out;
  73. }
  74.  
  75. TourPackage :: TourPackage ()
  76. {
  77. pid = 0; pName = ""; price = 0; desc = ""; startingDate = ""; duration = 0;
  78. }
  79.  
  80. TourPackage :: TourPackage (int a, string b, double c, string d, string e, int f)
  81. {
  82. pid = a; pName = b; price = c; desc = d; startingDate = e; duration = f;
  83. }
  84.  
  85. template <class T>
  86. T getNthElementFromSet(set<T> &searchSet, int SelectedIndex)
  87. {
  88. T a;
  89. int index(0);
  90.  
  91. for (T elem: searchSet)
  92. {
  93. index++;
  94. if(index == SelectedIndex)
  95. {
  96. a=elem;
  97. break;
  98. }
  99. }
  100.  
  101. return a;
  102. }
  103.  
  104. int main ()
  105. {
  106. int option1, option2, trNo;
  107. bool check1;
  108.  
  109. vector <Tourist> myTourist;
  110. string name; int id, contactNo, noOfPeople;
  111.  
  112. set <TourPackage> myTourPackage;
  113. int pid; string pName; double price; string desc, startingDate; int duration;
  114.  
  115. multimap <TourPackage, Tourist> myTourList;
  116.  
  117. do
  118. {
  119. cout << "1. Add a new tour package" << endl;
  120. cout << "2. Register a tourist to a package" << endl;
  121. cout << "3. Show all tourists registered" << endl;
  122. cout << "4. Show all packages available" << endl;
  123. cout << "5. Show the total tourist registered for a particular package and the number of availability" << endl;
  124. cout << "Option: ";
  125. cin >> option1;
  126.  
  127. switch (option1)
  128. {
  129. case 1:
  130. {
  131. cout << "Enter Package ID: ";
  132. cin >> pid;
  133. cout << "Enter Package Name: ";
  134. cin >> pName;
  135. cout << "Enter Package Price: ";
  136. cin >> price;
  137. cout << "Enter Package Description: ";
  138. cin >> desc;
  139. cout << "Enter the Starting-Date: ";
  140. cin >> startingDate;
  141. cout << "Enter the Package Duration: ";
  142. cin >> duration;
  143.  
  144. TourPackage p1(pid, pName, price, desc, startingDate, duration);
  145. myTourPackage.insert(p1);
  146. }
  147. break;
  148.  
  149. case 2:
  150. {
  151. check1 = false;
  152. cout << "Enter Name: ";
  153. cin >> name;
  154. cout << "Enter ID: ";
  155. cin >> id;
  156.  
  157. for (int i = 0; i < myTourist.size(); i++)
  158. {
  159. if (id == myTourist[i].getID())
  160. {
  161. trNo = i;
  162. cout << "ID has been registered before!" << endl;
  163. check1 = true;
  164. break;
  165. }
  166. }
  167.  
  168. if (check1 == false)
  169. {
  170. trNo = myTourist.size();
  171. cout << "Enter Contact No: ";
  172. cin >> contactNo;
  173. cout << "Enter No-of-People: ";
  174. cin >> noOfPeople;
  175. Tourist t1(name, id, contactNo, noOfPeople);
  176. myTourist.push_back(t1);
  177. cout << endl;
  178. }
  179.  
  180. do
  181. {
  182. cout << "--------------------------------------" << endl;
  183.  
  184. set <TourPackage, less <TourPackage> > :: iterator p = myTourPackage.begin();
  185.  
  186. while (p!= myTourPackage.end())
  187. {
  188. cout << *p << endl;
  189. p++;
  190. cout << endl;
  191. }
  192.  
  193. cout << "Which package would you like to select?: ";
  194. cin >> option2;
  195. }while (option2 < 1 || option2 > myTourPackage.size());
  196.  
  197. myTourList.insert(pair<TourPackage,Tourist> (getNthElementFromSet(myTourPackage, option2), myTourist[trNo]));
  198. cout << "Successfully Registered for tour. " << endl;
  199. }
  200.  
  201. break;
  202.  
  203. case 3:
  204. {
  205. int maxx = myTourist.size();
  206. int counter = 0;
  207. while (counter != maxx)
  208. {
  209. myTourist.at(counter).showTourist();
  210. counter++;
  211. }
  212. }
  213.  
  214. break;
  215.  
  216. case 4:
  217. {
  218. set <TourPackage, less <TourPackage> > :: iterator p = myTourPackage.begin();
  219.  
  220. while (p!= myTourPackage.end())
  221. {
  222. cout << *p << endl;
  223. p++;
  224. }
  225. }
  226.  
  227. break;
  228.  
  229. case 5:
  230. {
  231.  
  232. }
  233.  
  234. break;
  235.  
  236. default:
  237.  
  238. break;
  239. }
  240.  
  241. }while (option1 != 0);
  242.  
  243. return 0;
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement