Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include "string"
  3.  
  4. class Transport {
  5. private:
  6. int speed;
  7. int price1km;
  8. protected:
  9. Transport() = default;
  10. Transport(int qspeed, int qprice) {
  11. speed = qspeed;
  12. price1km = qprice;
  13. }
  14. Transport(Transport&&) {}
  15. Transport(const Transport&) {}
  16. ~Transport() {}
  17.  
  18. void printTransport() {
  19. std::cout << speed << std::endl << price1km << std::endl;
  20. }
  21.  
  22. float time(int distance) {
  23. float timex = distance / speed;
  24. return timex;
  25. }
  26.  
  27. float cost(int distance) {
  28. float costx = distance * price1km;
  29. return costx;
  30. }
  31.  
  32. };
  33.  
  34. class Auto : public Transport {
  35. private:
  36. int timeT;
  37. int costT;
  38. public:
  39. Auto() : Transport() {}
  40. Auto(int qspeed, int qprice) : Transport(qspeed, qprice) {}
  41.  
  42. void printAuto(Auto& old, int distancex) {
  43. old.printTransport();
  44. timeT = old.time(distancex);
  45. costT = old.cost(distancex);
  46. std::cout << timeT << std::endl << costT << std::endl;
  47. }
  48. };
  49.  
  50. class Bike : public Transport {
  51. private:
  52. int timeT;
  53. int costT;
  54. public:
  55. Bike() : Transport() {}
  56. Bike(int qspeed, int qprice) : Transport(qspeed, qprice) {}
  57.  
  58. void printBike(Bike& old, int distancex) {
  59. old.printTransport();
  60. timeT = old.time(distancex);
  61. costT = old.cost(distancex);
  62. std::cout << timeT << std::endl << costT << std::endl;
  63. }
  64. };
  65.  
  66. class Wagon : public Transport {
  67. private:
  68. int timeT;
  69. int costT;
  70. public:
  71. Wagon() : Transport() {}
  72. Wagon(int qspeed, int qprice) : Transport(qspeed, qprice) {}
  73.  
  74. void printWagon(Wagon& old, int distancex) {
  75. old.printTransport();
  76. timeT = old.time(distancex);
  77. costT = old.cost(distancex);
  78. std::cout << timeT << std::endl << costT << std::endl;
  79. }
  80. };
  81.  
  82.  
  83. int main(){
  84. Auto kia(90, 10);
  85. Bike GT(25, 5);
  86. Wagon telega(10, 3);
  87. kia.printAuto(kia, 600);
  88. GT.printBike(GT, 30);
  89. telega.printWagon(telega, 10);
  90.  
  91.  
  92.  
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement