//Perimeter and Area
//October 22 2007
//Computes the total perimeter and area, when the user inputs the width and length of a rectangle.
#include<iostream.h>
//Function: get_data
//Stores the width and length from the user's input
//Precondition: None
//Postcondiction: Two values, width and length
void get_data (double & rectWidth, double & rectLength);
//Function: Area
//Computes Area, using given width and length
//Precondiction: Two numbers, width and length
//Postcondiction: A number representing the rectangle's area
double rectArea (double rectWidth, rectLength);
//Function: Perimeter
//Computes perimeter, using given width and length
//Precondiction: Two numbers, width and length
//Postcondiction: A number representing the rectangle's perimeter
double rectPerimeter (double rectWidth, rectLength);
//Function: printResults
//Prints the results of both functions
//Precondiction: Four numbers, width, length, area, and perimeter
//Postcondiction: None
void printResults(double rectWidth, double rectLength, double area, double perimeter);
int main()
{
//Variable Identifier
double area, perimeter, rectWidth, rectLength;
//Functions to get input
get_data (rectWidth, rectLength);
//Functions to solve problems
area = rectArea (rectWidth, rectLength);
perimeter = rectPerimeter (rectWidth, rectLength);
//Functions to print
printResults(rectWidth, rectLength, area, perimeter);
return 0;
}
//Function: get_data
//Stores the width and length from the user's input
//Precondition: None
//Postcondiction: Two values, width and length
void get_data (double & rectWidth, double & rectLength);
{
//Ask the user for width and length
cout <<"Input the rectangle's width and press enter.";
cin >> rectWidth;
cout <<"Input the rectangle's length and press enter.";
cin >> rectLength;
}
//Function: Area
//Computes Area, using given width and length
//Precondiction: Two real numbers
//Postcondiction: A real number representing the rectangle's area
double rectArea (double rectWidth, rectLength);
{
return rectWidth * rectLength;
}
//Function: Perimeter
//Computes perimeter, using given width and length
//Precondiction: Two numbers, width and length
//Postcondiction: A number representing the rectangle's perimeter
double rectPerimeter (double rectWidth, rectLength);
{
return (rectWidth * 2 + rectLength * 2);
}
//Function: printResults
//Prints the results of both functions
//Precondiction: Four numbers, width, length, area, and perimeter
//Postcondiction: None
void printResults(double rectWidth, double rectLength, double area, double perimeter);
{
cout << "A length of "<< rectLength << endl <<" and with a width of "<< rectWidth << endl;
cout << "An area of "<< rectArea << endl" and an perimeter of "<< rectArea << endl;
}