Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++!!!! PLEASE HELP I am not allowed to use global variables!! Phase 1 Write a p

ID: 3589232 • Letter: C

Question

C++!!!!

PLEASE HELP

I am not allowed to use global variables!!

Phase 1

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 function’s 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 function’s 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.

(note - all function parameters will need to match the requirements of the assignment. - thus you do not use arrays in this assignment anywhere)

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.

Explanation / Answer

#include<iostream>

using namespace std;

int SimpleSum(int a, int b);
double SimpleDivison(int a, int b);
double ComplexDivison(int a, int b, int c,int d);

int main(){

int ch;
int a,b,c,d;
cout << "1.SimpleSum ";
cout << "2.SimpleDivison ";
cout << "3.Complex Divison ";
cout << "Enter your choice :";
cin >> ch;
switch(ch) {
      case 1 : cout << "Enter two numbers :" ;
               cin >> a >> b;
               cout << SimpleSum(a,b) << endl;
               break;
      case 2 : cout << "Enter two numbers :" ;
               cin >> a >> b;
               if (b > 0){
                  cout << SimpleDivison(a,b) << endl;
               }
               else {
                   cout << "Second number(divisor) should be more than 0 ";
               }
               break;
      case 3 : cout << "Enter three numbers and a divisor:" ;
               cin >> a >> b >> c >> d;
               if (d > 0)
                  cout << ComplexDivison(a,b,c,d) << endl;
               else {
                  cout << "Fourth number(divisor) should be more than 0 ";
               }
               break;

}

return 0;
}

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

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

   int sum = a+b+c;
   double res;

   res = (double)sum/d;
   return res;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote