Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- #include "iomanip"
- #include <string>
- #define _USE_MATH_DEFINES
- #include <math.h>
- using namespace std;
- //Фигура
- class Figure
- {
- protected:
- string Color;
- public:
- Figure(string color = "Red");
- virtual void Input() = 0;
- virtual void Output() = 0;
- virtual float Square() = 0;
- };
- Figure::Figure(string qq)
- {
- Color = qq;
- }
- //Круг
- class Circle : public Figure
- {
- public:
- int Radius;
- Circle(string color = "Blue", float radius = 20);
- void Input() override;
- void Output() override;
- float Square() override;
- };
- Circle::Circle(string color, float radius) : Figure(color)
- {
- Radius = radius;
- }
- void Circle::Input()
- {
- cout << "Введите цвет\n";
- cin >> Color;
- cout << "Введите радиус\n";
- cin >> Radius;
- cout << endl;
- }
- void Circle::Output()
- {
- cout << "Цвет: " << Color << endl;
- cout << "Радиус: " << Radius << endl;
- cout << "Площадь: " << Square() << endl;
- }
- float Circle::Square()
- {
- return M_PI * (Radius*Radius);
- }
- //Прямоугольник
- class Pr : public Figure
- {
- public:
- float Width;
- float Length;
- Pr(string color = "Green", float width = 40, float length = 35);
- void Input() override;
- void Output() override;
- float Square() override;
- };
- Pr::Pr(string color, float width, float length) : Figure(color)
- {
- Width = width;
- Length = length;
- }
- void Pr::Input()
- {
- cout << "Введите цвет\n";
- cin >> Color;
- cout << "Введите длину\n";
- cin >> Length;
- cout << "Введите ширину\n";
- cin >> Width;
- }
- void Pr::Output()
- {
- cout << "Цвет: " << Color << endl;
- cout << "Длина: " << Length << endl;
- cout << "Ширина: " << Width << endl;
- cout << "Площадь: " << Square() << endl;
- }
- float Pr::Square()
- {
- return Width * Length;
- }
- //Параллелипипед
- class Parall : public Pr {
- private:
- string Type;
- float Height;
- public:
- Parall(string color = "Green", float width = 20, float length = 35, string type = "Прямоугольный", float height = 35);
- void Input() override;
- void Output() override;
- float Square() override;
- };
- Parall::Parall(string color, float width, float length, string type, float height) : Pr(color, width, length) {
- Type = type;
- }
- void Parall::Input()
- {
- Pr::Input();
- cout << "Введите тип параллелепипеда [Прямоугольный 1| Куб 2]\n";
- int option = 0;
- cin >> option;
- switch (option)
- {
- case 1:
- Type = "Прямоугольный";
- cout << "Введите высоту параллелипеда" << endl;
- cin >> Height;
- break;
- case 2:
- Type = "Куб";
- break;
- default:
- Type = "Произвольный";
- break;
- }
- cout << endl;
- }
- void Parall::Output() {
- Pr::Output();
- cout << "Тип параллелипипеда: " << Type << endl << endl;
- cout << "Площадь: " << Square() << endl;
- }
- float Parall::Square() {
- if (Type == "Прямоугольный")
- return 2 * (Width*Length + Width * Height + Length * Height);
- else if (Type == "Куб")
- return 6 * (Width*Width);
- }
- //Цилиндр
- class Barrel : public Circle {
- private:
- string Type;
- public:
- float CHeight;
- Barrel(string name = "Black", float radius = 30, float height = 10, string type = "Круговой");
- void Input() override;
- void Output() override;
- float Square() override;
- };
- Barrel::Barrel(string color, float radius, float height, string type) : Circle(color, radius) {
- Type = type;
- CHeight = height;
- }
- void Barrel::Input() {
- Circle::Input();
- cout << "Введите высоту цилиндра\n";
- cin >> CHeight;
- cout << "Введите тип цилиндра [Круговой 1| Прямой 2| Наклонный 3]\n";
- int option = 0;
- cin >> option;
- switch (option)
- {
- case 1:
- Type = "Круговой";
- break;
- case 2:
- Type = "Прямой";
- break;
- case 3:
- Type = "Наклонный";
- break;
- default:
- Type = "Особый";
- break;
- }
- cout << endl;
- }
- void Barrel::Output() {
- Circle::Output();
- cout << "Высота: " << CHeight;
- cout << "Площадь: " << Square() << endl;
- }
- float Barrel::Square() {
- return 2*M_PI*Radius*(CHeight + Radius);
- }
- //Вывести доступные опции
- void ShowOptions() {
- cout << endl;
- cout << "[1] Circle - круг " << endl;
- cout << "[2] Pr - прямоугольник" << endl;
- cout << "[3] Barrel - цилиндр" << endl;
- cout << "[4] Parall - параллелипипед" << endl;
- cout << "0 - выход из программы" << endl << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- Figure *figure = nullptr;
- int option = 1;
- do {
- cout << "Введите тип фигуры:";
- ShowOptions();
- cin >> option;
- switch (option)
- {
- case 1:
- figure = new Circle();
- break;
- case 2:
- figure = new Pr();
- break;
- case 3:
- figure = new Barrel();
- break;
- case 4:
- figure = new Parall();
- break;
- case 0:
- cout << "Завершение программы" << endl;
- break;
- default:
- option = -1;
- cout << "Такой тип фигуры не найден" << endl;
- break;
- }
- if (option != -1 && option != 0) {
- figure->Input();
- figure->Output();
- delete figure;
- }
- } while (option != 0);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement