Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <vector>
- class CreditAccount
- {
- private:
- int m_credits = 0;
- public:
- void buy(int t_credits)
- {
- m_credits -= t_credits;
- m_credits = m_credits > 0 ? m_credits : 0;
- }
- void put_credits(int t_credits)
- {
- m_credits += t_credits;
- }
- void put_bools(int t_bools)
- {
- m_credits += t_bools * 3;
- }
- void put_stars(int t_stars)
- {
- m_credits += t_stars * 2 / 5;
- }
- std::string status()
- {
- return "Account: " + std::to_string(m_credits) + " credits";
- }
- };
- class SpacePoint
- {
- private:
- int X, Y;
- public:
- SpacePoint()
- :X(0), Y(0) {}
- SpacePoint(int t_X, int t_Y)
- :X(t_X), Y(t_Y) {}
- void read()
- {
- std::cin >> X >> Y;
- }
- int distance(const SpacePoint other)
- {
- return sqrt(pow(X - other.X, 2) + pow(Y - other.Y, 2));
- }
- int get_x() { return X; }
- int get_y() { return Y; }
- };
- class SpaceShip
- {
- private:
- std::string name;
- int fuelLeft;
- int fuelMax;
- SpacePoint position;
- CreditAccount m_credits;
- public:
- CreditAccount& get_credits() { return m_credits; }
- void status()
- {
- std::cout << "STATUS: " << name
- << "\nCordinates: x=" << position.get_x() << " y=" << position.get_y()
- << "\nFuel: " << fuelLeft << " from " << fuelMax
- << "\n" << m_credits.status() << "\n";
- }
- void flight(SpacePoint p)
- {
- fuelLeft -= position.distance(p);
- if (fuelLeft < 0) fuelLeft = 0;
- position = p;
- }
- void prepare()
- {
- std::cin >> name >> fuelLeft >> fuelMax;
- position.read();
- int credits;
- std::cin >> credits;
- m_credits.put_credits(credits);
- }
- };
- int main()
- {
- SpaceShip ship;
- ship.prepare();
- int actions;
- std::cin >> actions;
- for (int i = 0; i < actions; i++)
- {
- std::string action;
- std::cin >> action;
- if (action == "flight")
- {
- int X, Y;
- std::cin >> X >> Y;
- ship.flight(SpacePoint(X, Y));
- }
- else if (action == "cache")
- {
- int cost;
- std::string currency;
- std::cin >> cost >> currency;
- if (currency == "credits")
- ship.get_credits().put_credits(cost);
- else if (currency == "bools")
- ship.get_credits().put_bools(cost);
- else if (currency == "stars")
- ship.get_credits().put_stars(cost);
- }
- else if (action == "status")
- {
- ship.status();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement