Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. class Motor
  7. {
  8. protected:
  9. int HorsePower;
  10. public:
  11. Motor();
  12. ~Motor();
  13. void getHorsePower(int Power);
  14. };
  15.  
  16. class Vehicle
  17. {
  18. protected:
  19. bool canFlight;
  20. public:
  21. Vehicle();
  22. ~Vehicle();
  23. void isCanFlight(bool Flight);
  24. };
  25.  
  26. class Sentient
  27. {
  28. protected:
  29. bool mind;
  30. public:
  31. Sentient();
  32. ~Sentient();
  33. void getMind(bool mind);
  34. };
  35. class Car :
  36. public Vehicle,
  37. public Motor
  38.  
  39. {
  40. protected:
  41. char Color[10];
  42. public:
  43. Car();
  44. ~Car();
  45. void getColor(char Color[10]);
  46. };
  47.  
  48. class Human :
  49. public Sentient
  50. {
  51. protected:
  52. char name[255];
  53. int age;
  54. public:
  55. Human();
  56. ~Human();
  57. void setName(char name[10]);
  58. void setAge(int age);
  59.  
  60. private:
  61.  
  62. };
  63.  
  64.  
  65.  
  66. class Transformer :
  67. public Car,
  68. public Human
  69. {
  70. private:
  71. enum Age{old, young};
  72. public:
  73. Age Position;
  74. Transformer();
  75. ~Transformer();
  76. void getAge(int age);
  77. void print();
  78. };
  79.  
  80.  
  81.  
  82.  
  83.  
  84. //Описание методов
  85.  
  86. Car::Car()
  87. {
  88. cout << "Вызов конструктора Car" << endl;
  89. }
  90.  
  91. Car::~Car()
  92. {
  93. cout << "Вызов деструктора Car" << endl;
  94. }
  95.  
  96. void Car::getColor(char Color[255])
  97. {
  98. strcpy_s(this->Color, Color);
  99. }
  100.  
  101.  
  102. Human::Human()
  103. {
  104. cout << "Вызов конструктора Human" << endl;
  105. }
  106.  
  107. Human::~Human()
  108. {
  109. cout << "Вызов деструктора Human" << endl;
  110. }
  111.  
  112. void Human::setName(char name[20])
  113. {
  114. strcpy_s(this->name, name);
  115. }
  116.  
  117. void Human::setAge(int age)
  118. {
  119. this->age = age;
  120. }
  121.  
  122.  
  123. Motor::Motor()
  124. {
  125. cout << "Вызов конструктора Motor" << endl;
  126. }
  127.  
  128. Motor::~Motor()
  129. {
  130. cout << "Вызов деструктора Motor" << endl;
  131. }
  132.  
  133. void Motor::getHorsePower(int Power)
  134. {
  135. this->HorsePower = Power;
  136. }
  137.  
  138.  
  139.  
  140. Sentient::Sentient()
  141. {
  142. cout << "Вызов конструктора Sentient" << endl;
  143. }
  144.  
  145. Sentient::~Sentient()
  146. {
  147. cout << "Вызов деструктора Sentient" << endl;
  148. }
  149.  
  150. void Sentient::getMind(bool mind)
  151. {
  152. this->mind = mind;
  153. }
  154.  
  155.  
  156.  
  157. Transformer::Transformer()
  158. {
  159. cout << "Вызов конструктора Transformer" << endl;
  160. }
  161.  
  162. Transformer::~Transformer()
  163. {
  164. cout << "Вызов деструктора Transformer" << endl;
  165. }
  166.  
  167. void Transformer::getAge(int age)
  168. {
  169. switch (age)
  170. {
  171. case 0:
  172. {
  173. this->Position = Age::old;
  174. break;
  175. }
  176. case 1:
  177. {
  178. this->Position = Age::young;
  179. break;
  180. }
  181. }
  182. }
  183.  
  184. void Transformer::print()
  185. {
  186. cout << endl;
  187. cout << "Имя трансформера: " << this->name << endl;
  188. cout << "Возраст: " << this->age << endl;
  189. cout << "Наличие разума: " << this->mind << endl;
  190. cout << "Цвет: " << this->Color << endl;
  191. cout << "Мощность: " << this->HorsePower << endl;
  192. cout << "Возможность летать: " << this->canFlight << endl;
  193. cout << "Давность выпуска: " << this->Position << endl;
  194. cout << endl;
  195. }
  196.  
  197.  
  198.  
  199. Vehicle::Vehicle()
  200. {
  201. cout << "Вызов конструктора Vehicle" << endl;
  202. }
  203.  
  204. Vehicle::~Vehicle()
  205. {
  206. cout << "Вызов деструктора Vehicle" << endl;
  207. }
  208.  
  209. void Vehicle::isCanFlight(bool Flight)
  210. {
  211. this->canFlight = Flight;
  212. }
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220. int main()
  221. {
  222. setlocale(LC_ALL, "RUS");
  223.  
  224. Sentient NewSentient;
  225. NewSentient.getMind(false);
  226.  
  227. Human NewHuman;
  228. NewHuman.getMind(true);
  229. NewHuman.setAge(18);
  230. NewHuman.setName("Лена");
  231.  
  232.  
  233. Vehicle NewVehicle;
  234. NewVehicle.isCanFlight(true);
  235.  
  236. Motor NewMotor;
  237. NewMotor.getHorsePower(300);
  238.  
  239. Car NewCar;
  240. NewCar.isCanFlight(false);
  241. NewCar.getHorsePower(125);
  242. NewCar.getColor("Красный");
  243.  
  244. Transformer NewTransformer;
  245. NewTransformer.getColor("Желтый");
  246. NewTransformer.getHorsePower(1000);
  247. NewTransformer.getMind(true);
  248. NewTransformer.setAge(50);
  249. NewTransformer.setName("Alex");
  250. NewTransformer.isCanFlight(false);
  251. NewTransformer.getAge(1);
  252. NewTransformer.print();
  253.  
  254. return 0;
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement