Guest User

Untitled

a guest
Jul 19th, 2018
1,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.21 KB | None | 0 0
  1. ##Travel.h
  2. #ifndef TRAVEL_H
  3. #define TRAVEL_H
  4.  
  5. #include<iostream>
  6. #include<string>
  7. #include<stdlib.h>
  8. using namespace std;
  9. const int size=10;
  10.  
  11. class Travel
  12. {
  13. private:
  14. string name;//basic information
  15. double payment, amount_owe;
  16. int booking_select;//select current booking so that user can edit or delete
  17. int added;//added count for booking data;
  18.  
  19. protected:
  20. string book_type[size], provider[size], departure_D[size], departure_T[size], arrival_D[size], arrival_T[size],
  21. departure_L[size], dest[size], aircraft[size];
  22. double price[size];
  23. int seat[size], deck[size], room_no[size], floor[size], length[size], site[size];
  24. char first_class[size], breakfast[size], electric[size], water[size];
  25.  
  26. public:
  27.  
  28. Travel(){added=0; payment=0;}//Constructor
  29.  
  30. //Get and set all of the main data members of the booking sytem
  31. string get_provider(int a){return(provider[a]);}
  32. void set_provider(string a){provider[added]=a;}
  33. string get_departure_D(int a){return(departure_D[a]);}
  34. void set_departure_D(string a){departure_D[added]=a;}
  35. string get_departure_T(int a){return(departure_T[a]);}
  36. void set_departure_T(string a){departure_T[added]=a;}
  37. string get_arrival_D(int a){return(arrival_D[a]);}
  38. void set_arrival_D(string a){arrival_D[added]=a;}
  39. string get_arrival_T(int a){return(arrival_T[a]);}
  40. void set_arrival_T(string a){arrival_T[added]=a;}
  41. string get_departure_L(int a){return(departure_L[a]);}
  42. void set_departure_L(string a){departure_L[added]=a;}
  43. string get_dest(int a){return(dest[a]);}
  44. void set_dest(string a){dest[added]=a;}
  45. string get_aircraft(int a){return(aircraft[a]);}
  46. void set_aircraft(string a){aircraft[added]=a;}
  47. double get_price(int a){return(price[a]);}
  48. void set_price(double a){price[added]=a;}
  49. int get_seat(int a){return(seat[a]);}
  50. void set_seat(int a){seat[added]=a;}
  51. int get_deck(int a){return(deck[a]);}
  52. void set_deck(int a){deck[added]=a;}
  53. int get_room_no(int a){return(room_no[a]);}
  54. void set_room_no(int a){room_no[added]=a;}
  55. int get_floor(int a){return(floor[a]);}
  56. void set_foor(int a){floor[added]=a;}
  57. int get_length(int a){return(length[a]);}
  58. void set_length(int a){length[added]=a;}
  59. int get_site(int a){return(site[a]);}
  60. void set_site(int a){site[added]=a;}
  61. char get_first_class(int a){return(first_class[a]);}
  62. void set_first_class(char a){first_class[added]=a;}
  63. char get_breakfast(int a){return(breakfast[a]);}
  64. void set_breakfast(char a){breakfast[added]=a;}
  65. char get_electric(int a){return(electric[a]);}
  66. void set_electric(char a){electric[added]=a;}
  67. char get_water(int a){return(water[a]);}
  68. void set_water(char a){water[added]=a;}
  69.  
  70. //Selection 4
  71. //Record Payment
  72. double total_cal();
  73.  
  74. double get_amount_owe();
  75.  
  76. void set_payment(double a){payment+=a;}
  77.  
  78. //Selection 5.
  79. //Invoice
  80. void display_invoice();
  81.  
  82. void data_added(){added++;} // when data is added to the booking system. this counter increments.
  83. virtual void add(){}
  84. void setname(string a){name=a;}
  85. string getname(){return(name);}
  86. virtual void book()=0;//Polymorphism for the booking types. Airline, Cruises, Hotel and camp
  87.  
  88. //Selection 6
  89. //Display and sets the booking the suer wants to change
  90. void display_booking()
  91.  
  92. //Selection 7
  93. //Cancel Booking
  94. void cancel_booking();
  95.  
  96. void display_cancel_booking(){cout<<departure_D[booking_select]<<" "<<provider[booking_select]<<endl;}
  97.  
  98. void set_booking_select(int x){booking_select=x;}
  99. int get_booking_select(){return(booking_select);}
  100. };
  101. #endif TRAVEL_H
  102.  
  103. ##Travel.cpp
  104. #include "Travel.h"
  105.  
  106. //Selection 4.
  107. //Record Payment
  108. double Travel::total_cal()
  109. {
  110. int i;
  111. double total=0;
  112. for(i=1; i<=added; i++)
  113. total+=price[i];
  114. return(total);
  115. }
  116.  
  117. double Travel::get_amount_owe()
  118. {
  119. int i; amount_owe=0;
  120. for(i=1;i<=added;i++)
  121. {
  122. amount_owe=amount_owe+price[i];
  123. }
  124. amount_owe=amount_owe-payment;
  125. return(amount_owe);
  126. }
  127.  
  128. //Selection 5.
  129. //Invoice
  130. void Travel::display_invoice()
  131. {
  132. cout<<"invoice for "<<name<<endl;
  133. cout<<"address"<<endl;
  134. cout<<"city"<<endl;
  135. cout<<"state"<<" "<<"zip code"<<endl;
  136. int i; for(i=1;i<=added;i++)
  137. {
  138. cout<<departure_D[i]<<" "<<provider[i]<<" "<<price[i]<<endl;
  139. }
  140. cout<<"Total :"<<total_cal()<<endl;
  141. cout<<"payments recived "<<" "<<payment<<endl;
  142. cout<<"amount due: "<<amount_owe<<endl;
  143. }
  144.  
  145. //Selection 6.
  146. //Display and sets the booking the user wants to change
  147. void Travel::display_booking()
  148. {
  149. int i;
  150. for(i=1; i<=added; i++)
  151. {
  152. cout<<i<<". "<<departure_D[i]<<" "<<provider[i]<<endl;
  153. }
  154. }
  155.  
  156. //selection 7.
  157. //Cancel Booking
  158. void Travel::cancel_booking()
  159. {
  160. if(booking_select<added){
  161. provider[booking_select]=provider[added];
  162. departure_D[booking_select]=departure_D[added];
  163. departure_T[booking_select]=departure_T[added];
  164. arrival_D[booking_select]=arrival_D[added];
  165. arrival_T[booking_select]=arrival_T[added];
  166. dest[booking_select]=dest[added];
  167. aircraft[booking_select]=aircraft[added];
  168. price[booking_select]=price[added];
  169. seat[booking_select]=seat[added];
  170. deck[booking_select]=deck[added];
  171. room_no[booking_select]=room_no[added];
  172. site[booking_select]=site[added];
  173. first_class[booking_select]=first_class[added];
  174. breakfast[booking_select]=breakfast[added];
  175. electric[booking_select]=electric[added];
  176. added--;}
  177. else
  178. added--;
  179. }
  180. ##project1.h
  181. #ifndef proejct1
  182. #define proejct1
  183.  
  184. #include "Travel.cpp"
  185.  
  186. class Customer : public Travel{
  187.  
  188. public:
  189. Customer(): Travel(){}//default constructor
  190. void book(){}
  191. void add()
  192. {
  193. string a;
  194. cout<<"Add a name"<<endl;
  195. cin>>a;
  196. setname(a);}};
  197.  
  198. class Airline: public Travel{
  199. public:
  200. Airline():Travel(){}
  201. void book()
  202. {
  203. cout<<"Please enter the detail of the flight"<<endl;
  204. cout<<"Provider: "; cin>>provider[1];
  205. cout<<"Price: "; cin>>price[1];
  206. cout<<"Departure Date: "; cin>>departure_D[1];
  207. /*cout<<"Departure time: "; cin>>departure_T[1];
  208. cout<<"Arrival Date: "; cin>>arrival_D[1];
  209. cout<<"Arrival Time: "; cin>>arrival_T[1]; ;
  210. cout<<"Departure Location: "; cin>>departure_L[1];
  211. cout<<"First class (y/n?): "; cin>>dest[1];
  212. cout<<"Flight number:"; cin>>first_class[1];
  213. cout<<"Seat: "; cin>>seat[1];
  214. cout<<"Aircraft type: "; cin>>aircraft[1];*/
  215. }
  216. };
  217. class Cruise: public Travel{
  218. public:
  219. Cruise():Travel(){}//default constructor
  220. virtual void book()
  221. {
  222. cout<<"Please enter the detail of the Cruise"<<endl;
  223. cout<<"Provider: "; cin>>provider[1];
  224. cout<<"Price: "; cin>>price[1];
  225. cout<<"Departure Date: "; cin>>departure_D[1];
  226. /*cout<<"Departure time: "; cin>>departure_T[1];
  227. cout<<"Arrival Date: "; cin>>arrival_D[1];
  228. cout<<"Arrival Time: "; cin>>arrival_T[1]; ;
  229. cout<<"Departure Location: "; cin>>departure_L[1];
  230. cout<<"Destination:"; cin>>dest[1];
  231. cout<<"First class (y/n?): "; cin>>first_class[1];
  232. cout<<"Flight number:"; cin>>first_class[1];
  233. cout<<"Deck: "; cin>>deck[1];
  234. cout<<"Room #: "; cin>>room_no[1];*/
  235. }};
  236.  
  237. class Hotel: public Travel{
  238. public:
  239. Hotel(): Travel(){}//default constructor
  240. void book()
  241. {
  242. cout<<"Please enter the detail of the flight"<<endl;
  243. cout<<"Provider: "; cin>>provider[1];
  244. cout<<"Price: "; cin>>price[1];
  245. cout<<"Arrival Date: "; cin>>arrival_D[1];
  246. cout<<"Length of stay: "; cin>>length[1];
  247. cout<<"Room#: "; cin>>room_no[1];
  248. cout<<"Floor:"; cin>>floor[1];
  249. cout<<"Is breakfast included (y/n)?: "; cin>>breakfast[1];
  250. }};
  251.  
  252. class Camp: public Travel{
  253. public:
  254. Camp():Travel(){}//default constructor
  255. void book()
  256. {
  257.  
  258. cout<<"Please enter the detail of the camp"<<endl;
  259. cout<<"Provider: "; cin>>provider[1];
  260. cout<<"Price: "; cin>>price[1];
  261. cout<<"Arrival Date: "; cin>>arrival_D[1];
  262. cout<<"Length of stay: "; cin>>length[1];
  263. cout<<"Site: "; cin>>site[1];
  264. cout<<"Is electricity provided(y/n)?"; cin>>electric[1];
  265. cout<<"Is water provided(y/n)?: "; cin>>water[1];
  266. }};
  267.  
  268. #endif project1
  269. ##main.cpp
  270. #include "project1.h"
  271. #include "Travel.h"
  272.  
  273. void transfer(Travel *p[], Travel *b, int current){
  274. p[current]->data_added();
  275. p[current]->set_provider(b->get_provider(1));
  276. p[current]->set_departure_D(b->get_departure_D(1));
  277. p[current]->set_departure_T(b->get_departure_T(1));
  278. p[current]->set_arrival_D(b->get_arrival_D(1));
  279. p[current]->set_arrival_T(b->get_arrival_T(1));
  280. p[current]->set_dest(b->get_dest(1));
  281. p[current]->set_aircraft(b->get_aircraft(1));
  282. p[current]->set_price(b->get_price(1));
  283. p[current]->set_seat(b->get_seat(1));
  284. p[current]->set_deck(b->get_deck(1));
  285. p[current]->set_room_no(b->get_room_no(1));
  286. p[current]->set_site(b->get_site(1));
  287. p[current]->set_first_class(b->get_first_class(1));
  288. p[current]->set_breakfast(b->get_breakfast(1));
  289. p[current]->set_electric(b->get_electric(1));
  290. p[current]->set_water(b->get_water(1));}
  291.  
  292. int main()
  293. {
  294. Travel *p[size];// All of p dynamically create objects of Customers
  295. Travel *b; //Pointer b will only access the classes of bookings such as Airline and Crusies through polymorphism
  296. int i;
  297. int select=0;//selection for the menu.
  298. int current=0;//current customer. Null lets the program know program has not selected a costumer
  299. int added=0;// adding customers count. Null means Customer list is empty;
  300. do{// user friendly interface
  301. system("CLS");
  302. cout<<" 1. add a new customer"<<endl;
  303. cout<<" 2. Select a customer"<<endl;
  304. cout<<" 3. add a booking"<<endl;
  305. cout<<" 4. Record a payment"<<endl;
  306. cout<<" 5. Print an invoice"<<endl;
  307. cout<<" 6. Select a book"<<endl;
  308. cout<<" 7. Cancel booking"<<endl;
  309. cout<<" 8. quit"<<endl;
  310. cout<<"select..."<<endl;
  311. cin>>select;
  312. system("CLS");
  313. switch(select){
  314. case 1:{
  315. added++;
  316. p[added]=new Customer;
  317. p[added]->add();
  318. }break;
  319. case 2:{
  320. if(added!=0){
  321. for(i=1;i<=added;i++)
  322. cout<<i<<". "<<p[i]->getname()<<endl;
  323. cout<<"select a costomer."<<endl<<endl;
  324. cin>>current;
  325. cout<<" you have selected "<<p[current]->getname()<<endl;
  326. system("CLS");
  327. }
  328. else
  329. cout<<"There are no Costomers. Please go back to the main menu and add one"<<endl;
  330. }break;
  331. case 3:{
  332. if (current!=0)
  333. {
  334. cout<<"1. Airline"<<endl<<"2. Cruise"<<endl<<"3. Hotel"<<endl<<"4. Camp"<<endl<<"Select book type."<<endl;
  335. cin>>select;
  336. switch(select){
  337. case 1:{
  338. b=new Airline;
  339. b->book();
  340. transfer(p, b, current);
  341. }break;
  342. case 2: {
  343. b=new Cruise;
  344. b->book();
  345. transfer(p, b, current);
  346. }break;
  347. case 3: {
  348. b=new Hotel;
  349. b->book();
  350. transfer(p, b, current);
  351. }break;
  352. case 4:{
  353. b=new Camp;
  354. b->book();
  355. transfer(p, b, current);
  356. }break;
  357. default: cout<<"you have no selected anything. Going back to the menu."<<endl;
  358. }}
  359. else
  360. cout<<" Error! You have no selected a Customer. Go back to menu."<<endl;
  361. }break;
  362. case 4:{if(current!=0){
  363. double x;
  364. cout<<"Record of payment for "<< p[current]->getname()<<endl
  365. <<"Amount owing: "<<p[current]->get_amount_owe()<<endl<<endl
  366. <<"Enter payment amount: ";
  367. cin>>x;
  368. p[current]->set_payment(x);
  369. cout<<" Now owes : "<<p[current]->get_amount_owe()<<endl;}
  370. else
  371. cout<<" Error! Please go back to the menu and select a costumer"<<endl;
  372. }break;
  373. case 5:p[current]->display_invoice();break;
  374. case 6:{
  375. int x;
  376. p[current]->display_booking();
  377. cout<<"Select a booking #"<<endl;
  378. cin>>x;
  379. p[current]->set_booking_select(x);
  380. }break;
  381. case 7:{
  382. cout<<"Cancel booking for "<<p[current]->getname()<<endl;
  383. p[current]->display_cancel_booking();
  384. cout<<"Please confirm: [y/n]"<<endl;
  385. char y_n;
  386. cin>>y_n;
  387. if(y_n=='y')
  388. p[current]->cancel_booking();
  389. }break;
  390. default: select=8; break;
  391. }
  392. }while(select!=8);
  393. delete b;
  394. //delete [] p;
  395.  
  396. return(0);
  397. }
  398.  
  399. ##Errors
  400. 1>------ Build started: Project: Project_1, Configuration: Debug Win32 ------
  401. 1>Compiling...
  402. 1>main.cpp
  403. 1>Travel.cpp
  404. 1>Generating Code...
  405. 1>Compiling manifest to resources...
  406. 1>Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
  407. 1>Copyright (C) Microsoft Corporation. All rights reserved.
  408. 1>Linking...
  409. 1>Travel.obj : error LNK2005: "public: double __thiscall Travel::total_cal(void)" (?total_cal@Travel@@QAENXZ) already defined in main.obj
  410. 1>Travel.obj : error LNK2005: "public: double __thiscall Travel::get_amount_owe(void)" (?get_amount_owe@Travel@@QAENXZ) already defined in main.obj
  411. 1>Travel.obj : error LNK2005: "public: void __thiscall Travel::display_invoice(void)" (?display_invoice@Travel@@QAEXXZ) already defined in main.obj
  412. 1>Travel.obj : error LNK2005: "public: void __thiscall Travel::display_booking(void)" (?display_booking@Travel@@QAEXXZ) already defined in main.obj
  413. 1>Travel.obj : error LNK2005: "public: void __thiscall Travel::cancel_booking(void)" (?cancel_booking@Travel@@QAEXXZ) already defined in main.obj
  414. 1>C:\Documents and Settings\Ezro\My Documents\My Dropbox\Public\CSC330\Project_1\Debug\Project_1.exe : fatal error LNK1169: one or more multiply defined symbols found
  415. 1>Build log was saved at "file://c:\Documents and Settings\Ezro\My Documents\My Dropbox\Public\CSC330\Project_1\Project_1\Debug\BuildLog.htm"
  416. 1>Project_1 - 6 error(s), 0 warning(s)
  417. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Add Comment
Please, Sign In to add comment