Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. #include <string>
  5. #include <vector>
  6.  
  7. class CreditAccount
  8. {
  9. private:
  10.     int m_credits = 0;
  11. public:
  12.     void buy(int t_credits)
  13.     {
  14.         m_credits -= t_credits;
  15.         m_credits = m_credits > 0 ? m_credits : 0;
  16.     }
  17.  
  18.     void put_credits(int t_credits)
  19.     {
  20.         m_credits += t_credits;
  21.     }
  22.     void put_bools(int t_bools)
  23.     {
  24.         m_credits += t_bools * 3;
  25.     }
  26.     void put_stars(int t_stars)
  27.     {
  28.         m_credits += t_stars * 2 / 5;
  29.     }
  30.     std::string status()
  31.     {
  32.         return "Account: " + std::to_string(m_credits) + " credits";
  33.     }
  34. };
  35.  
  36. class SpacePoint
  37. {
  38. private:
  39.     int X, Y;
  40. public:
  41.     SpacePoint()
  42.         :X(0), Y(0) {}
  43.     SpacePoint(int t_X, int t_Y)
  44.         :X(t_X), Y(t_Y) {}
  45.     void read()
  46.     {
  47.         std::cin >> X >> Y;
  48.     }
  49.     int distance(const SpacePoint other)
  50.     {
  51.         return sqrt(pow(X - other.X, 2) + pow(Y - other.Y, 2));
  52.     }
  53.     int get_x() { return X; }
  54.     int get_y() { return Y; }
  55. };
  56.  
  57. class SpaceShip
  58. {
  59. private:
  60.     std::string name;
  61.  
  62.     int fuelLeft;
  63.     int fuelMax;
  64.     SpacePoint position;
  65.     CreditAccount m_credits;
  66. public:
  67.     CreditAccount& get_credits() { return m_credits; }
  68.     void status()
  69.     {
  70.         std::cout << "STATUS: " << name
  71.                   << "\nCordinates: x=" << position.get_x() << " y=" << position.get_y()
  72.                   << "\nFuel: " << fuelLeft << " from " << fuelMax
  73.                   << "\n" << m_credits.status() << "\n";
  74.     }
  75.  
  76.     void flight(SpacePoint p)
  77.     {
  78.         fuelLeft -= position.distance(p);
  79.         if (fuelLeft < 0) fuelLeft = 0;
  80.  
  81.         position = p;
  82.     }
  83.  
  84.     void prepare()
  85.     {
  86.         std::cin >> name >> fuelLeft >> fuelMax;
  87.  
  88.         position.read();
  89.         int credits;
  90.         std::cin >> credits;
  91.         m_credits.put_credits(credits);
  92.     }
  93. };
  94.  
  95. int main()
  96. {
  97.     SpaceShip ship;
  98.     ship.prepare();
  99.  
  100.     int actions;
  101.     std::cin >> actions;
  102.  
  103.     for (int i = 0; i < actions; i++)
  104.     {
  105.         std::string action;
  106.         std::cin >> action;
  107.  
  108.         if (action == "flight")
  109.         {
  110.             int X, Y;
  111.             std::cin >> X >> Y;
  112.             ship.flight(SpacePoint(X, Y));
  113.         }
  114.         else if (action == "cache")
  115.         {
  116.             int cost;
  117.             std::string currency;
  118.             std::cin >> cost >> currency;
  119.  
  120.             if (currency == "credits")
  121.                 ship.get_credits().put_credits(cost);
  122.             else if (currency == "bools")
  123.                 ship.get_credits().put_bools(cost);
  124.             else if (currency == "stars")
  125.                 ship.get_credits().put_stars(cost);
  126.         }
  127.         else if (action == "status")
  128.         {
  129.             ship.status();
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement