Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

****Write in C++ Write a program that prints a menu. Based on the menu item selected by the user, the program should request the required

****Write in C++

Write a program that prints a menu. Based on the menu item selected by the user, the program should

request the required inputs from the user

call the appropriate function

print the functions result (from the main program NOT the function)

For example, if the user selections the sum function, then your program will ask them for two numbers to be added together, call the sum function, and finally print the sum functions result.

NOTE: In case of a typo on here make your output match the CA output!

The functions to implement are:

Simple Sum: Takes two int parameters and returns their sum. You will need to ask the user for two integers before calling this function.

Simple Division: Takes two int parameters and returns their floating point quotient (e.g., 10/3 returns 3.33). You will need to ask the user for two integers before calling this function.

Complex Division: Takes four int parameters, sums the first three parameters and then divides the sum by the fourth parameter. Returns the floating point quotient (e.g., (10 + 7 + 5) / 4 returns 5.5). You will need to ask the user for three integers and an integer divisor before calling this function.

Design:

It is imperative that each of these three operations be in their own function.

You should have an additional function that determines the operation type by printing the menu and then returning the integer that the user selects.

Your main program should use a switch statement that switches on the numeric integer entered by the user to select the correct function to call.

Your switch statement should also gather the inputs from the user before calling the function.

You will print the result returned by the function in your switch statement.

All function prototypes will be listed at the top of your code (after using namespace std;) and all your function definitions to be placed after main.

Part 2:

This part will give you more practice using functions such as the pre-defined functions and loops. Remember to include the cmath library, which contains the required pre-defined functions for this lab. Add the following functions to your menu and implement them:

Max: Takes three int parameters and returns their maximum value. You will need to ask the user for three integer values before calling this function.

Hypotenuse: Takes two floating point variables which are the lengths of the two sides of a triangle, and returns the floating point length of the third side of the triangle (the third side is called the hypotenuse). The equation for the length of the hypotenuse is a2 +b2=c2 You will need to ask the user for two floating point numbers before calling this function.

Cubic Equation: Takes four floating point coefficients for the cubic equation ax3+bx2+cx+d plus the value of x and returns the result. You must use the pow function to compute x3 and x2. You will need to ask the user for four coefficients (a, b, c, d) and the value of x before calling this function.

***IN ADDITION*** Add the ability to let the user repetitively enter menu options until they enter the numeric code for quit (for this phase it is item 9).

Part 3:

In this part you will get experience writing void functions that return more than one result via reference parameters. Write the following two functions and add them to your menu:

MinMax: Takes 5 parameters, the first three are user-supplied inputs and the last two are result parameters. Place the smallest of the first three parameters into the fourth parameter (min) and the largest of the three parameters in the fifth parameter (max). When MinMax returns, the calling function will examine the fourth and fifth arguments and find the values placed there by MinMax. For example, if MinMax were called as:

int x = 3, y = 10, z = 1;

int min, max;

MinMax(x, y, z, min, max);

then min will be 1 and max will be 10 when MinMax returns. You will need to ask the user for three integers before calling this function.

Modulus: Takes 4 int parameters, the first two are user-supplied inputs and the last two are the quotient and remainder. The quotient is calculated by dividing the first parameter by the second parameter. The remainder is whatever is left after division. For example, if Modulus were called as follows:

int x = 17, y = 3;

int quotient, remainder;

Modulus(x, y, quotient, remainder);

then quotient will be 5 and remainder will be 2 after Modulus returns. You will need to ask the user for two integers before calling this function.

I HAVE COMPLETED THE FIRST PART this is what I have...

#include #include

int SimpleSum(int a, int b); double SimpleDivision(int a, int b); double ComplexDivision(int a, int b, int c,int d);

using namespace std;

int main(){ //PART 1 int ch; int a,b,c,d;

cout << "Please make a selection from the following menu"; cout << endl; cout << endl; cout << "1. Simple Sum" << endl; cout << "2. Simple Division" << endl; cout << "3. Complex Division" << endl; cout << endl; cout << "Enter the number of the operation you wish to perform: "; cin >> ch;

switch(ch) { case 1: cout << "Please enter two integers:"; cin >> a >> b; cout << endl; cout << "sum = " << SimpleSum(a,b) << endl; break; case 2: cout << "Please enter two integers:"; cin >> a >> b; cout << endl; if (b > 0){ cout << "quotient = " << SimpleDivision(a,b) << endl; } else { cout << "Second number(divisor) shoule be more than 0 "; } break; case 3: cout << "Please enter four integers: "; cin >> a >> b >> c >> d; cout << endl; if (d > 0) cout << "quotient = " << ComplexDivision(a,b,c,d) << endl; else { cout << "Fourth number(divisor) should be more than 0 " << endl; } break;

}

return 0;

}

int SimpleSum(int a, int b){ return (a+b); }

double SimpleDivision(int a, int b){ double res; res = (double)a/(double)b; return res; }

double ComplexDivision(int a, int b, int c, int d){ int sum = a + b + c; double res; res = (double)sum/d; return res; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions