/*******************************************************/ // R.A. Hillyard // funDevelopProcess3.cpp // October 2001 // // See funDevelopProcess1.cpp for project specs. // // The third stage implements the functions for each tasks // // When completed with this step we will have the complete // shell of a working program. Now we just need to implement // the function definitions one at a time /*******************************************************/ #include<iostream> using namespace std; //function prototypes char printMenu(); //print menu of choices int min(int a, int b); //returns min of a and b double max(double x, double y); //returns max of x and y void printLine(char ch, int count); //print count characters int main() { char choice; //char variable for user input int m, n; //int variables for user input double p, q; //double variables for user input while(true) //run program until user chooses to quit { choice = printMenu(); //print menu - get choice if(choice == 'Q') //if quit - break out of loop break; else if(choice == 'S') //else - call function to handle user request { cout << "Enter two integers: "; cin >> m >> n; cout << min(m,n) << " is the smallest\n"; } else if(choice == 'L') { cout << "Enter two doubles: "; cin >> p >> q; cout << max(p,q) << " is the largest\n"; } else if(choice == 'P') { cout << "Enter a character and how many to print:"; cin >> choice >> n; printLine(choice, n); } }//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 /*******************************************************/ 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 << " S Find the smaller of two ints\n"; cout << " L 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 != 'S' && ch != 'L' && ch != 'P' && ch != 'Q'); return ch; } /*******************************************************/ // min - will return the smaller of two ints /*******************************************************/ int min(int a, int b) { if(a <= b) return a; return b; }//end min /*******************************************************/ /*******************************************************/ // max - will return the larger of two doubles /*******************************************************/ double max(double x, double y) { if(x >= y) return x; return y; }//end max /*******************************************************/ /*******************************************************/ // printLine - will print count ch's to the screen /*******************************************************/ void printLine(char ch, int count) { for(int i = 0; i < count; i++) cout << ch << " "; cout << endl; } /********************Program output***************** Welcome to Function Developmen ------------------------------------ Choose one of the following S Find the smaller of two ints L Find the largest of two doubles P Print a Number of Characters Q To quit Enter your choice: s Enter two integers: 6 8 6 is the smallest Welcome to Function Developmen ------------------------------------ Choose one of the following S Find the smaller of two ints L Find the largest of two doubles P Print a Number of Characters Q To quit Enter your choice: S Enter two integers: 9 2 2 is the smallest Welcome to Function Developmen ------------------------------------ Choose one of the following S Find the smaller of two ints L Find the largest of two doubles P Print a Number of Characters Q To quit Enter your choice: s Enter two integers: 5 5 5 is the smallest Welcome to Function Developmen ------------------------------------ Choose one of the following S Find the smaller of two ints L Find the largest of two doubles P Print a Number of Characters Q To quit Enter your choice: q */