SOURCE FILE: EX0302.CPP


// Example 3.2. Program to return the floor space for a room   
   
#include <iostream.h>
   
int main(void)   
{   
   void directions(void);  // prototypes
   int  GetDim(void);   
   int  area(int, int);   
   
   int dim1,               // one dimension of the room     
       dim2,               // another dimension of the room 
       FloorSpace;         // area of floor in room         
   
   directions();   
   
   dim1 = GetDim();   
   dim2 = GetDim();   
   
   FloorSpace = area(dim1, dim2);   
   
   cout << "\nThe floor space is " << FloorSpace 
        << " square feet.\n";
   
   return 0;
}   
   
//   
// Function to print program directions   
// Pre:  none   
// Post: Program directions have been printed.   
//    
   
void directions(void)   
{   
   cout << "This program will give you the floor space ";
   cout << "in square feet\n";
   cout << "for a room of your choosing.\n\n";
}   
      
//   
// Function to prompt the user for one dimension   
// of a floor and to return that dimension   
// Pre:  The user enters an integer dimension.   
// Post: The function has returned that dimension.   
//    
   
int GetDim(void)   
{   
   int dimension;      // one dimension of floor 
   
   cout << "Type one dimension of the floor in feet:  ";
   cin  >> dimension;
   return dimension;   
}   
   
//   
// Function to calculate the floor space (area of the floor)   
// given two dimensions (length and width).   
// Pre:  dim1 and dim2 are integer dimensions.   
// Post: The function has returned the integer floor space.   
//    
   
int area(int dim1, int dim2)   
{   
   return (dim1 * dim2);   
}