Advertisement
Eriss69

3.STRUCT

Apr 9th, 2020
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <string>
  4. #include <math.h>
  5. #include <cmath>
  6. struct Circle
  7. {
  8.     float r;
  9. }; // Circumference=2*pi*r
  10. //area=pi*r*r
  11. struct Rectangle
  12. {
  13.     float a;
  14.     float b;
  15. };//Circumference =2a +2b;
  16. //area = ab;
  17. struct Triangle
  18. {
  19.     float a;
  20.     float h;
  21.     float b;
  22.     float c;
  23. };// Circumference= L=a+b+c
  24. //area= 1/2*a*h
  25. double Circumference(const Triangle& triangle)
  26. {
  27.     return triangle.a + triangle.b + triangle.c;
  28. }
  29. double area(const Triangle& triangle)
  30. {
  31.     return 0.5* triangle.a * triangle.h;
  32. }
  33. double Circumference(const Rectangle& rectangle)
  34. {
  35.     return (2 * rectangle.a) + (2 * rectangle.b);
  36. }
  37. double area(const Rectangle& rectangle)
  38. {
  39.     return rectangle.a * rectangle.b;
  40. }
  41. Triangle readTriangle()
  42. {
  43.     Triangle h;
  44.     std::cout << "a=";
  45.     std::cin >> h.a;
  46.     std::cout << "h=";
  47.     std::cin >> h.h;
  48.     std::cout << "b=";
  49.     std::cin >> h.b;
  50.     std::cout<<"c=";
  51.     std::cin >> h.c;
  52.     return h;
  53. }
  54. void handleTriangle()
  55. {
  56.     Triangle h = readTriangle();
  57.     std::cout << "Circumference = " << Circumference(h);
  58.     std::cout << std::endl;
  59.     std::cout << "Area=" << area(h);
  60. }
  61. Rectangle readRectangle()
  62. {
  63.     Rectangle r;
  64.     std::cout << "a =";
  65.     std::cin >> r.a;
  66.     std::cout << "b=";
  67.     std::cin >> r.b;
  68.     return r;
  69.  
  70. }
  71. void handleRectangle()
  72. {
  73.     Rectangle r = readRectangle();
  74.     std::cout << "Circumference: " << Circumference(r);
  75.     std::cout << std::endl;
  76.     std::cout << "Area:" << area(r);
  77. }
  78. double Circumference(const Circle& circrle)
  79. {
  80.     return 2 * M_PI * circrle.r;
  81.  
  82. }
  83. double area(const Circle& circle)
  84. {
  85.     return M_PI * circle.r * circle.r;
  86. }
  87. Circle readCircle()
  88. {
  89.     Circle c;
  90.     std::cout << "r = ";
  91.     std::cin >> c.r;
  92.  
  93.     return c;
  94. }
  95. void handleCircle()
  96. {
  97.     Circle c = readCircle();
  98.     std::cout << "Circumference: " << Circumference(c);
  99.     std::cout << std::endl;
  100.     std::cout << "Area: " << area(c);
  101. }
  102. void choose()
  103. {
  104.     int answer;
  105.     std::cout << "[1] Circle" << std::endl;
  106.     std::cout << "[2]rectangle" << std::endl;
  107.     std::cout << "[3]triangle" << std::endl;
  108.     std::cout << "enter:";
  109.     std::cin >> answer;
  110.     switch (answer)
  111.     {
  112.     case 1:
  113.     {
  114.         handleCircle();
  115.         break;
  116.     }
  117.     case 2:
  118.     {
  119.         handleRectangle();
  120.         break;
  121.     }
  122.     case 3:
  123.     {
  124.         handleTriangle();
  125.         break;
  126.  
  127.     }
  128.     }
  129. }
  130. int main()
  131. {
  132.     choose();
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement