Lixard

Lab6_class

Apr 25th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.94 KB | None | 0 0
  1. #include "class.h"
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. Cars::Cars() : model("Octavia"), gosnomer("B131AM"), familiya("Борисов"), color("Синий"), max_speed(180), places(4), lps(100)
  9. {
  10. }
  11.  
  12. Cars::Cars(string mod, string gsn, string fam, string col, int ms, int p, int l):
  13.     model(mod), gosnomer(gsn), familiya(fam), color(col), max_speed(ms), places(p), lps(l)
  14. {
  15. }
  16.  
  17. Cars::Cars(const Cars& a)
  18. {
  19.     model = a.model;
  20.     gosnomer = a.gosnomer;
  21.     familiya = a.familiya;
  22.     color = a.color;
  23.     max_speed = a.max_speed;
  24.     places = a.places;
  25.     lps = a.lps;
  26. }
  27.  
  28. void Cars::get_all()
  29. {
  30.     cout << setiosflags(ios::left) << setw(10) << model << setw(10) << gosnomer << setw(10) << familiya << setw(10) << color << setw(10) << max_speed <<
  31.         setw(10) << places << setw(10) << lps << endl;
  32. }
  33.  
  34. void Cars::get_model()
  35. {
  36.     cout << model << endl;
  37. }
  38.  
  39. void Cars::get_gosnomer()
  40. {
  41.     cout << gosnomer << endl;
  42. }
  43.  
  44. void Cars::get_familiya()
  45. {
  46.     cout << familiya << endl;
  47. }
  48.  
  49. void Cars::get_color()
  50. {
  51.     cout << color << endl;
  52. }
  53.  
  54. void Cars::get_max_speed()
  55. {
  56.     cout << max_speed << endl;
  57. }
  58.  
  59. void Cars::get_places()
  60. {
  61.     cout << places << endl;
  62. }
  63.  
  64. void Cars::get_lps()
  65. {
  66.     cout << lps << endl;
  67. }
  68.  
  69. void Cars::set_all()
  70. {
  71.     cout << "Введите модель автомобиля: ";
  72.     cin >> model;
  73.     cout << "Ведите госномер: ";
  74.     cin >> gosnomer;
  75.     cout << "Введите фамилию водителя: ";
  76.     cin >> familiya;
  77.     cout << "Введите цвет автомобиля: ";
  78.     cin >> color;
  79.     cout << "Введите максимальную скорость автомобиля: ";
  80.     cin >> max_speed;
  81.     int_check(max_speed);
  82.     cout << "Введите количество мест в автомобиле: ";
  83.     cin >> places;
  84.     int_check(places);
  85.     cout << "Введите мощность двигателя: ";
  86.     cin >> lps;
  87.     int_check(lps);
  88. }
  89.  
  90. void Cars::set_model()
  91. {
  92.     cout << "Введите модель автомобиля: ";
  93.     cin >> model;
  94. }
  95.  
  96. void Cars::set_gosnomer()
  97. {
  98.     cout << "Ведите госномер: ";
  99.     cin >> gosnomer;
  100. }
  101.  
  102. void Cars::set_familiya()
  103. {
  104.     cout << "Введите фамилию водителя: ";
  105.     cin >> familiya;
  106. }
  107.  
  108. void Cars::set_color()
  109. {
  110.     cout << "Введите цвет автомобиля: ";
  111.     cin >> color;
  112. }
  113.  
  114. void Cars::set_max_speed()
  115. {
  116.     cout << "Введите максимальную скорость автомобиля: ";
  117.     cin >> max_speed;
  118.     int_check(max_speed);
  119. }
  120.  
  121. void Cars::set_places()
  122. {
  123.     cout << "Введите количество мест в автомобиле: ";
  124.     cin >> places;
  125.     int_check(places);
  126. }
  127.  
  128. void Cars::set_lps()
  129. {
  130.     cout << "Введите мощность двигателя: ";
  131.     cin >> lps;
  132.     int_check(lps);
  133. }
  134.  
  135. void Cars::msoversmth(vector<Cars>& obj)
  136. {
  137.     if (obj.size() - 1 == 0)
  138.     {
  139.         cout << "Нет автомобилей в списке." << endl;
  140.     }
  141.     if (obj.size() - 1 > 0)
  142.     {
  143.         string colors;
  144.         int ms;
  145.         cout << "Введите цвет автомобиля: ";
  146.         cin >> colors;
  147.         cout << "Введите максимальную скорость автомобиля: ";
  148.         cin >> ms;
  149.         int_check(ms);
  150.         int j = 1;
  151.         cout << setiosflags(ios::left) << setw(10) << "Модель" << setw(10) << "Госномер" <<
  152.             setw(10) << "Фамилия" << setw(10) << "Цвет" << setw(10) << "Скорость" <<
  153.             setw(10) << "Места" << setw(10) << "Мощность" << endl;
  154.         palki();
  155.         setlocale(LC_ALL, "Russian");
  156.         for (int i = 0; i < obj.size() - 1; i++)
  157.         {
  158.             if (equal(obj[i].color, colors) && (ms < obj[i].max_speed))
  159.             {
  160.                 cout << j++ << ".";
  161.                 obj[i].get_all();
  162.             }
  163.         }
  164.         palki();
  165.     }
  166. }
  167.  
  168. void Cars::mestaoversmth(vector<Cars>& obj)
  169. {
  170.     if (obj.size() - 1 == 0)
  171.     {
  172.         cout << "Нет автомобилей в списке." << endl;
  173.     }
  174.     if (obj.size() - 1 > 0)
  175.     {
  176.         int place;
  177.         cout << "Введите количество мест: ";
  178.         cin >> place;
  179.         int_check(place);
  180.         int j = 1;
  181.         cout << setiosflags(ios::left) << setw(2) << "  " << setw(10) << "Модель" << setw(10) << "Госномер" <<
  182.             setw(10) << "Фамилия" << setw(10) << "Цвет" << setw(10) << "Скорость" <<
  183.             setw(10) << "Места" << setw(10) << "Мощность" << endl;
  184.         palki();
  185.         for (int i = 0; i < obj.size() - 1; i++)
  186.         {
  187.             if (obj[i].places > place)
  188.             {
  189.                 cout << j++ << ".";
  190.                 obj[i].get_all();
  191.             }
  192.         }
  193.         palki();
  194.     }
  195. }
  196.  
  197.  
  198. void Cars::int_check(int& number)
  199. {
  200.     if (cin.fail())
  201.     {
  202.         cin.clear();
  203.         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  204.         number = 0;
  205.     }
  206. }
  207.  
  208. bool Cars::equal(const string& a, const string& b)
  209. {
  210.     if (a.size() != b.size())
  211.     {
  212.         return false;
  213.     }
  214.     for (int i = 0; i < a.size(); i++)
  215.     {
  216.         if (tolower(a[i]) != tolower(b[i]))
  217.         {
  218.             return false;
  219.         }
  220.     }
  221.     return true;
  222. }
  223.  
  224. void Cars::palki()
  225. {
  226.     for (int i = 0; i < 72; i++)
  227.     {
  228.         cout << "-";
  229.     }
  230.     cout << endl;
  231. }
  232.  
  233.  
  234. Cars::~Cars()
  235. {
  236. }
Advertisement
Add Comment
Please, Sign In to add comment