Develop a flowchart and then write a menu-driven C++ program that uses several user-defined functions, overloaded functions, and references.

Question:

Develop a flowchart and then write a menu-driven C++ program that uses several user-defined functions, overloaded functions, and references.

Upon program execution, the screen will be cleared and the menu shown below will appear at the top of the screen and centered. The menu items are explained below.

                                Help                        Smallest                        Largest                       Quit

H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user how to interact with the program, type of data to be entered, and what results would the program produce. Each help screen should remain on the monitor until the user strikes any key. Once the user’s input is processed, the screen will be cleared and the menu is displayed again.

S or s ( for Smallest ) option will invoke the function named smallest( ) which will prompt the user for the two floats and calls the function findSmallest() which will compute and return the smallest number in the set. Once the smallest number is found, the function display() will be called (from the smallest() function) and displays the inputted numbers and the smallest using the format shown below.

n1 = xxx.xx, n2 = yy.yy and smallest is zzz.zz

where n1 is the first number and n2 is the second number. x, y, and z are place holders for the actual numbers. Note that two significant digits are required after the decimal point.

The function prototypes to be used are:

                void smallest(void);

     float      findSmallest(float f, float s);

     void display(float& f, float& s, float& small);

where f refers to the first number and s refers to the second number.

The results should stay on the screen with the following prompt, which will appear in the lower right hand corner of the screen:

                                                                     Strike any key to continue…

Once the user has entered a key, the screen will be cleared and the menu is displayed again.

Note: display() is an overloaded function.

L or l ( for Largest ) option will invoke the function named largest( ) which will prompt the user for the two doubles and calls the function findLargestt() which will compute and return the largest number in the set. Once the largest number is found, the function display() will be called (from the largest() function) and displays the inputted numbers and the smallest using the format shown below.

n1 = xxx.xxxx, n2 = yy.yyyy and largest is zzz.zzzz

where n1 is the first number and n2 is the second number. x, y, and z are place holders for the actual numbers. Note that four significant digits are required after the decimal point.

The function prototypes to be used are:

                void largest(void);

     double     findLargest(double f, double s);

     void display(double& f, double& s, double& large);

where f refers to the first number and s refers to the second number.

The results should stay on the screen with the following prompt, which will appear in the lower right hand corner of the screen:

                                                                                                                                Strike any key to continue…

Once the user has entered a key, the screen will be cleared and the menu is displayed again.

Note: display() is an overloaded function.

Q or q (for Quit) option will clear the screen and returns the control to the Visual Studio IDE.

Try your program with the following data sets and make sure the sample runs include them for the smallest and the largest.

set 1 :   30.0, 60.0                                             set 2 :   30.5, -120.0

set 3 : 0.0, 0.0                                                    set 4 :   -60.8, -32.6

set 5 :   -10.0, -10.0                                           set 6 :   150.0, 150.0

Answer:

#include    <iostream>
#include    <iomanip>
#include    <cstdlib>
using namespace std;



extern  char    menu(void);
    void    smallest(void);
    float   findsmallest(float f, float s);
    void    display (float f, float s, float& small);
    void    largest(void);
    double   findlargest(double f, double s);
    void    display (double f, double s, double& large);

int main(void)
{
     float n1, n2;
     char op;


     while(1)
     {
          op = menu();
          switch(op)
          {
            case 'h' :
            case 'H' :
                    cout << "\t How to Operate Program\n"
                         << "Select any of the menu items\n" 
                         << "h or H for Help\n"
                         << "s or S for Smallest\n"
                         << "Option will find the smallest number of two numbers\n"
                         << "l or L for Largest\n"
                         << "Option will find the largest number of two numbers\n"
                         << "q or Q will terminate program\n";
            case 's' :
            case 'S' :
                    cout << "\n\nPlease input values for n1 and n2,";

                    cin >> n1 >> n2;
                    findsmallest (n1, n2);
                    break;
            case 'l' :
            case 'L' :
                    cout << "\n\nPlease input values for n1 and n2,";

                    cin >> n1 >> n2;
                    findlargest (n1, n2);
                    break;
          }
     }
    return EXIT_SUCCESS;
 }

    extern char menu(void)
    {  
        char menuOption;                                 
        int flag = 1;
        while(flag == 1)
        {  
            cout << "\th. Help\t\ts. Smallest\t\tl. Largest\t\tq. Quit\n\n\t\t\tmake"
                 << " your selection ==> ";
            cin >> menuOption;
            switch(menuOption)
            {
                case 'h' :
                case 'H' :
                case 's' :
                case 'S' :
                case 'l' :
                case 'L' :
                         flag = 0;
                         break;           
                case 'q':
                case 'Q':
                         cout << "\nFinished..." << endl;
                         exit(0);        
                default  :
                         cout << "\n\twrong choice, try again\n\n";            
            }             
        }    

        return menuOption;
    }
Click to Rate This Answer!
[Total: 0 Average: 0]

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.