//Devin Scheu CS1A Chapter 4, P. 220, #4
//
/**************************************************************
*
* COMPARE AREAS OF TWO RECTANGLES
* ____________________________________________________________
* This program asks for the length and width of two rectangles
* and determines which has the greater area, or if they are
* equal.
*
* Computation is based on the formulas:
* area1 = length1 * width1
* area2 = length2 * width2
* ____________________________________________________________
* INPUT
* length1 : Length of the first rectangle (as a double)
* width1 : Width of the first rectangle (as a double)
* length2 : Length of the second rectangle (as a double)
* width2 : Width of the second rectangle (as a double)
*
* OUTPUT
* message : Indicates which rectangle has the greater area or if they are equal
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
//Variable Declarations
double length1; //INPUT - Length of the first rectangle (as a double)
double width1; //INPUT - Width of the first rectangle (as a double)
double length2; //INPUT - Length of the second rectangle (as a double)
double width2; //INPUT - Width of the second rectangle (as a double)
double area1; //PROCESSING - Area of the first rectangle
double area2; //PROCESSING - Area of the second rectangle
string message; //OUTPUT - Indicates which rectangle has the greater area or if they are equal
//Prompt for Input
cout << "Enter the length of the first rectangle: ";
cin >> length1;
cout << "\nEnter the width of the first rectangle: ";
cin >> width1;
cout << "\nEnter the length of the second rectangle: ";
cin >> length2;
cout << "\nEnter the width of the second rectangle: ";
cin >> width2;
//Calculate Areas
area1 = length1 * width1;
area2 = length2 * width2;
//Determine Comparison
if (area1 > area2) {
message = "The first rectangle has the greater area.";
} else if (area2 > area1) {
message = "The second rectangle has the greater area.";
} else {
message = "The areas are the same.";
}
//Output Result
cout << fixed << setprecision(2);
cout << "\n";
cout << left << setw(25) << "First Rectangle Length:" << right << setw(15) << length1 << endl;
cout << left << setw(25) << "First Rectangle Width:" << right << setw(15) << width1 << endl;
cout << left << setw(25) << "Second Rectangle Length:" << right << setw(15) << length2 << endl;
cout << left << setw(25) << "Second Rectangle Width:" << right << setw(15) << width2 << endl;
cout << left << setw(25) << "First Area:" << right << setw(15) << area1 << endl;
cout << left << setw(25) << "Second Area:" << right << setw(15) << area2 << endl;
cout << left << setw(25) << "Result:" << right << setw(15) << message << endl;
} //end of main()