Добавил:
Рад, если кому-то помог Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
1
Добавлен:
01.11.2025
Размер:
2.28 Кб
Скачать
#include <iostream>
#include <string>
#include <locale>
using namespace std;

class Point {
protected:
    double x, y;
public:
    Point(double x_val = 0, double y_val = 0) : x(x_val), y(y_val) {}
    virtual void draw() const {
        cout << "Точка в (" << x << ", " << y << ")" << endl;
    }
    virtual void erase() const {
        cout << "Стираем точку в (" << x << ", " << y << ")" << endl;
    }
    virtual void move(double dx, double dy) {
        x += dx;
        y += dy;
    }
    virtual ~Point() {}
};

class Circle : public Point {
protected:
    double radius;
public:
    Circle(double x_val = 0, double y_val = 0, double r = 1) 
        : Point(x_val, y_val), radius(r) {}
    
    void draw() const override {
        cout << "Окружность в (" << x << ", " << y << ") с радиусом " << radius << endl;
    }
    
    void erase() const override {
        cout << "Стираем окружность в (" << x << ", " << y << ")" << endl;
    }
    
    void changeRadius(double new_radius) {
        radius = new_radius;
    }
};

class CircleWithText : public Circle {
    string text;
public:
    CircleWithText(double x_val = 0, double y_val = 0, double r = 1, const string& t = "") 
        : Circle(x_val, y_val, r), text(t) {}
    
    void draw() const override {
        cout << "Окружность с текстом в (" << x << ", " << y << "), радиус: " 
             << radius << ", текст: \"" << text << "\"" << endl;
    }
    
    void erase() const override {
        cout << "Стираем окружность с текстом в (" << x << ", " << y << ")" << endl;
    }
    
    void changeText(const string& new_text) {
        text = new_text;
    }
};

int main() {
    setlocale(LC_ALL, "ru_RU.UTF-8");
    
    Point point(1, 2);
    Circle circle(3, 4, 5);
    CircleWithText circleText(6, 7, 8, "Привет!");
    
    point.draw();
    circle.draw();
    circleText.draw();
    
    circleText.changeRadius(10);
    circleText.changeText("Новый текст");
    circleText.move(2, 3);
    
    cout << "После изменений: ";
    circleText.draw();
    
    return 0;
}
Соседние файлы в папке Лаба5