Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. // координаты объекта в космосе
  8.  
  9. class SpacePoint
  10. {
  11. public:
  12. int X, Y;
  13. int distance(SpacePoint point) {
  14. return sqrt(pow(X - point.X, 2) + pow(Y - point.Y, 2));
  15. }
  16.  
  17. void read() {
  18. cin >> X >> Y;
  19. }
  20.  
  21. void print() {
  22. cout << "Cordinates: x=" << X << " y=" << Y << endl;
  23. }
  24. };
  25.  
  26.  
  27. // Денежный счет
  28. class CreditAccount {
  29. public:
  30. // Галактические кредиты
  31. int credits = 0;
  32.  
  33. void buy(int t_credits)
  34. {
  35. credits -= t_credits;
  36. //credits = credits > 0 ? credits : 0;
  37. }
  38.  
  39. void putCredits(int credits) {
  40. credits += credits;
  41. }
  42.  
  43. void putProtorianBools(int count) {
  44. credits += count * 3;
  45. }
  46.  
  47. void putOrionStars(int count) {
  48. credits += count * 2 / 5;
  49. }
  50.  
  51. void printSatus() {
  52. cout << "Account: " << credits << " credits" << endl;
  53. }
  54. };
  55.  
  56. class SpaceShip {
  57. public:
  58. int fuelLeft; //Остаток топлива
  59. int fuelMax; // Вместимость топливного бака (максимум топлива)
  60. string name; // Название корабля
  61.  
  62. SpacePoint pos; //Координаты корабля
  63. CreditAccount account; // Денежный счет
  64.  
  65. void printStatus() {
  66. cout << "STATUS: " << name << endl;
  67. pos.print();
  68. cout << "Fuel: " << fuelLeft << " from " << fuelMax << endl;
  69. account.printSatus();
  70. }
  71.  
  72. void flight(SpacePoint pt) {
  73. fuelLeft -= pos.distance(pt);
  74. if (fuelLeft < 0)
  75. fuelLeft = 0;
  76. pos = pt;
  77. }
  78.  
  79. void prepare() {
  80. cin >> name >> fuelLeft >> fuelMax;
  81. pos.read();
  82. cin >> account.credits;
  83. }
  84. };
  85.  
  86.  
  87. int main() {
  88. SpaceShip ship;
  89. ship.prepare();
  90.  
  91. int comCount;
  92. cin >> comCount;
  93.  
  94. for (int i = 0; i < comCount; i++)
  95. {
  96. string com;
  97. cin >> com;
  98.  
  99. if (com == "flight") {
  100. SpacePoint pt;
  101. pt.read();
  102. ship.flight(pt);
  103. }
  104.  
  105. else if (com == "buy")
  106. {
  107. int cost;
  108. std::cin >> cost;
  109.  
  110. ship.account.buy(cost);
  111. }
  112.  
  113. else if (com == "cache") {
  114. int count;
  115. string name;
  116. cin >> count >> name;
  117.  
  118. if (name == "credits")
  119. ship.account.putCredits(count);
  120. if (name == "bools")
  121. ship.account.putProtorianBools(count);
  122. if (name == "stars")
  123. ship.account.putOrionStars(count);
  124. }
  125. else if (com == "status")
  126. {
  127. ship.printStatus();
  128. }
  129.  
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement