/* Filename: area3.cpp Author: Br. David Carlson Br. Isidore Minerd Date: January 4, 2000 Modified: June 26, 2000; August 19, 2001; July 16, 2009 This program asks the user to enter the length and width of a rectangle. It then computes and prints the area of the rectangle. Tested with: Microsoft Visual C++ 6.0 Microsoft Visual C++ .NET Microsoft Visual Studio g++ under Linux */ #include using namespace std; // Function prototypes: void Explanation(void); void GetValues(float & Length, float & Width); float ComputeArea(float Length, float Width); void PrintArea(float Area); int main(void) { float Length, Width, Area; Explanation(); GetValues(Length, Width); Area = ComputeArea(Length, Width); PrintArea(Area); return 0; } /* Given: Nothing. Task: To ask the user for the length and width of a rectangle and to return these values via the two parameters. Return: Length The length entered by the user. Width The width entered by the user. */ void GetValues(float & Length, float & Width) { cout << "Enter the rectangle's length: "; cin >> Length; cout << "Enter the rectangle's width: "; cin >> Width; } /* Given: Length The length of the rectangle. Width The width of the rectangle. Task: To compute the area of this rectangle. Return: The area in the function name. */ float ComputeArea(float Length, float Width) { return Length * Width; } /* Given: Nothing. Task: To print an explanation of what the program does. Return: Nothing. */ void Explanation(void) { cout << "This program computes the area of a rectangle." << endl; cout << "You will be prompted to enter both the length and width."; cout << endl << "Enter a real number (such as 4 or 2.89) for each."; cout << endl << "The program will then compute and print the area."; cout << endl << endl; } /* Given: Area The area of a rectangle. Task: To print Area. Return: Nothing. */ void PrintArea(float Area) { cout << "The area of the rectangle is: " << Area << endl << endl; }