Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sp0203.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- class Rectangle {
- double sideA, sideB;
- public:
- Rectangle() :sideA(0), sideB(0){};
- Rectangle(double a, double b) : sideA(a), sideB(b) {}
- Rectangle(const Rectangle &r);
- void get_sides(double *a, double *b);
- void set_sides(double a, double b);
- double get_area() { return sideA*sideB; }
- double get_perimeter() { return 2*(sideA+sideB); }
- void show();
- Rectangle operator+(Rectangle &Rect);
- Rectangle operator-(Rectangle &Rect);
- Rectangle operator=(const Rectangle &Rect);
- bool operator<(Rectangle &Rect)
- {
- return get_area() < Rect.get_area();
- }
- bool operator>(Rectangle &Rect)
- {
- return get_area() > Rect.get_area();
- }
- bool operator==(Rectangle &Rect)
- {
- return get_area() == Rect.get_area();
- }
- bool operator!=(Rectangle &Rect)
- {
- return get_area() == Rect.get_area();
- }
- };
- Rectangle::Rectangle(const Rectangle &r)
- {
- sideA = r.sideA;
- sideB = r.sideB;
- }
- void Rectangle::get_sides(double *a, double *b)
- {
- *a = sideA;
- *b = sideB;
- }
- void Rectangle::set_sides(double a, double b)
- {
- if (a < 0 || b < 0)
- throw "Side is negative";
- sideA = a;
- sideB = b;
- }
- void Rectangle::show()
- {
- std::cout << "Side A=" << sideA << ", side B=" << sideB << std::endl;
- }
- Rectangle Rectangle::operator+(Rectangle &Rect)
- {
- return Rectangle(fmax(sideA, Rect.sideA), fmax(sideB, Rect.sideB));
- }
- Rectangle Rectangle::operator-(Rectangle &Rect)
- {
- return Rectangle(fmin(sideA, Rect.sideA), fmin(sideB, Rect.sideB));
- }
- Rectangle Rectangle::operator=(const Rectangle &Rect)
- {
- if (this == &Rect)
- return *this;
- sideA = Rect.sideA;
- sideB = Rect.sideB;
- return *this;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- Rectangle r1(20, 10),r2(r1);
- r1.show();
- cout << r1.get_area();
- if (r1 == r2) r2.show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement