Question: // function prototypes void addition(); void menu(); void selectiona(int &choice); int selectionb(); void subtraction(); /// write a small c++ program that // 1. display a

// function prototypes void addition(); void menu(); void selectiona(int &choice); int selectionb(); void subtraction(); /// write a small c++ program that // 1. display a menu for the user // 2. if the user chooses 1 addition happens // 3. if the user chooses 2 subtraction happens // 4. multiplication // 5. division

int main() { // declaration int choice; // code entry point // 1. display menu menu(); // 2. choose an operation // using selectiona selectiona(choice); // using selectionb choice = selectionb(); // 3. prompt for numbers switch (choice) { case 1: // call addition and break; addition(); break; case 2:// call subtaction subtraction(); break; //case 3: // call multiplication // multiplication(); break; //case 4: // call division // division(); break; default: cout << "invalid entry" << endl; } // display results return 0; }

// displays the user options // function type : void since the function only dumps some option to the screen void menu() { cout << "1. addition" << endl; // option 2 // option 3 // option 4 }

// selection function // a. it could be void but must have parameters by reference // b. or value returning function void selectiona(int &choice) { // what ever the user chooses it would be communicated to the caller by reference cout << "Please choose an option :" << endl; cin >> choice; } int selectionb() { // what ever the user chooses it would be communicated to the caller by function type int choice = 0; cout << "Please choose an option :" << endl; cin >> choice; return choice; }

// adds two numbers entered by the user void addition() { // declaratiopn double x, y, result; // collect values to add cout << "Please enter the numbers to add " << endl; cin >> x >> y; result = x + y; cout << "the sum is: "<

// subtracts two numbers entered by the user void subtraction() {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!