Advertisement
plarmi

workcpp_3_1

Jun 9th, 2023
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class ShapeAreaCalculator {
  4. public:
  5.     static double calculateTriangleAreaBySides(double a, double b, double c) {
  6.         double p = (a + b + c) / 2.0;
  7.         return std::sqrt(p * (p - a) * (p - b) * (p - c));
  8.     }
  9.  
  10.     static double calculateTriangleAreaByBaseAndHeight(double base, double height) {
  11.         return 0.5 * base * height;
  12.     }
  13.  
  14.     static double calculateRectangleArea(double width, double height) {
  15.         return width * height;
  16.     }
  17.  
  18.     static double calculateSquareArea(double sideLength) {
  19.         return sideLength * sideLength;
  20.     }
  21.  
  22.     static double calculateRhombusArea(double diagonal1, double diagonal2) {
  23.         return 0.5 * diagonal1 * diagonal2;
  24.     }
  25.  
  26.     static int getCount() {
  27.         return count;
  28.     }
  29.  
  30. private:
  31.     static int count;
  32. };
  33.  
  34.  
  35. int main() {
  36.     int ShapeAreaCalculator::count = 0;
  37.     // Подсчет площади треугольника по сторонам
  38.     double triangleArea = ShapeAreaCalculator::calculateTriangleAreaBySides(3.0, 4.0, 5.0);
  39.     std::cout << "The area of the triangle is: " << triangleArea << std::endl;
  40.  
  41.     // Подсчет площади прямоугольника
  42.     double rectangleArea = ShapeAreaCalculator::calculateRectangleArea(5.0, 7.0);
  43.     std::cout << "The area of the rectangle is: " << rectangleArea << std::endl;
  44.  
  45.     // Подсчет площади квадрата
  46.     double squareArea = ShapeAreaCalculator::calculateSquareArea(6.0);
  47.     std::cout << "The area of the square is: " << squareArea << std::endl;
  48.  
  49.     // Подсчет площади ромба
  50.     double rhombusArea = ShapeAreaCalculator::calculateRhombusArea(8.0, 10.0);
  51.     std::cout << "The area of the rhombus is: " << rhombusArea << std::endl;
  52.  
  53.     // Вывод количества выполненных расчетов площадей
  54.     std::cout << "The number of area calculations is: " << ShapeAreaCalculator::getCount() << std::endl;
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement