//Zachary Abdollahi CS1A Chapter 6, P. 369, #2
//
/*******************************************************************************
*
* COMPUTE RECTANGLE AREA
*
* This program calculates the area based on user-supplied length and width
* values. The program is implemented using functions for modular design.
*
* Computation is based on the formula:
* Area = Length x Width
*
* INPUT
* length : Length of the rectangle in units
* width : Width of the rectangle in units
*
* OUTPUT
* area : Calculated area of the rectangle
*
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Function Prototypes
double getLength();
double getWidth();
double getArea(double length, double width);
void displayData(double length, double width, double area);
int main()
{
double length; // To hold the rectangle's length
double width; // To hold the rectangle's width
double area; // To hold the rectangle's area
// Get the rectangle's length from the user
length = getLength();
// Get the rectangle's width from the user
width = getWidth();
// Calculate the rectangle's area
area = getArea(length, width);
// Display the rectangle's data
displayData(length, width, area);
return 0;
}
/******************************************************************************
* getLength
* Prompts the user to enter the rectangle's length and returns *
* that value as a double.
*
*****************************************************************************/
double getLength()
{
double length;
cout << "Enter the length of the rectangle: ";
cin >> length;
return length;
}
/*****************************************************************************
* getWidth *
* Prompts the user to get the rectangle's width and returns *
* That value as a double. *
****************************************************************************/
double getWidth()
{
double width;
cout << "Enter the width of the rectangle: ";
cin >> width;
return width;
}
/****************************************************************************
* getArea *
* Accepts the rectangle's length and width as arguments and returns the *
* calculated area (length x width). *
***************************************************************************/
double getArea(double length, double width)
{
return length * width;
}
/****************************************************************************
* displayData *
* Accepts the rectangle's length, width, and area as arguments and *
* displays them formatted on the screen. *
***************************************************************************/
void displayData(double length, double width, double area)
{
cout << fixed << showpoint << setprecision(2);
cout << "\n--- Rectangle Details ---" << endl;
cout << "Length : " << length << endl;
cout << "Width : " << width << endl;
cout << "Area : " << area << endl;
}