Advertisement
Guest User

Untitled

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