# programming

posted by .

Write a program that asks for the length and width of two rectangles. The program should tell the user which rectangles has the greater area, or if the area are the same.

• programming -

We do not write code here.

Also, as there are many programming languages, it would help to specify the language that you are suppose to use.

• programming -

#include <iostream>
using namespace std;

class Rectangle
{
private:
int width, height;
public:
Rectangle(int width=0, int height=0) : width(width), height(height) { }
int getWidth() {
return width;
}
int getHeight() {
return height;
}
};

istream& operator>> (istream& is, Rectangle& r) {
is >> r.width >> r.height;
return is;
}

ostream& operator<< (ostream& os, Rectangle& r) {
os << r.getWidth() << " " << r.getHeight();
return os;
}

Rectangle operator+ (Rectangle& r1, Rectangle& r2) {
int w = r1.getWidth() * r2.getHeight() + r2.getWidth() * r1.getHeight();
int h = r1.getWidth() * r2.getHeight();
return Rectangle(w, h);
}

Rectangle operator- (Rectangle& r1, Rectangle& r2) {
int w = r1.getWidth() * r2.getHeight() - r2.getWidth() * r1.getHeight();
int h = r1.getWidth() * r2.getHeight();
return Rectangle(w, h);
}

bool operator< (Rectangle& r1, Rectangle&r2) {
return r1.getWidth() * r2.getHeight() < r2.getWidth() * r1.getHeight();
}

bool operator== (Rectangle& r1, Rectangle&r2) {
return r1.getWidth() * r2.getHeight() = r2.getWidth() * r1.getHeight();
}

int main() {
int w, h;

for (int i=0; i<3; i++) {
cout << "Enter width and height of the first rectangle: ";
cin >> w >> h;
Rectangle r1(w,h);

cout << "Enter width and height of the second rectangle: ";
cin >> w >> h;
Rectangle r2(w,h);

if (r1 == r2)
cout << "The area of both rectangles are the SAME!" << endl << endl;
else if (r1 > r2)
cout << "The area of the first rectangle is LARGER!" << endl << endl;
else
cout << "The area of the first rectangle is SMALLER!" << endl << endl;
}
return 0;
}

## Similar Questions

1. ### math

Recognize that rectangles that have the same area can have different perimenters. Do rectangles with the same area necessarily have the same perimeter?
2. ### math

Three rectangles have exactly the same area. The dimensions of each rectangle (as length and width) are a and b; a – 3 and b + 2; and a + 3 and b – 1. Find the area of the rectangles.
3. ### math

Three rectangles have exactly the same area. The dimensions of each rectangle (as length and width) are a and b; a – 3 and b + 2; and a + 3 and b – 1. Find the area of the rectangles.
4. ### math

Three rectangles have exactly the same area. The dimensions of each rectangle (as length and width) are a and b; a – 3 and b + 2; and a + 3 and b – 1. Find the area of the rectangles.
5. ### Math

Three rectangles have exactly the same area. The dimensions of each rectangle (as length and width) are a and b; a – 3 and b + 2; and a + 3 and b – 1. Find the area of the rectangles.
6. ### Programming

Write a pseudocode program that asks the user for an integer between 1 and 12. The program is to calculate the times table for that number. So for example, if the user enters a 2, then the program has to calculate 2x1 and display the …
7. ### MATH Middle School

The area of two rectangles is 360 square centimeters. The length of the second rectangle is 12 cm greater than the first while its width is 5 cm less than the first. Find the difference of the perimeters of the two rectangles if the …
8. ### calculus(Lab)

Well, first graph the graph of f(x)=-1/10x^2 + 3 2. We are going to approximate the area between f and the x-axis from x = 0 to x = 4 using rectangles (the method of Riemann sums). This is not the entire area in the first quadrant, …
9. ### intro to computer programming

Write a program that asks the user to enter the number of packages purchased. The program should then display the amount of the discount (if any) and the total amount of the purchase after the discount. Your program should use a loop …
10. ### java programming

1. Time Calculator Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number …

More Similar Questions