Advertisement
P1punGorbach

laba programulirovanie 1

Dec 9th, 2022
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. /*Создать класс, описывающий круг.Определить площадь круга.Определить площадь кольца, образованного двумя концентрическими кругами.
  2. Создать класс - наследник, описывающий конус.Определить ребро куба, имеющего объем, совпадающий с объемом этого конуса.*/
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. class circle
  10. {
  11.  
  12. public:
  13.     float rad;
  14.     circle(float value)
  15.     {
  16.         rad = value;
  17.     }
  18.     float circlear()
  19.     {
  20.         float area;
  21.         area = 3.14 * rad * rad;
  22.         return area;
  23.     }
  24. };
  25.  
  26. class cone : public circle {
  27. public:
  28.     float height;
  29.     cone(float value, float value1) : circle(value)
  30.     {
  31.         height = value1;
  32.     }
  33.  
  34.     float conearea() {
  35.         float circar = circlear();
  36.         float conar = 0.334 * circar * height;
  37.         return conar;
  38.     }
  39. };
  40.  
  41. void main()
  42. {
  43.     while (1) {
  44.         int number;
  45.  
  46.         cout << "1. Find circle area" << endl;
  47.         cout << "2. Find ring area" << endl;
  48.         cout << "3. Find edge of the cube" << endl;
  49.         cout << "Choose number: ";
  50.         cin >> number;
  51.         switch (number) {
  52.         case 1: {
  53.             float radius111, area;
  54.             cout << "Enter radius: " << endl;
  55.             cin >> radius111;
  56.             circle cir3(radius111);
  57.             area = cir3.circlear();
  58.             cout << "Circle area: " << area << endl;
  59.             break;
  60.         }
  61.         case 2: {
  62.             float radius1, radius2, ringarea;
  63.             cout << "Enter radius1: ";
  64.             cin >> radius1;
  65.             cout << endl << "Enter radius2: ";
  66.             cin >> radius2;
  67.             circle cir1(radius1);
  68.             circle cir2(radius2);
  69.             ringarea = cir1.circlear() - cir2.circlear();
  70.             cout << "Ring area: " << abs(ringarea) << endl;
  71.             break;
  72.         }
  73.         case 3: {
  74.             float radius11, height1, sqar;
  75.             cout << "Enter radius: ";
  76.             cin >> radius11;
  77.             cout << endl << "Enter height: ";
  78.             cin >> height1;
  79.             cone cil1(radius11, height1);
  80.             sqar = cbrt(cil1.conearea());
  81.             cout << "Edge of the cube: " << sqar << endl;
  82.             break;
  83.         }
  84.         default:
  85.             cout << "Wrong number";
  86.             break;
  87.         }
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement