< previous page page_346 next page >

Page 346
Let's write the two Level 1 modules as void functions, GetTemp and PrintActivity, so that the main function looks like the main module of our top-down design. Here is the resulting program.
//******************************************************************
// Activity program
// This program outputs an appropriate activity
// for a given temperature
//******************************************************************
#include <iostream.h>

void GetTemp( int& );                   // Function prototypes
void PrintActivity( int );

int main()
{
    int temperature;    // The outside temperature

    GetTemp(temperature);                   // Function call
    PrintActivity(temperature);             // Function call
    return 0;
}

//******************************************************************

void GetTemp( int& temp )                       // Reference parameter

// This function prompts for a temperature to be entered,
// reads the input value into temp, and echo-prints it

{
    cout << Enter the outside temperature: << endl;
    cin >> temp;
    cout << The current temperature is  << temp << endl;
}

//******************************************************************

void PrintActivity( int temp )              // Value parameter

// Given the value of temp, this function prints a message
// indicating an appropriate activity

{
    cout << The recommended activity is ;
    if (temp > 85)
        cout << swimming. << endl;
    else if (temp > 70)

 
< previous page page_346 next page >