Advertisement
Ansaid

Laba_4

Apr 2nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.14 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Child
  8. {
  9. private:
  10.     string name;
  11.     string surname;
  12.     int age;
  13. public:
  14.     void set_info();
  15.     void get_info();
  16.  
  17.     Child() // конструктор по умолчанию
  18.     {
  19.         name = "NoName";
  20.         surname = "NoSurname";
  21.         age = 0;
  22.     }
  23.  
  24.     Child(string nameVal, string surnameVal,int ageVal) // конструктор с параметрами
  25.     {
  26.         name = nameVal;
  27.         surname = surnameVal;
  28.         age = ageVal;
  29.     }
  30.  
  31.     Child(string nameVal, string surnameVal, int ageVal) : name(nameVal), surname(surnameVal), age(ageVal) // инициализирующий конструктор
  32.     {
  33.  
  34.     }
  35.    
  36. };
  37.  
  38. class Tiles
  39. {
  40. public:
  41.     string brand;
  42.     float size_h;
  43.     float size_w;
  44.     float price;
  45.     void getData();
  46.  
  47.     Tiles()
  48.     {
  49.         brand = "NoBrend";
  50.         size_h = 0;
  51.         size_w = 0;
  52.         price = 0;
  53.     }
  54.  
  55.     Tiles(string brandVal, float size_hVal, float size_wVal, float priceVal)
  56.     {
  57.         brand = brandVal;
  58.         size_h = size_hVal;
  59.         size_w = size_wVal;
  60.         price = priceVal;
  61.     }
  62.  
  63.     Tiles(string brandVal, float size_hVal, float size_wVal, float priceVal) : brand(brandVal), size_h(size_hVal), size_w(size_wVal), price(priceVal) // инициализирующий конструктор
  64.     {
  65.  
  66.     }
  67. };
  68.  
  69. class Complex
  70. {
  71. private:
  72.     float x;
  73.     float y;
  74. public:
  75.     void set_info();
  76.     void get_info();
  77.     void abs();
  78. };
  79.  
  80. class Vector
  81. {
  82. private:
  83.     float x;
  84.     float y;
  85.     float z;
  86. public:
  87.     void set_info();
  88.     void get_info();
  89.     void sum(Vector a, Vector b);
  90.     void sub(Vector a, Vector b);
  91.     void abs();
  92. };
  93.  
  94. int main()
  95. {
  96.     setlocale(LC_ALL, "Russian");
  97.     int choice;
  98.     cout << "Введите номер задания: ";
  99.     cin >> choice;
  100.     switch (choice)
  101.     {
  102.     case 1:
  103.     {
  104.         Child child_1, child_2;
  105.         cout << "Введите информацию о первом ребенке:" << endl;
  106.         child_1.set_info();
  107.         cout << "Введите информацию о втором ребенке:" << endl;
  108.         child_2.set_info();
  109.         cout << "Информация о первом ребенке:" << endl;
  110.         child_1.get_info();
  111.         cout << "Информация о втором ребенке:" << endl;
  112.         child_2.get_info();
  113.     }
  114.     break;
  115.  
  116.     case 2:
  117.     {
  118.         Tiles tile_1, tile_2;
  119.         cout << "Введите информацию о первом виде кафеля:" << endl;
  120.         cout << "Введите бренд кафеля: ";
  121.         cin >> tile_1.brand;
  122.         cout << "Введите высоту кафеля: ";
  123.         cin >> tile_1.size_h;
  124.         cout << "Введите ширину кафеля: ";
  125.         cin >> tile_1.size_w;
  126.         cout << "Введите цену кафеля: ";
  127.         cin >> tile_1.price;
  128.  
  129.         cout << "Введите информацию о втором виде кафеля:" << endl;
  130.         cout << "Введите бренд кафеля: ";
  131.         cin >> tile_2.brand;
  132.         cout << "Введите высоту кафеля: ";
  133.         cin >> tile_2.size_h;
  134.         cout << "Введите ширину кафеля: ";
  135.         cin >> tile_2.size_w;
  136.         cout << "Введите цену кафеля: ";
  137.         cin >> tile_2.price;
  138.  
  139.         cout << "\nИнформация о первом виде кафеля:" << endl;
  140.         tile_1.getData();
  141.         cout << "\nИнформацию о втором виде кафеля:" << endl;
  142.         tile_2.getData();
  143.     }
  144.     break;
  145.  
  146.     case 3:
  147.     {
  148.         Complex number;
  149.         cout << "Введите число: " << endl;
  150.         number.set_info();
  151.         cout << "\nЗначение числа: " << endl;
  152.         number.get_info();
  153.         number.abs();
  154.     }
  155.     break;
  156.  
  157.     case 4:
  158.     {
  159.         Vector vector_1, vector_2, vector_sum, vector_sub;
  160.         cout << "Введите первый вектор: " << endl;
  161.         vector_1.set_info();
  162.         cout << "Введите второй вектор: " << endl;
  163.         vector_2.set_info();
  164.  
  165.         cout << "\nЗначение координат первого вектора: " << endl;
  166.         vector_1.get_info();
  167.         cout << "\nЗначение координат второго вектора: " << endl;
  168.         vector_2.get_info();
  169.  
  170.         cout << "\nСумма координат первого и второго вектора: " << endl;
  171.         vector_sum.sum(vector_1, vector_2);
  172.         vector_sum.get_info();
  173.  
  174.         cout << "\nРазность координат первого второго вектора: " << endl;
  175.         vector_sub.sub(vector_1, vector_2);
  176.         vector_sub.get_info();
  177.  
  178.         cout << "\nМодуль первого вектора: ";
  179.         vector_1.abs();
  180.         cout << "\nМодуль второго вектора: ";
  181.         vector_2.abs();
  182.     }
  183.     break;
  184.     default:
  185.         break;
  186.     }
  187. }
  188.  
  189. void Child::set_info()
  190. {
  191.     cout << "Введите имя ребенка:";
  192.     cin >> name;
  193.     cout << "Введите фамилию ребенка: ";
  194.     cin >> surname;
  195.     cout << "Введите возраст ребенка: ";
  196.     cin >> age;
  197. }
  198.  
  199. void Child::get_info()
  200. {
  201.     cout << "Имя ребенка: " << name << endl;
  202.     cout << "Фамилия ребенка: " << surname << endl;
  203.     cout << "Возраст ребенка: " << age << endl;
  204. }
  205.  
  206. void Tiles::getData()
  207. {
  208.     cout << "Бренд кафеля" << brand << endl;
  209.     cout << "Высота кафеля" << size_h << endl;
  210.     cout << "Ширина кафеля" << size_w << endl;
  211.     cout << "Цена кафеля" << price << endl;
  212. }
  213.  
  214. void Complex::set_info()
  215. {
  216.     cout << "Введите X: ";
  217.     cin >> x;
  218.     cout << "Введите Y: ";
  219.     cin >> y;
  220. }
  221.  
  222. void Complex::get_info()
  223. {
  224.     cout << "Значение X: " << x << endl;
  225.     cout << "Значение Y: " << y << endl;
  226. }
  227.  
  228. void Complex::abs()
  229. {
  230.     float result = sqrt(x * x + y * y);
  231.     cout << "\nМодуль числа равен: " << result << endl;
  232. }
  233.  
  234. void Vector::set_info()
  235. {
  236.     cout << "Введите X: ";
  237.     cin >> x;
  238.     cout << "Введите Y: ";
  239.     cin >> y;
  240.     cout << "Введите Z: ";
  241.     cin >> z;
  242. }
  243.  
  244. void Vector::get_info()
  245. {
  246.     cout << "Значение X: " << x << endl;
  247.     cout << "Значение Y: " << y << endl;
  248.     cout << "Значение Z: " << z << endl;
  249. }
  250.  
  251. void Vector::sum(Vector a, Vector b)
  252. {
  253.     x = a.x + b.x;
  254.     y = a.y + b.y;
  255.     z = a.z + b.z;
  256. }
  257.  
  258. void Vector::sub(Vector a, Vector b)
  259. {
  260.     x = a.x - b.x;
  261.     y = a.y - b.y;
  262.     z = a.z - b.z;
  263. }
  264.  
  265. void Vector::abs()
  266. {
  267.     float result = sqrt(x*x + y * y + z * z);
  268.     cout << result << endl;
  269. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement