SOURCE FILE: floorSpace03.cpp
/*
Program to display the floor space for a room
Fleshed-out design.
* Now there are declarations of the variables
used in the main function
* Now there are prototypes for the functions
+ prototypes tell
- what data type, if any the function returns
- the name of the function
- the number and types of parameters required by the function
* Now there are also definitions of the functions
+ the function definitions have only STUB CODE,
not FINISHED CODE.
+ STUB CODE is place-holder code that allows
us to compile and run the program for the purpose
of checking that the main function is correct
* As indicated above, this program can be compiled and executed.
The result of doing that is to get output that shows that the
program is calling the functions and performing its other
actions in the right order, and using the right logic and
flow of control.
*/
#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 length, int width);
/* 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 an 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 */
/* ================================== */
/* ================================== */
/* ALL ARE STUBS */
/* ================================== */
/* ================================== */
void directions(void)
{
// stub output so we will know when the function runs
cout << "Entering function 'directions' \n" ;
}
/* ================================== */
/* ================================== */
int GetDim(void)
{
// stub output so we will know when the function runs
cout << "Entering function 'GetDim' \n" ;
/* return SOMETHING, so that the caller gets a value
back from the function. */
return 39 ; // arbitrary return value
}
/* ================================== */
/* ================================== */
int area(int dim1, int dim2)
{
// stub output so we will know when the function runs
cout << "Entering function 'area' \n" ;
/* stub output tells what the values of the
parameters are, so we know that the function
received the correct thing from the caller */
cout << "dim1 is: " << dim1 << endl ;
cout << "dim2 is: " << dim2 << endl ;
/* return SOMETHING, so that the caller gets a value
back from the function. */
return 42 ;// arbitrary return value
}
/* ================================== */