Advertisement
Guest User

Untitled

a guest
May 27th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include<iomanip>
  6. using namespace std;
  7. class transport
  8. {
  9. protected:
  10. string gos_number;
  11. string inv_number;
  12. int year;
  13. string mark;
  14. bool remont;
  15. string description;
  16. public:
  17. virtual ~transport();
  18. string get_gn();
  19. string get_in();
  20. int get_year();
  21. void set_remont(bool x);
  22. string get_mark();
  23. string get_description();
  24. virtual bool check();
  25. virtual void Show();
  26. virtual void ReadFromFile(ifstream &f);
  27. virtual void WriteToFile(ofstream &f);
  28. virtual void input();
  29. };
  30.  
  31. class traktor: public transport
  32. {
  33. private:
  34. double ost_resource;
  35. double ost_resource_max;
  36. double power;
  37. public:
  38. ~traktor();
  39. double get_ost_resource();
  40. double get_ost_resource_max();
  41. double get_power();
  42. void Show();
  43. void ReadFromFile(ifstream &f);
  44. void input();
  45. void WriteToFile(ofstream &f);
  46. bool check();
  47.  
  48. };
  49.  
  50. class bus: public transport
  51. {
  52. private:
  53. double ost_resource;
  54. double ost_resource_max;
  55. double pass_max;
  56. public:
  57. ~bus();
  58. double get_ost_resource();
  59. double get_ost_resource_max();
  60. double get_pass_max();
  61. void Show();
  62. void ReadFromFile(ifstream &f);
  63. void input();
  64. void WriteToFile(ofstream &f);
  65. bool check();
  66.  
  67. };
  68.  
  69. class truck: public transport
  70. {
  71. private:
  72. double ost_resource;
  73. double ost_resource_max;
  74. double power;
  75. double carrying;
  76. public:
  77. //truck();
  78. ~truck();
  79. double get_ost_resource();
  80. double get_ost_resource_max();
  81. double get_power();
  82. double get_carrying();
  83. void Show();
  84. void ReadFromFile(ifstream &f);
  85. void input();
  86. void WriteToFile(ofstream &f);
  87. bool check();
  88.  
  89. };
  90.  
  91.  
  92.  
  93. transport::~transport()
  94. {
  95. // cout << "Deleted - " << Show() << endl;
  96. }
  97. string transport::get_gn()
  98. {
  99. return gos_number;
  100. }
  101. string transport::get_in()
  102. {
  103. return inv_number;
  104. }
  105. string transport::get_mark()
  106. {
  107. return mark;
  108. }
  109. int transport::get_year()
  110. {
  111. return year;
  112. }
  113. string transport::get_description()
  114. {
  115. return description;
  116. }
  117. void transport::set_remont(bool x)
  118. {
  119. remont = x;
  120. }
  121.  
  122. void transport::Show()
  123. {
  124.  
  125. cout << " | Марка: " << internal << setw(10) << get_mark()
  126. << " | Гос номер: " << internal << setw(10) << get_gn()
  127. << " | Инв номер: " << internal << setw(10) << get_in()
  128. << " | Год: " << internal << setw(10) << get_year()
  129. << " | Описание: " << internal << setw(15) << get_description();
  130.  
  131.  
  132. }
  133. void transport::ReadFromFile(ifstream &f)
  134. {
  135.  
  136. }
  137. void transport::WriteToFile(ofstream &f)
  138. {
  139.  
  140. }
  141. void transport::input()
  142. {
  143. cout << "Введите марку: ";
  144. cin >> mark;
  145. cout << "Введите гос номер: ";
  146. cin >> gos_number;
  147. cout << "Введите инв номер: ";
  148. cin >> inv_number;
  149. cout << "Введите год: ";
  150. cin >> year;
  151. if (remont == 1)
  152. {
  153. cout << "Введите тип ремонта (слитно): ";
  154. cin >> description;
  155. } else description="Не_ремонтировалась";
  156. }
  157.  
  158. bool transport::check()
  159. {
  160. return 1;
  161. }
  162. traktor::~traktor()
  163. {
  164. //cout << "Deleted - " << Show() << endl;
  165. }
  166. double traktor::get_ost_resource()
  167. {
  168. return ost_resource;
  169. }
  170. double traktor::get_ost_resource_max()
  171. {
  172. return ost_resource_max;
  173. }
  174. double traktor::get_power()
  175. {
  176. return power;
  177. }
  178.  
  179. void traktor::Show()
  180. {
  181. cout <<" Транспорт: трактор ";
  182. transport::Show();
  183. cout << " | Ост ресурс: " << internal << setw(10) << get_ost_resource()
  184. << " | Ост ресурс макс: " << internal << setw(10) << get_ost_resource_max()
  185. << " | Мощность: " << internal << setw(10) << get_power();
  186.  
  187.  
  188. }
  189. void traktor::ReadFromFile(ifstream &f)
  190. {
  191. f>> mark >> gos_number >> inv_number >> year >> ost_resource >> ost_resource_max >> power>> remont >> description;
  192. }
  193. void traktor::WriteToFile(ofstream &f)
  194. {
  195. f <<"traktor " << mark << " " << gos_number << " " << inv_number <<" "<< year << " " << ost_resource << " " << ost_resource_max << " " << power <<" "<<remont<<" "<<description<< endl;
  196.  
  197. }
  198. void traktor::input()
  199. {
  200. transport::input();
  201. cout << "Введите ост ресурс: ";
  202. cin >> ost_resource;
  203. cout << "Введите ост ресурс макс: ";
  204. cin >> ost_resource_max;
  205. cout << "Введите мощность: ";
  206. cin >> power;
  207.  
  208. }
  209. bool traktor::check()
  210. {
  211. if (ost_resource-ost_resource_max>=0)
  212. return true;
  213. else
  214. return false;
  215. }
  216.  
  217. bus::~bus()
  218. {
  219. // cout << "Deleted - " << Show() << endl;
  220. }
  221. double bus::get_ost_resource()
  222. {
  223. return ost_resource;
  224. }
  225. double bus::get_ost_resource_max()
  226. {
  227. return ost_resource_max;
  228. }
  229. double bus::get_pass_max()
  230. {
  231. return pass_max;
  232. }
  233.  
  234. void bus::Show()
  235. {
  236. cout <<" Транспорт: автобус ";
  237. transport::Show();
  238. cout << " | Ост ресурс: " << internal << setw(10) << get_ost_resource()
  239. << " | Ост ресурс макс: " << internal << setw(10) << get_ost_resource_max()
  240. << " | Пассажировместимость: " << internal << setw(10) << get_pass_max();
  241.  
  242.  
  243. }
  244. void bus::ReadFromFile(ifstream &f)
  245. {
  246. f>> mark >> gos_number >> inv_number >> year >> ost_resource >> ost_resource_max >> pass_max>> remont >> description;
  247. }
  248. void bus::WriteToFile(ofstream &f)
  249. {
  250. f <<"bus " << mark << " " << gos_number << " " << inv_number << " "<< year << " " << ost_resource << " " << ost_resource_max << " " << pass_max <<" "<<remont<<" "<<description<< endl;
  251.  
  252. }
  253. void bus::input()
  254. {
  255. transport::input();
  256. cout << "Введите ост ресурс: ";
  257. cin >> ost_resource;
  258. cout << "Введите ост ресурс макс: ";
  259. cin >> ost_resource_max;
  260. cout << "Введите Пассажировместимость: ";
  261. cin >> pass_max;
  262.  
  263. }
  264. bool bus::check()
  265. {
  266. if (ost_resource-ost_resource_max>=0)
  267. return true;
  268. else
  269. return false;
  270. }
  271. truck::~truck()
  272. {
  273. //cout << "Deleted - " << Show() << endl;
  274. }
  275. double truck::get_ost_resource()
  276. {
  277. return ost_resource;
  278. }
  279. double truck::get_ost_resource_max()
  280. {
  281. return ost_resource_max;
  282. }
  283. double truck::get_power()
  284. {
  285. return power;
  286. }
  287. double truck::get_carrying()
  288. {
  289. return carrying;
  290. }
  291.  
  292. void truck::Show()
  293. {
  294. cout <<" Транспорт: грузовик ";
  295. transport::Show();
  296. cout << " | Ост ресурс: " << internal << setw(10) << get_ost_resource()
  297. << " | Ост ресурс макс: " << internal << setw(10) << get_ost_resource_max()
  298. << " | Мощность: " << internal << setw(10) << get_power()
  299. << " | Грузоподъемность: " << internal << setw(10) << get_carrying();
  300.  
  301.  
  302. }
  303. void truck::ReadFromFile(ifstream &f)
  304. {
  305. f>> mark >> gos_number >> inv_number >> year >> ost_resource >> ost_resource_max >> power >> carrying >> remont >> description;
  306. }
  307. void truck::WriteToFile(ofstream &f)
  308. {
  309. f <<"truck " << mark << " " << gos_number << " " << inv_number <<" " << year << " " << ost_resource << " " << ost_resource_max << " " << power << " " << carrying <<" "<<remont<<" "<<description<< endl;
  310.  
  311. }
  312. void truck::input()
  313. {
  314. transport::input();
  315. cout << "Введите ост ресурс: ";
  316. cin >> ost_resource;
  317. cout << "Введите ост ресурс макс: ";
  318. cin >> ost_resource_max;
  319. cout << "Введите мощность: ";
  320. cin >> power;
  321. cout << "Введите грузоподъемность: ";
  322. cin >> carrying;
  323. }
  324. bool truck::check()
  325. {
  326. if (ost_resource-ost_resource_max>=0)
  327. return true;
  328. else
  329. return false;
  330. }
  331. int main()
  332. {
  333. setlocale(LC_ALL, "Russian");
  334. vector <transport *> ts; // создаем вектор указателей
  335. bool isProgramActive = true;
  336. while (isProgramActive) // пока не поступило сигнала о завершении программы, выполняем код ниже
  337. {
  338. cout << "1. Добавить новое ТС\n"
  339. "2. Добавить ТС после ремонта\n"
  340. "3. Удалить ТС и вывести информацию о нем\n"
  341. "4. Вывести все ТС\n"
  342. "5. Вывести все ТС с остаточным остатком ресурсов менее заданного\n"
  343. "6. Вывод всех тракторов\n"
  344. "7. Вывод всех автобусов\n"
  345. "8. Вывод всех грузовых авто\n"
  346. "0. Выход из программы\n"
  347. "9. Добавить ТС из файла\n"
  348. "10. Добавить ТС в файл\n"
  349. "\nВведите номер действия: ";
  350. //156790
  351. int action = -1;
  352. cin >>action;
  353. cout << endl;
  354. switch (action)
  355. {
  356. case 0:
  357. {
  358. for ( int i = 0; i<ts.size();i++)
  359. {
  360. delete ts[i];
  361. }
  362. isProgramActive = false;
  363. break;
  364. }
  365. case 1:
  366.  
  367. {
  368. cout << "Введите тип автомобиля(traktor, bus, truck): ";
  369. string type;
  370. cin >> type;
  371. transport *t=0;
  372. if (type=="traktor")t=new traktor;
  373. if (type=="bus")t=new bus;
  374. if (type=="truck") t=new truck;
  375. t->set_remont(0);
  376. t->input();
  377. ts.push_back(t);
  378. break;
  379. }
  380. case 2:
  381. {
  382. cout << "Введите тип автомобиля(traktor, bus, truck): ";
  383. string type;
  384. cin >> type;
  385. transport *t=0;
  386. if (type=="traktor")t=new traktor;
  387. if (type=="bus")t=new bus;
  388. if (type=="truck") t=new truck;
  389. t->set_remont(1);
  390. t->input();
  391. ts.push_back(t);
  392. break;
  393. }
  394. case 3:
  395. {
  396. int id = -1;
  397. while (id < 0)
  398. {
  399. cout << "Введите номер автомобиля в списке : ";
  400. cin >> id;
  401. if (id >= ts.size())
  402. id = -1;
  403. }
  404. cout << "Удалили ТС: ";
  405. ts[id]->Show();
  406. delete ts[id]; // освобождаем дин.память
  407. ts.erase(ts.begin() + id); // удаляем указатель из вектора
  408. break;
  409. }
  410. case 4:
  411. {
  412. for (int i = 0; i < ts.size(); i++)
  413. {
  414. cout << i << ". "; // номер
  415. ts[i]->Show();
  416. cout <<endl;
  417. }
  418. break;
  419. }
  420. case 5:
  421. {
  422. int k=0;
  423. for ( int i = 0; i < ts.size(); i++)
  424. {
  425.  
  426. if ( ts[i]->check()==false)
  427. {
  428. cout << k << ". "; // номер
  429. ts[i]->Show();
  430. k++;
  431. cout <<endl;
  432. }
  433.  
  434. }
  435. break;
  436. }
  437. case 6:
  438. {
  439. int k=0;
  440. for ( int i = 0; i < ts.size(); i++)
  441. {
  442. traktor* tr = dynamic_cast<traktor*>(ts[i]);
  443. if (tr)
  444. {
  445. cout << k << ". "; // номер
  446. ts[i]->Show();
  447. k++;
  448. cout <<endl;
  449. }
  450. }
  451. break;
  452. }
  453. case 7:
  454. {
  455. int k=0;
  456. for ( int i = 0; i < ts.size(); i++)
  457. {
  458. bus* tr = dynamic_cast<bus*>(ts[i]);
  459. if (tr)
  460. {
  461. cout << k << ". "; // номер
  462. ts[i]->Show();
  463. k++;
  464. cout <<endl;
  465. }
  466. }
  467. break;
  468. }
  469. case 8:
  470. {
  471. int k=0;
  472. for ( int i = 0; i < ts.size(); i++)
  473. {
  474. truck* tr = dynamic_cast<truck*>(ts[i]);
  475. if (tr)
  476. {
  477. cout << k << ". "; // номер
  478. ts[i]->Show();
  479. k++;
  480. cout <<endl;
  481. }
  482. }
  483. break;
  484. }
  485. case 9:
  486. {
  487. ifstream fin("E:\input.txt");
  488. while (!fin.eof())
  489. {
  490. string type;
  491. fin >> type;
  492. transport *t=0;
  493. if (type=="traktor") t=new traktor;
  494. if (type=="bus") t=new bus;
  495. if (type=="truck") t=new truck;
  496. if(t)
  497. {
  498. t->ReadFromFile(fin);
  499. ts.push_back(t);
  500. }
  501. }
  502. break;
  503. }
  504. case 10:
  505. {
  506. ofstream fout("E:\input.txt");
  507. for (int i = 0; i<ts.size();++i)
  508. {
  509. ts[i]->WriteToFile(fout);
  510. }
  511. break;
  512. }
  513.  
  514.  
  515. }
  516. }
  517. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement