Advertisement
plarmi

workcpp_7_1

Jun 23rd, 2023
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Circle {
  4. private:
  5.     double radius;
  6.  
  7. public:
  8.     Circle(double r) : radius(r) {}
  9.  
  10.     // Перегруженный оператор ==
  11.     bool operator==(const Circle& other) const {
  12.         return radius == other.radius;
  13.     }
  14.  
  15.     // Перегруженный оператор >
  16.     bool operator>(const Circle& other) const {
  17.         return radius > other.radius;
  18.     }
  19.  
  20.     // Перегруженный оператор +=
  21.     Circle& operator+=(double increment) {
  22.         radius += increment;
  23.         return *this;
  24.     }
  25.  
  26.     // Перегруженный оператор -=
  27.     Circle& operator-=(double decrement) {
  28.         radius -= decrement;
  29.         return *this;
  30.     }
  31.  
  32.     // Геттер для радиуса
  33.     double getRadius() const {
  34.         return radius;
  35.     }
  36. };
  37.  
  38. int main() {
  39.     Circle c1(5.0);
  40.     Circle c2(3.0);
  41.     Circle c3(5.0);
  42.  
  43.     // Проверка на равенство радиусов двух окружностей (операция ==)
  44.     if (c1 == c2) {
  45.         std::cout << "c1 and c2 have equal radii." << std::endl;
  46.     } else {
  47.         std::cout << "c1 and c2 have different radii." << std::endl;
  48.     }
  49.  
  50.     if (c1 == c3) {
  51.         std::cout << "c1 and c3 have equal radii." << std::endl;
  52.     } else {
  53.         std::cout << "c1 and c3 have different radii." << std::endl;
  54.     }
  55.  
  56.     // Сравнение длин двух окружностей (операция >)
  57.     if (c1 > c2) {
  58.         std::cout << "c1 has a greater radius than c2." << std::endl;
  59.     } else {
  60.         std::cout << "c1 does not have a greater radius than c2." << std::endl;
  61.     }
  62.  
  63.     // Пропорциональное изменение размеров окружности (операция += и -=)
  64.     c1 += 2.0;  // Увеличение радиуса на 2
  65.     c2 -= 1.0;  // Уменьшение радиуса на 1
  66.  
  67.     std::cout << "New radius of c1: " << c1.getRadius() << std::endl;
  68.     std::cout << "New radius of c2: " << c2.getRadius() << std::endl;
  69.  
  70.     return 0;
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement