Advertisement
Infiniti_Inter

2. 1)2)

Nov 13th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <exception>
  5. using namespace std;
  6.  
  7.  
  8.  
  9. ifstream in("input.txt");
  10. ofstream out("output.txt");
  11.  
  12.  
  13. class Rectangle {
  14.     int a;
  15.     int b;
  16. public:
  17.  
  18.  
  19.     void Print()
  20.     {
  21.         out << "A = " << a << ", B = " << b << '\n';
  22.     }
  23.     int Perimeter() {
  24.         return 2 * (a + b);
  25.     }
  26.     int Area() {
  27.         return a * b;
  28.     }
  29.     void setA(int value) {
  30.         this->a = value;
  31.     }
  32.     void setB(int value) {
  33.         this->b = value;
  34.     }
  35.     bool isSquare() {
  36.         return (a == b);
  37.     }
  38.    
  39.    
  40.     const Rectangle operator++();
  41.     const Rectangle operator--();
  42.  
  43.    
  44. };
  45. const Rectangle Rectangle::operator++()
  46. {
  47.     this->a++;
  48.     this->b++;
  49.     return *this;
  50. }
  51.  
  52. const Rectangle Rectangle::operator--()
  53. {
  54.     this->a--;
  55.     this->b--;
  56.     return *this;
  57. }
  58. int main()
  59. {
  60.     Rectangle a;
  61.     a.setA(10);
  62.     a.setB(15);
  63.     a.Print();
  64.     if (a.isSquare())
  65.         out << "This is square\n";
  66.     else
  67.         out << "This isn't square\n";
  68.     out << "Area = " << a.Area() << endl;
  69.     out << "Perimeter = " << a.Perimeter() << endl;
  70.    
  71.     --a;
  72.  
  73.     a.Print();
  74.     if (a.isSquare())
  75.         out << "This is square\n";
  76.     else
  77.         out << "This isn't square\n";
  78.     out << "Area = " << a.Area() << endl;
  79.     out << "Perimeter = " << a.Perimeter() << endl;
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement