Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. class CreditAccount
  2. {
  3. private:
  4.  
  5. public:
  6.     int credits = 0;
  7.     double bools_rate = 0;
  8.     double stars_rate = 0;
  9.     double borks_rate = 0;
  10. public:
  11.     void prepare() { std::cin >> credits >> stars_rate >> bools_rate >> borks_rate; }
  12.  
  13.     void buy(int t_credits) { credits -= t_credits; } // m_credits = m_credits > 0 ? m_credits : 0;
  14.  
  15.     void putCredits(int t_credits) { credits += t_credits; }
  16.     void putProtorianBools(int t_bools) { credits += t_bools * bools_rate; }
  17.     void putOrionStars(int t_stars) { credits += t_stars * stars_rate; }
  18.     void putOmegaSectorBorks(int t_borks) { credits += t_borks * borks_rate; }
  19.  
  20.     std::string printStatus() { return "Account: " + std::to_string(credits) + " credits"; }
  21. };
  22.  
  23. class SpacePoint
  24. {
  25. private:
  26.     int X, Y;
  27. public:
  28.     SpacePoint()
  29.         :X(0), Y(0) {}
  30.     SpacePoint(int t_X, int t_Y)
  31.         :X(t_X), Y(t_Y) {}
  32.     void read() { std::cin >> X >> Y; }
  33.     int distance(const SpacePoint other) { return sqrt(pow(X - other.X, 2) + pow(Y - other.Y, 2)); }
  34.     int get_x() { return X; }
  35.     int get_y() { return Y; }
  36. };
  37.  
  38. class SpaceShip
  39. {
  40. private:
  41.     std::string name;
  42.  
  43.     int fuelLeft;
  44.     int fuelMax;
  45.     SpacePoint position;
  46.  
  47. public:
  48.     CreditAccount account;
  49.     CreditAccount& get_credits() { return account; }
  50.     void printStatus()
  51.     {
  52.         std::cout << "STATUS: " << name
  53.             << "\nCordinates: x=" << position.get_x() << " y=" << position.get_y()
  54.             << "\nFuel: " << fuelLeft << " from " << fuelMax
  55.             << "\n" << account.printStatus() << "\n";
  56.     }
  57.  
  58.     void flight(SpacePoint p)
  59.     {
  60.         fuelLeft -= position.distance(p);
  61.         if (fuelLeft < 0) fuelLeft = 0;
  62.  
  63.         position = p;
  64.     }
  65.  
  66.     void prepare()
  67.     {
  68.         std::cin >> name >> fuelLeft >> fuelMax;
  69.         position.read();
  70.         account.prepare();
  71.     }
  72. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement