Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Circle {
- private:
- double radius;
- public:
- Circle(double r) : radius(r) {}
- // Перегруженный оператор ==
- bool operator==(const Circle& other) const {
- return radius == other.radius;
- }
- // Перегруженный оператор >
- bool operator>(const Circle& other) const {
- return radius > other.radius;
- }
- // Перегруженный оператор +=
- Circle& operator+=(double increment) {
- radius += increment;
- return *this;
- }
- // Перегруженный оператор -=
- Circle& operator-=(double decrement) {
- radius -= decrement;
- return *this;
- }
- // Геттер для радиуса
- double getRadius() const {
- return radius;
- }
- };
- int main() {
- Circle c1(5.0);
- Circle c2(3.0);
- Circle c3(5.0);
- // Проверка на равенство радиусов двух окружностей (операция ==)
- if (c1 == c2) {
- std::cout << "c1 and c2 have equal radii." << std::endl;
- } else {
- std::cout << "c1 and c2 have different radii." << std::endl;
- }
- if (c1 == c3) {
- std::cout << "c1 and c3 have equal radii." << std::endl;
- } else {
- std::cout << "c1 and c3 have different radii." << std::endl;
- }
- // Сравнение длин двух окружностей (операция >)
- if (c1 > c2) {
- std::cout << "c1 has a greater radius than c2." << std::endl;
- } else {
- std::cout << "c1 does not have a greater radius than c2." << std::endl;
- }
- // Пропорциональное изменение размеров окружности (операция += и -=)
- c1 += 2.0; // Увеличение радиуса на 2
- c2 -= 1.0; // Уменьшение радиуса на 1
- std::cout << "New radius of c1: " << c1.getRadius() << std::endl;
- std::cout << "New radius of c2: " << c2.getRadius() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement