Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. typedef unsigned short int usi;
  6. typedef const unsigned short int cusi;
  7. const int N = 1e2+5;
  8. class Date
  9. {
  10. private :
  11.     usi days, month,year;
  12.     cusi DaysInMonth [13] = {0,31,28,31,30,31,30,31,31,30,31,30,31} ;
  13.  
  14. public:
  15.     usi get_days() const
  16.     {
  17.         return days;
  18.     }
  19.     usi get_month() const
  20.     {
  21.         return month;
  22.     }
  23.     usi get_year() const
  24.     {
  25.         return year;
  26.     }
  27.     Date( usi a = 0, usi b = 0,  usi c = 0)
  28.     {
  29.  
  30.         days = a;
  31.         month = b;
  32.         year = c ;
  33.     }
  34.  
  35.     Date operator+(int nDays) const
  36.     {
  37.         Date tmp = *this;
  38.         int maxnDays = DaysInMonth[tmp.month];
  39.         int newday = tmp.days+nDays;
  40.         int newmonth = tmp.month+(newday/maxnDays);
  41.         tmp.days = (((newday % maxnDays) == 0 ? newday : (newday % maxnDays)));
  42.         tmp.month = (((newmonth % 12) == 0 ? newmonth : (newmonth % 12)));
  43.         tmp.year = (tmp.year+(newmonth/12));
  44.         return tmp;
  45.     }
  46.     Date& operator = (const Date& tmp)
  47.     {
  48.         days = tmp.days;
  49.         month = tmp.month;
  50.         year = tmp.year;
  51.         return *this;
  52.     }
  53.     friend ostream& operator<<(ostream& out, Date& tmp) ;
  54.     friend istream& operator>>(istream& in, Date& tmp);
  55.  
  56. };
  57. ostream& operator<<(ostream& out, Date& tmp)
  58. {
  59.     if (tmp.days <= 9)
  60.         out <<0;
  61.     out << tmp.days << "." ;
  62.     if (tmp.month <= 9)
  63.         out <<0;
  64.     out << tmp.month << ".";
  65.     out << tmp.year;
  66.     return out;
  67. }
  68.  
  69. istream& operator>>(istream& in, Date& tmp)
  70. {
  71.     char dot;
  72.     in >> tmp.days >> dot >> tmp.month >> dot >> tmp.year;
  73.     return in;
  74. }
  75.  
  76.  
  77.  
  78.  
  79. class Board
  80. {
  81.     enum  Type {noMeal = 0, breakfast = 1, halfPension = 2, AllInclusive = 3  };
  82.     Type type;
  83. public:
  84.     Board (char c)
  85.     {
  86.         switch(c)
  87.         {
  88.         case 'a':
  89.             type = AllInclusive;
  90.             break;
  91.         case 'b':
  92.             type = breakfast;
  93.             break;
  94.         case 'h':
  95.             type = halfPension;
  96.             break;
  97.         case 'n':
  98.             type = noMeal;
  99.             break;
  100.         default:
  101.             type= noMeal;
  102.         }
  103.     }
  104.     friend ostream& operator << (ostream & out, Board& tmp) ;
  105.  
  106. };
  107.  
  108. ostream& operator << (ostream & out, Board& tmp)
  109. {
  110.     switch (tmp.type)
  111.     {
  112.     case (Board :: noMeal):
  113.         out << "noMeal";
  114.         break;
  115.     case (Board :: breakfast):
  116.         out << "breakfast";
  117.         break;
  118.     case  (Board :: halfPension):
  119.         out << "halfPension";
  120.         break;
  121.     case (Board :: AllInclusive):
  122.         out << "AllInclusive";
  123.         break;
  124.     default:
  125.         out << "Not an option";
  126.     }
  127.  
  128.     return out;
  129. }
  130. class Hotel
  131. {
  132. public:
  133.     Hotel(string n,int ni,int s, int d, double ps, double pd, bool p, Board* b )
  134.     {
  135.         name = n ;
  136.         nights = ni;
  137.         singles = s;
  138.         doubles = d ;
  139.         priceNightSingle = ps ;
  140.         priceNightDouble = pd ;
  141.         parking = p;
  142.         board = b;
  143.     }
  144.     virtual ~Hotel()
  145.     {
  146.  
  147.     }
  148.  
  149.     string Getname()
  150.     {
  151.         return name;
  152.     }
  153.     void Setname(string val)
  154.     {
  155.         name = val;
  156.     }
  157.     Date Getarrival()
  158.     {
  159.         return arrival;
  160.     }
  161.     void Setarrival(Date val)
  162.     {
  163.         arrival = val;
  164.     }
  165.     int Getnights()
  166.     {
  167.         return nights;
  168.     }
  169.     void Setnights(int val)
  170.     {
  171.         nights = val;
  172.     }
  173.     int Getsingles()
  174.     {
  175.         return singles;
  176.     }
  177.     void Setsingles(int val)
  178.     {
  179.         singles = val;
  180.     }
  181.     int Getdoubles()
  182.     {
  183.         return doubles;
  184.     }
  185.     void Setdoubles(int val)
  186.     {
  187.         doubles = val;
  188.     }
  189.     Board* Getboard()
  190.     {
  191.         return board;
  192.     }
  193.     void Setboard(Board* val)
  194.     {
  195.         board = val;
  196.     }
  197.     double getprice()
  198.     {
  199.         double tp = nights*(priceNightDouble*singles + doubles*priceNightSingle);
  200.         return parking? nights*10 + tp: tp;
  201.     }
  202.     double GetpriceNightSingle()
  203.     {
  204.         return priceNightSingle;
  205.     }
  206.     void SetpriceNightSingle(double val)
  207.     {
  208.         priceNightSingle = val;
  209.     }
  210.     double GetpriceNightDouble()
  211.     {
  212.         return priceNightDouble;
  213.     }
  214.     void SetpriceNightDouble(double val)
  215.     {
  216.         priceNightDouble = val;
  217.     }
  218.     Date getCheckout()
  219.     {
  220.         return (arrival+nights);
  221.     }
  222.  
  223.  
  224. private:
  225.     string name;
  226.     Date arrival;
  227.     int nights;
  228.     int singles;
  229.     int doubles;
  230.     Board* board;
  231.     double priceNightSingle;
  232.     double priceNightDouble;
  233.     bool parking;
  234. };
  235.  
  236. class Transportation
  237. {
  238. public :
  239.     virtual ~Transportation()
  240.     {
  241.         cout << "This is transpotation, yoo" ;
  242.     };
  243.     virtual bool withTransfer() = 0 ;
  244.     virtual double getPrice() = 0 ;
  245.     virtual void  print() = 0 ;
  246. };
  247.  
  248. class SelfOrganised :public Transportation
  249. {
  250. public :
  251.     SelfOrganised()
  252.     {
  253.     }
  254.     virtual ~SelfOrganised()
  255.     {
  256.  
  257.     }
  258.     double getPrice()
  259.     {
  260.         return 0.00;
  261.     }
  262.     bool withTransfer()
  263.     {
  264.         return false ;
  265.     }
  266.     void  print()
  267.     {
  268.         cout << "self organised transport\n";
  269.     }
  270. } ;
  271.  
  272. class PublicTransport : public Transportation
  273. {
  274. protected :
  275.     Date departure;
  276.     string code, from, to ;
  277.     double priceOneSeat;
  278.     bool firstClass;
  279. public:
  280.  
  281.     PublicTransport(Date dep, string cod, string frm, string t, double pos, bool fc = 0)
  282.     {
  283.         departure = dep  ;
  284.         code = cod  ;
  285.         from = frm ;
  286.         to = t ;
  287.         priceOneSeat = pos ;
  288.         firstClass = fc  ;
  289.     }
  290.     virtual ~PublicTransport()
  291.     {
  292.         cout << "Public transport deleted";
  293.     };
  294.  
  295.  
  296. };
  297.  
  298. class Train  : public PublicTransport
  299. {
  300. public:
  301.     Train(Date d, string co, string fr, string t, double p, bool fc = 0 ) : PublicTransport(d,co,fr,t,p,fc)
  302.     {
  303.  
  304.     }
  305.     double getPrice()
  306.     {
  307.         return priceOneSeat;
  308.     }
  309.     virtual ~Train()
  310.     {
  311.         cout << "Train is deleted successfully\n";
  312.     }
  313.     bool withTransfer()
  314.     {
  315.         return 0;
  316.     }
  317.     void print()
  318.     {
  319.         cout << "main train station of departure: " << from << endl << "main train station of arrival: " << to <<endl << "price for one passenger: " <<fixed << setprecision(5) << priceOneSeat <<endl;
  320.     }
  321.  
  322. };
  323.  
  324. class Flight : public PublicTransport
  325. {
  326. private :
  327.  
  328.     bool transfer ;
  329.  
  330. public :
  331.     Flight(Date d, string co, string fr, string t, double p, bool fc = 0, bool tr  = 1 ) : PublicTransport(d,co,fr,t,p,fc)
  332.     {
  333.         transfer = tr;
  334.     }
  335.     virtual ~ Flight()
  336.     {
  337.         cout << "flight is deleted\n" ;
  338.     }
  339.     bool withTransfer()
  340.     {
  341.         return transfer ;
  342.     }
  343.     double getPrice()
  344.     {
  345.         return ((firstClass)? priceOneSeat*2 : priceOneSeat);
  346.     }
  347.     void print ()
  348.     {
  349.         cout << "Airport of departure: " << from << endl << "Airport of arrival: " << to <<endl << "price for one passenger: " <<fixed << setprecision(5) << ((firstClass)? priceOneSeat*2 : priceOneSeat) <<endl;
  350.  
  351.     }
  352. };
  353. class Trip
  354. {
  355. public:
  356.  
  357.     Trip( int n, Hotel* h, Transportation* b, Transportation* o  )
  358.     {
  359.         travellers = n;
  360.         hotel = h;
  361.         transportBack = b;
  362.         transportout = o;
  363.     }
  364.     virtual ~Trip()
  365.     {
  366.  
  367.     }
  368.  
  369.     const unsigned int Getno()
  370.     {
  371.         return no;
  372.     }
  373.     const unsigned int GetlastNo()
  374.     {
  375.         return lastNo;
  376.     }
  377.     void SetlastNo(const unsigned int val)
  378.     {
  379.         lastNo = val;
  380.     }
  381.     unsigned int Gettravellers()
  382.     {
  383.         return travellers;
  384.     }
  385.     void Settravellers(unsigned int val)
  386.     {
  387.         travellers = val;
  388.     }
  389.     Hotel Gethotel()
  390.     {
  391.         return *hotel;
  392.     }
  393.     void Sethotel(Hotel val)
  394.     {
  395.         *hotel = val;
  396.     }
  397.  
  398.     double get_price ()
  399.     {
  400.         cout << "Total price of the journey : \n";
  401.         return (hotel->getprice()+transportBack->getPrice()+transportout->getPrice());
  402.     }
  403.     void print ()
  404.     {
  405.         Date tmp = hotel->Getarrival();
  406.         Date checkout = hotel->getCheckout();
  407.         bool transfer = (transportBack->withTransfer());
  408.         Board* ty = hotel->Getboard();
  409.         cout << "trip inquiry   " << no<<  "    for " << (2*(hotel->Getdoubles()) +hotel->Getsingles()) << "  person(s)\n";
  410.         cout << "check in :    " << tmp<< "  Hotel: " << hotel->Getname() << "  for   " << hotel->Getnights() << " Nights  checkout:    " <<checkout<<endl<<hotel->Getsingles() << " Single room(s)  \n" << hotel->Getdoubles() << " double room(s)\n";
  411.         cout << *ty << endl;
  412.         cout << "outward journey : " ;
  413.         transportout->print();
  414.         cout << "backward journey : " ;
  415.         transportBack->print() ;
  416.         cout << (transfer? "With Transfer":"Without Transfer") << endl << "" << get_price() << "Euro";
  417.     }
  418.  
  419. private:
  420.     const unsigned int no = ++lastNo;
  421.     static unsigned int lastNo;
  422.     unsigned int travellers;
  423.     Hotel *hotel;
  424.     Transportation* transportout ;
  425.     Transportation* transportBack;
  426. };
  427.  
  428. unsigned int Trip:: lastNo = 0;
  429. class TravelAgency
  430. {
  431. private :
  432.     Trip* trips[N] {} ;
  433.     int ct;
  434. public :
  435.     TravelAgency()
  436.     {
  437.         ct = 0;
  438.     }
  439.     void add(Trip* t)
  440.     {
  441.         trips[ct] = t;
  442.         ct++;
  443.     }
  444.     void remove(Trip* t)
  445.     {
  446.         int idx = -1 ;
  447.         for (int i = 0 ; i<ct ; ++i)
  448.         {
  449.             if (trips[i]->Getno() == t->Getno())
  450.             {
  451.                 idx = i;
  452.                 break;
  453.             }
  454.         }
  455.         if (idx == -1)
  456.             return;
  457.         delete trips[idx];
  458.         for (int i = idx ; i<ct ; ++i)
  459.         {
  460.             trips[i] = trips[i+1];
  461.         }
  462.         ct--;
  463.     }
  464.     Trip* search(unsigned int n)
  465.     {
  466.         for (int i = 0 ; i<ct ; ++i)
  467.         {
  468.             if (trips[i]->Getno() == n)
  469.                 return trips[i];
  470.         }
  471.         return 0;
  472.     }
  473.     void print()
  474.     {
  475.         for (int i = 0 ; i<ct ; ++i)
  476.         {
  477.             cout << "Trip number " << i+1 << ": \n";
  478.             trips[i]->print();
  479.             cout << "\n\n";
  480.         }
  481.     }
  482. };
  483.  
  484. Hotel* ReadHotel()
  485. {
  486.     string name;
  487.     Date date;
  488.     int singles;
  489.     int doubles;
  490.     double ps;
  491.     double pd;
  492.     int nights;
  493.     bool parking = 0;
  494.     char ty,park;
  495.     cout << "name of hotel: ";
  496.     cin >> name ;
  497.     cout << "\narrival on: ";
  498.     cin >>date;
  499.     cout << "\nhow many nights: ";
  500.     cin >> nights;
  501.     cout << "\nhow many single bed rooms: ";
  502.     cin >> singles;
  503.     cout << "\nhow many double bed rooms: ";
  504.     cin >> doubles;
  505.     cout << "\na all inclusive\n" << "b breakfast\n" << "h half board\n" << "w without meals\n" ;
  506.     cin >> ty;
  507.     cout << "price one night in single bed room: " ;
  508.     cin >> ps;
  509.     cout << "\nPrice one night in double bed room: " ;
  510.     cin >> pd ;
  511.     cout << "\nwith parking (y(es) or n(o)): " ;
  512.     cin >> park ;
  513.     if (park =='y')
  514.         parking = 1;
  515.     Board* type = new Board(ty);
  516.     Hotel* ret = new Hotel(name,nights,singles,doubles,ps,pd,parking,type);
  517.     ret->Setarrival(date);
  518.     return (ret);
  519. }
  520. Train* ReadTrain()
  521. {
  522.     Date dt;
  523.     string cod;
  524.     string frm;
  525.     string to;
  526.     double price;
  527.     bool fc = 0;
  528.     cout<< " code of Train: ";
  529.     cin >> cod;
  530.     cout << "\nstation of departure: ";
  531.     cin >>frm;
  532.     cout << "\nstation of arrival: ";
  533.     cin >> to;
  534.     cout << "\nprice for one passenger: ";
  535.     cin >> price ;
  536.     cout << "\nFirst class?? (1-> yes , 0-> no)";
  537.     cin >> fc;
  538.     if (fc == 1)
  539.     {
  540.         cout << "The seat is first class\n";
  541.     }
  542.     else
  543.     {
  544.         cout << "Not first class\n";
  545.     }
  546.  
  547.     Train* t = new Train(dt,cod,frm,to,price,fc);
  548.     return t ;
  549. }
  550. Flight* ReadFlight()
  551. {
  552.     Date dt;
  553.     string cod;
  554.     string frm;
  555.     string to;
  556.     double price;
  557.     bool fc = 0;
  558.     bool transfer = 1;
  559.     cout<< " code of flight: ";
  560.     cin >> cod;
  561.     cout << "\nairport of departure: ";
  562.     cin >>frm;
  563.     cout << "\nairport of arrival: ";
  564.     cin >> to;
  565.     cout << "\nprice for one passenger: ";
  566.     cin >> price ;
  567.     cout << "\nFirst class? (1-> yes , 0-> no)";
  568.     cin >> fc;
  569.     if (fc == 1)
  570.     {
  571.         cout << "The seat is first class\n";
  572.     }
  573.     else
  574.     {
  575.         cout << "Not first class\n";
  576.     }
  577.     cout << "\n with or without transfer? (1-> yes , 0-> no)";
  578.     cin >> transfer;
  579.     if (transfer == 0)
  580.     {
  581.         cout << "there is no transfer\n";
  582.     }
  583.     else
  584.     {
  585.         cout << "With transfer";
  586.     }
  587.     Flight* f = new Flight(dt,cod,frm,to,price,fc,transfer);
  588.     return f;
  589. }
  590. int main()
  591. {
  592.     int mainchoice ;
  593.     TravelAgency* TA = new TravelAgency();
  594.     while(true)
  595.     {
  596.         cout << "\n\nHOTLINE TRAVEL AGENCY\n\n0 end\n1 new trip\n2 search trip\n3 show all trip offers\n";
  597.         cin >> mainchoice;
  598.         switch (mainchoice)
  599.         {
  600.         case (0) :
  601.         {
  602.             return 0 ;
  603.             break;
  604.         }
  605.         case (1) :
  606.         {
  607.             Hotel* hotel = ReadHotel();
  608.             int choice = 0;
  609.             Transportation* backward;
  610.             Transportation* outward;
  611.             cout << "please choose transport for outward journey \n0 self organised \n1 by flight\n2 by train\n";
  612.             cin >> choice;
  613.             switch (choice)
  614.             {
  615.             case (0) :
  616.                 outward = new SelfOrganised();
  617.                 break;
  618.             case (1) :
  619.                 outward = ReadFlight();
  620.                 break;
  621.             case (2) :
  622.                 outward= ReadTrain();
  623.                 break;
  624.             default:
  625.                 return 0;
  626.             }
  627.             cout << "please choose transport for journey back \n0 self organised \n1 by flight\n2 by train\n";
  628.             cin >> choice;
  629.             switch (choice)
  630.             {
  631.             case (0) :
  632.                 backward = new SelfOrganised();
  633.                 break;
  634.             case (1) :
  635.                 backward = ReadFlight();
  636.                 break;
  637.             case (2) :
  638.                 backward = ReadTrain();
  639.                 break;
  640.             default:
  641.                 return 0;
  642.             }
  643.             Trip* newtrip = new Trip((hotel->Getsingles()+2*hotel->Getdoubles()),hotel,backward,outward);
  644.             TA->add(newtrip);
  645.             break;
  646.         }
  647.         case (2) :
  648.         {
  649.             int tripnumber;
  650.             cin >> tripnumber;
  651.             Trip* search_trip = TA->search(tripnumber);
  652.             if (search_trip==0)
  653.                 cout << "trip not found\n";
  654.             else
  655.             {
  656.                 char c;
  657.                 search_trip->print();
  658.                 cout <<"\n";
  659.                 cout << "(d)elete or (n)ot";
  660.                 cin >> c;
  661.                 if (c == 'd')
  662.                     TA->remove(search_trip);
  663.             }
  664.             break;
  665.         }
  666.         case (3) :
  667.             TA->print();
  668.             break;
  669.         default:
  670.             return 0;
  671.  
  672.         }
  673.     }
  674.     return 0;
  675. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement