SOURCE FILE: EX0301.CPP


//   
// Example 3.1.  Program to print the square of 97 as an    
// example, then to prompt the user for an integer and print    
// its square   
//    
   
#include <iostream.h>
   
int sqr(int);              // prototype
   
int main(void)   
{   
   void directions(void);  // prototype
   
   int num,                // input    
       square;             // square of num 
   
   directions();           // call to procedure 
   
   cout << "Please type an integer:  ";
   cin  >> num;
   
   square = sqr(num);      // call to function sqr 
   cout << "The square of " << num << " is " << square << ".\n";

   return 0;
}   
   
//    
// Print directions   
// Pre:  none   
// Post: Program directions have been printed.    
//    
   
void directions(void)   
{   
   cout << "This program will allow you to input an ";
   cout << "integer to square.\n";
   cout << "For example, if you input 97, ";
   cout << "the program will output " << sqr(97) << ".\n";
}   
   
//    
// Function to return the square of an integer   
// Pre:  num is an integer.   
// Post: The square of num has been returned.    
//    
   
int sqr(int num)   
{   
   return (num * num);   
}