/*******************************************************/
// R.A. Hillyard
// funDevelopProcess1.cpp
// October 2001
//
// Program to illustrate program development process using
// functions, stubs and drivers.
//
// The program will print a menu of choices (tasks) and call a
// function that will accomplish the task the user has chosen.
//
// We will need a function to print the menu, and one function for each task.
// For this example we will use three tasks - find the minimun of two integers,
// find the maximum of two doubles, or print a character to the screen "n" times.
//
// The first stage gives the function prototypes and implements the function to print the menu.
// At yhis point, the main program is written to test the printMenu function
// and is called a driver program.
//
// When we have the menu working and have tested all input combinations
// we are ready for phase 2
/*******************************************************/
#include<iostream>
using namespace std;
//function prototypes
char printMenu(); //print menu of choices
//pre condition : none
//post condition: will return an upper case char indicating the users choice
int min(int a, int b); //returns min of a and b
//pre condition : variables a and b will contain a valid integers
//post condition: will return the smallest of a and b
double max(double x, double y);//returns max of x and y
//pre condition : variables x and y will contain a valid doubles
//post condition: will return the largest of x and y
void printLine(char ch, int count);
//pre condition : variable ch will contain a printable character
// : variables count will contain a valid integers
//post condition: count ch's will be printed to the screen
int main()
{
char choice; //for user choice
while(true) //run program until user chooses to quit
{
choice = printMenu();
if(choice == 'Q') //break out of program to quit
break;
else //verify printMenu function returns a value
{
cout << "User choice is: "<< choice << endl;
}
}//end while true
return 0;
}//end main
/*******************************************************/
// printMenu - prints the menu of choices checks for valid input and
// returns the upper case version of the user choice as a char variable
/*******************************************************/
char printMenu()
{
char ch; //this variable is local to the function
do
{
cout << "\nWelcome to Function Developmen\n";
cout << "------------------------------------\n";
cout << "Choose one of the following\n";
cout << " M Find the smaller of two ints\n";
cout << " X Find the largest of two doubles\n";
cout << " P Print a Number of Characters\n";
cout << " Q To quit\n\n";
cout << "Enter your choice: ";
cin >> ch;
ch = toupper(ch);
}while(ch != 'M' && ch != 'X' && ch != 'P' && ch != 'Q');
return ch;
}
/********************Program output*****************
Welcome to Function Developmen
------------------------------------
Choose one of the following
M Find the smaller of two ints
X Find the largest of two doubles
P Print a Number of Characters
Q To quit
Enter your choice: M
User choice is: M
Welcome to Function Developmen
------------------------------------
Choose one of the following
M Find the smaller of two ints
X Find the largest of two doubles
P Print a Number of Characters
Q To quit
Enter your choice: x
User choice is: X
Welcome to Function Developmen
------------------------------------
Choose one of the following
M Find the smaller of two ints
X Find the largest of two doubles
P Print a Number of Characters
Q To quit
Enter your choice: f
Welcome to Function Developmen
------------------------------------
Choose one of the following
M Find the smaller of two ints
X Find the largest of two doubles
P Print a Number of Characters
Q To quit
Enter your choice: Q
*/