Advertisement
avr39-ripe

structLectureBBV192

Apr 29th, 2020
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.71 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. struct Dimension
  4. {
  5.     int width;
  6.     int lenght;
  7.     int height;
  8.  
  9.     void enter();
  10.     void print(bool extra = false);
  11.     int volume() { return width * lenght * height; };
  12.     int area() { return width * lenght; };
  13.     bool set(int w, int l, int h);
  14. };
  15.  
  16. struct WashingMachine
  17. {
  18.     char manufacturer[100];
  19.     char color[20];
  20.     Dimension dm;
  21.     int power;
  22.     int speed;
  23.     int temp;
  24.  
  25.     void enter();
  26.     void print();
  27. };
  28.  
  29. int main()
  30. {
  31.     //Dimension dm{100,110,120}; // dm.width dm.length dm.height
  32.     //Dimension dm1{200,210,0}; // dm1.width dm1.length dm1.height
  33.  
  34.     ////dm.enter(); //dm dm.width dm.length dm.height
  35.     ////dm1.enter(); //dm1 dm1.width dm1.length dm1.height
  36.  
  37.     //if (dm.set(150, 160, -270))
  38.     //{
  39.     //    std::cout << "Changed!\n";
  40.     //}
  41.     //else
  42.     //{
  43.     //    std::cout << "Change FAILED!\n";
  44.     //}
  45.     //dm.print(true);
  46.     //std::cout << '\n';
  47.     //dm1.print(true);
  48.  
  49.     //WashingMachine wm;
  50.     //wm.enter();
  51.     //std::cout << '\n';
  52.     //wm.print();
  53.  
  54.     const int wmArrSize{ 3 };
  55.     WashingMachine washingMachines[wmArrSize]{ {"LG", "red", {100, 100, 85}, 1500, 900, 65},
  56.                                                 {"Samsung", "black", {150, 150, 85}, 1200, 850, 100},
  57.                                                 {"RUCHNA", "green", {300, 300, 85}, 2500, 1900, 250} };
  58.  
  59.     for (int i{ 0 }; i < wmArrSize; ++i)
  60.     {
  61.         washingMachines[i].print();
  62.         std::cout << "\n\n";
  63.     }
  64.  
  65. /*
  66.     int wmArrSize{ 3 };
  67.     WashingMachine** washingMachines{ new WashingMachine* [wmArrSize] {
  68.                                       new WashingMachine{"LG", "red", {100, 100, 85}, 1500, 900, 65},
  69.                                       new WashingMachine{"Samsung", "black", {150, 150, 85}, 1200, 850, 100},
  70.                                       new WashingMachine {"RUCHNA", "green", {300, 300, 85}, 2500, 1900, 250}} };
  71.  
  72.     for (int i{ 0 }; i < wmArrSize; ++i)
  73.     {
  74.         washingMachines[i]->print();
  75.         std::cout << "\n\n";
  76.     }
  77. */
  78. }
  79.  
  80. void Dimension::enter()
  81. {
  82.     std::cout << "Width:\n";
  83.     std::cin >> width;
  84.     std::cout << "Length:\n";
  85.     std::cin >> lenght;
  86.     std::cout << "Height:\n";
  87.     std::cin >> height;
  88. };
  89.  
  90. void Dimension::print(bool extra)
  91. {
  92.     std::cout << "\nLength: " << lenght;
  93.     std::cout << "\nWidth: " << width;
  94.     std::cout << "\nHeight: " << height;
  95.     if (extra)
  96.     {
  97.         std::cout << "\nArea: " << area();
  98.         if (height > 0) { std::cout << "\nVolume: " << volume(); }
  99.     }
  100. };
  101.  
  102. bool Dimension::set(int w, int l, int h)
  103. {
  104.     if (w < 0) { return false; };
  105.     if (l < 0) { return false; };
  106.     if (h < 0) { return false; };
  107.     width = w;
  108.     lenght = l;
  109.     height = h;
  110.     return true;
  111. };
  112.  
  113. void WashingMachine::enter()
  114. {
  115.     std::cout << "Washing machine\n";
  116.     std::cout << "Manufacturer:\n";
  117.     std::cin.getline(manufacturer, 100);
  118.     std::cout << "Color:\n";
  119.     std::cin.getline(color, 20);
  120.     dm.enter();
  121.     std::cout << "Power:\n";
  122.     std::cin >> power;
  123.     std::cout << "Speed:\n";
  124.     std::cin >> speed;
  125.     std::cout << "Temperature:\n";
  126.     std::cin >> temp;
  127. };
  128.  
  129. void WashingMachine::print()
  130. {
  131.     std::cout << "Washing machine";
  132.     std::cout << "\nManufacturer: " << manufacturer;
  133.     std::cout << "\nColor: " << color;
  134.     dm.print(true);
  135.     std::cout << "\nPower: " << power;
  136.     std::cout << "\nSpeed: " << speed;
  137.     std::cout << "\nTemperature: " << temp;
  138. };
  139.  
  140. Dimension enterDimension()
  141. {
  142.     Dimension dm;
  143.     std::cout << "Width:\n";
  144.     std::cin >> dm.width;
  145.     std::cout << "Length:\n";
  146.     std::cin >> dm.lenght;
  147.     std::cout << "Height:\n";
  148.     std::cin >> dm.height;
  149.     return dm;
  150. };
  151.  
  152. void printDimension(const Dimension& dm)
  153. {
  154.     std::cout << "\nLength: " << dm.lenght;
  155.     std::cout << "\nWidth: " << dm.width;
  156.     std::cout << "\nHeight: " << dm.height;
  157. };
  158.  
  159. WashingMachine enterWashingMachine()
  160. {
  161.     WashingMachine wm;
  162.     std::cout << "Washing machine\n";
  163.     std::cout << "Manufacturer:\n";
  164.     std::cin.getline(wm.manufacturer, 100);
  165.     std::cout << "Color:\n";
  166.     std::cin.getline(wm.color, 20);
  167.     wm.dm = enterDimension();
  168.     std::cout << "Power:\n";
  169.     std::cin >> wm.power;
  170.     std::cout << "Speed:\n";
  171.     std::cin >> wm.speed;
  172.     std::cout << "Temperature:\n";
  173.     std::cin >> wm.temp;
  174.     return wm;
  175. };
  176.  
  177. void printWashingMachine(const WashingMachine& wm)
  178. {
  179.     std::cout << "Washing machine";
  180.     std::cout << "\nManufacturer: " << wm.manufacturer;
  181.     std::cout << "\nColor: " << wm.color;
  182.     printDimension(wm.dm);
  183.     std::cout << "\nPower: " << wm.power;
  184.     std::cout << "\nSpeed: " << wm.speed;
  185.     std::cout << "\nTemperature: " << wm.temp;
  186. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement