Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Rectangle {
- string name;
- int width, length, area;
- public:
- int getWidth() {return width;}
- int getLength() {return length;}
- int getArea() {return area;}
- string getName() {return name;}
- void print() {
- cout << name << ": " << width << " * " << length << " = " << getArea() << endl;
- }
- void setValues() {
- cout << "Enter the name of the rectangle. ";
- cin >> name;
- cout << "Enter the length of " << name << ". ";
- cin >> length;
- cout << "Enter the width of " << name << ". ";
- cin >> width;
- cout << endl;
- area = width * length;
- }
- void compare(Rectangle rect) {
- string res = area > rect.getArea()
- ? " is greater than "
- : area < rect.getArea()
- ? " is less than "
- : " is equal to ";
- cout << "\nThe area of " << name << res << rect.getName() << "\n\n";
- }
- };
- int main() {
- Rectangle rect1, rect2;
- rect1.setValues();
- rect2.setValues();
- rect1.print();
- rect2.print();
- rect1.compare(rect2);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement