Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
0
Добавлен:
16.06.2026
Размер:
21.59 Кб
Скачать

8.Написать три функции (объемы геометрических тел) для геометрических расчетов и оформить их в отдельном файле.

geometry_calculator.h:

#ifndef GEOMETRY_CALCULATOR_H
#define GEOMETRY_CALCULATOR_H

const double PI = 3.141592653589793;

// Прототипы функций
double calculateCylinderVolume(double radius, double height);
double calculateSphereVolume(double radius);
double calculateConeVolume(double radius, double height);

#endif  // GEOMETRY_CALCULATOR_H

geometry_calculator.cpp:

#include "geometry_calculator.h"


double calculateCylinderVolume(double radius, double height) {
    return PI * radius * radius * height;
}


double calculateSphereVolume(double radius) {
    return (4.0 / 3.0) * PI * radius * radius * radius;
}


double calculateConeVolume(double radius, double height) {
    return (1.0 / 3.0) * PI * radius * radius * height;
}

main.cpp:

#include <iostream>
#include "geometry_calculator.h"

int main() {
    double radius, height;

    
    std::cout << "Enter the radius of the cylinder: ";
    std::cin >> radius;
    std::cout << "Enter the height of the cylinder: ";
    std::cin >> height;

    double cylinderVolume = calculateCylinderVolume(radius, height);
    std::cout << "Volume of the cylinder: " << cylinderVolume << std::endl;

    std::cout << "Enter the radius of the sphere: ";
    std::cin >> radius;

    double sphereVolume = calculateSphereVolume(radius);
    std::cout << "Volume of the sphere: " << sphereVolume << std::endl;

    std::cout << "Enter the radius of the cone: ";
    std::cin >> radius;
    std::cout << "Enter the height of the cone: ";
    std::cin >> height;

    double coneVolume = calculateConeVolume(radius, height);
    std::cout << "Volume of the cone: " << coneVolume << std::endl;

    return 0;
}

Соседние файлы в папке Функции ( Решение)