Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class ShapeAreaCalculator {
- public:
- static double calculateTriangleAreaBySides(double a, double b, double c) {
- double p = (a + b + c) / 2.0;
- return std::sqrt(p * (p - a) * (p - b) * (p - c));
- }
- static double calculateTriangleAreaByBaseAndHeight(double base, double height) {
- return 0.5 * base * height;
- }
- static double calculateRectangleArea(double width, double height) {
- return width * height;
- }
- static double calculateSquareArea(double sideLength) {
- return sideLength * sideLength;
- }
- static double calculateRhombusArea(double diagonal1, double diagonal2) {
- return 0.5 * diagonal1 * diagonal2;
- }
- static int getCount() {
- return count;
- }
- private:
- static int count;
- };
- int main() {
- int ShapeAreaCalculator::count = 0;
- // Подсчет площади треугольника по сторонам
- double triangleArea = ShapeAreaCalculator::calculateTriangleAreaBySides(3.0, 4.0, 5.0);
- std::cout << "The area of the triangle is: " << triangleArea << std::endl;
- // Подсчет площади прямоугольника
- double rectangleArea = ShapeAreaCalculator::calculateRectangleArea(5.0, 7.0);
- std::cout << "The area of the rectangle is: " << rectangleArea << std::endl;
- // Подсчет площади квадрата
- double squareArea = ShapeAreaCalculator::calculateSquareArea(6.0);
- std::cout << "The area of the square is: " << squareArea << std::endl;
- // Подсчет площади ромба
- double rhombusArea = ShapeAreaCalculator::calculateRhombusArea(8.0, 10.0);
- std::cout << "The area of the rhombus is: " << rhombusArea << std::endl;
- // Вывод количества выполненных расчетов площадей
- std::cout << "The number of area calculations is: " << ShapeAreaCalculator::getCount() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement