Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. //ciapong
  2. #ifndef TRAIN_H
  3. #define TRAIN_H
  4.  
  5. #include "Locomotive.h"
  6. #include "Train_car.h"
  7. #include "Driver.h"
  8.  
  9. #include <iostream>
  10.  
  11. class Train {
  12. private:
  13. std::string m_name;
  14. int m_amount_train_car;
  15. Train_car* m_train_car_array;
  16. Locomotive m_locomotive;
  17. Driver m_driver;
  18. static int s_amount_of_objects;
  19. public:
  20. Train();
  21. Train(const std::string& name, const Locomotive& locomotive);
  22. Train(const int& amount_train_car, const Locomotive& locomotive);
  23. Train(const std::string& name, const int& amount_train_car, const Locomotive& locomotive);
  24. Train(const Train& train);
  25.  
  26. std::string getName() const;
  27. Train_car* getTrainCar() const;
  28. Train_car getTrainCar(const int& key) const;
  29. Locomotive getLocomotive() const;
  30. Driver getDriver() const;
  31.  
  32. void setName(const std::string& name);
  33. void setTrainCar(const Train_car& train_car, const int& key);
  34. void setLocomotive(const Locomotive& locomotive);
  35. void setDriver(const Driver& driver);
  36.  
  37. Train operator+(const Train& train);
  38. Train operator=(const Train& train);
  39. Train operator[](const Train& train);
  40. bool operator==(const Train& train);
  41. // operator konwersji
  42.  
  43. static int getAmountOfObjects();
  44. ~Train();
  45. };
  46.  
  47.  
  48.  
  49. #endif TRAIN_H
  50.  
  51. #include "Train.h"
  52.  
  53. int Train::s_amount_of_objects = 0;
  54.  
  55. Train::Train() {
  56. m_name = "";
  57. m_amount_train_car = 0;
  58. m_train_car_array = nullptr;
  59. m_locomotive = Locomotive();
  60. m_driver = Driver();
  61. s_amount_of_objects++;
  62. }
  63.  
  64. Train::Train(const std::string& name, const Locomotive& locomotive) {
  65. m_name = name;
  66. m_amount_train_car = 0;
  67. m_train_car_array = nullptr;
  68. m_locomotive = locomotive;
  69. m_driver = Driver();
  70. s_amount_of_objects++;
  71. }
  72.  
  73. Train::Train(const int& amount_train_car, const Locomotive& locomotive) {
  74. m_name = "";
  75. m_amount_train_car = amount_train_car;
  76. m_train_car_array = new Train_car[m_amount_train_car];
  77. m_locomotive = locomotive;
  78. m_driver = Driver();
  79. s_amount_of_objects++;
  80. }
  81.  
  82. Train::Train(const std::string& name, const int& amount_train_car, const Locomotive & locomotive) {
  83. m_name = name;
  84. m_amount_train_car = amount_train_car;
  85. m_train_car_array = new Train_car[m_amount_train_car];
  86. m_locomotive = locomotive;
  87. m_driver = Driver();
  88. s_amount_of_objects++;
  89. }
  90.  
  91. Train::Train(const Train& train) {
  92. m_name = train.m_name;
  93. m_amount_train_car = train.m_amount_train_car;
  94. m_train_car_array = new Train_car[m_amount_train_car];
  95. for (int i = 0; i < m_amount_train_car; i++)
  96. m_train_car_array[i] = train.m_train_car_array[i];
  97. m_locomotive = train.m_locomotive;
  98. m_driver = train.m_driver;
  99. s_amount_of_objects++;
  100. }
  101.  
  102. std::string Train::getName() const {
  103. return m_name;
  104. }
  105.  
  106. Train_car* Train::getTrainCar() const {
  107. return m_train_car_array;
  108. }
  109.  
  110. Train_car Train::getTrainCar(const int& key) const {
  111. return m_train_car_array[key];
  112. }
  113.  
  114. Locomotive Train::getLocomotive() const {
  115. return m_locomotive;
  116. }
  117.  
  118. Driver Train::getDriver() const {
  119. return m_driver;
  120. }
  121.  
  122. void Train::setName(const std::string& name) {
  123. m_name = name;
  124. }
  125.  
  126. void Train::setTrainCar(const Train_car& train_car, const int& key) {
  127. m_train_car_array[key] = train_car;
  128. }
  129.  
  130. void Train::setLocomotive(const Locomotive& locomotive) {
  131. m_locomotive = m_locomotive;
  132. }
  133.  
  134. void Train::setDriver(const Driver& driver) {
  135. m_driver = driver;
  136. }
  137.  
  138. int Train::getAmountOfObjects() {
  139. return s_amount_of_objects;
  140. }
  141.  
  142. Train::~Train() {
  143. delete[] m_train_car_array;
  144. }
  145. //klasa maszynista
  146. #ifndef DRIVER_H
  147. #define DRIVER_H
  148.  
  149. #include <iostream>
  150.  
  151. class Driver {
  152. private:
  153. std::string m_name;
  154. int m_age;
  155. int m_experience;
  156. double salary;
  157. };
  158.  
  159. #endif DRIVER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement