SOURCE FILE: 210_floorSpace04.cpp
/*
Program to display the floor space for a room
This is the finished program. The programmer finished the
functions one by one. Now all functions are complete and there is
no more STUB CODE.
Notice that the main function did not change from the form it had
in program "floorSpace03.cpp"
This is how top down design of a program is supposed to work. You
write the program one function at a time. You don't start working
on the next function until the previous one is finished and you
have verified through testing that it works correctly.
*/
#include <iostream>
using namespace std ;
/* ================================== */
/* FUNCTION DECLARATIONS (PROTOTYPES) */
/* ================================== */
void directions(void);
/* Print directions for using the program. */
int GetDim(void);
/* Prompt the user for one dimension of a floor and
return that dimension */
int area(int, int);
/* Return the floor space (area of the floor)
given two dimensions (length and width). */
/* ================================== */
/* ================================== */
int main(void)
{
int dim1, // one dimension of the room
dim2, // another dimension of the room
FloorSpace; // area of floor in room
/* Step One: Print Directions for the user */
directions() ;
/* Step Two: Get the dimensions of the floor from the user */
dim1 = GetDim();
dim2 = GetDim();
/* Step Three: IF either dimension is not positive
print and error message
ELSE Compute FloorSpace as product and
print the answer out for the user to see
*/
if ( (dim1 <= 0) || (dim2 <= 0) ) // invalid data
{
cout << "\nSorry, only positive dimensions are allowed.\n";
cout << "Please reexecute the program.\n\n";
}
else // valid data
{
FloorSpace = area(dim1, dim2);
cout << "\nThe floor space is " << FloorSpace << " square feet.\n\n";
}
return 0;
}
/* ================================== */
/* FUNCTION DEFINITIONS */
/* ================================== */
/* ================================== */
void directions(void)
{
cout << "\nThis program will give you the floor space ";
cout << "in square feet\n" ;
cout << "for a room of your choosing.\n\n" ;
}
/* ================================== */
/* ================================== */
int GetDim(void)
{
int dimension; // one dimension of floor
cout << "Type one dimension of the floor in feet: ";
cin >> dimension;
// pass the value obtained back to the caller
return dimension;
}
/* ================================== */
/* ================================== */
int area(int dim1, int dim2)
{
// calculate the value and pass it to the caller
return (dim1 * dim2);
}
/* ================================== */