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

In C++, create a text-based, menu-driven program that allows the user to choose

ID: 3537261 • Letter: I

Question

In C++, create a text-based, menu-driven program that allows the user to choose whether to add, subtract, multiply or divide two numbers. The program should then input two double values from the use, perform the appropriate calculation, and display the result. Use an array of function pointers in which each pointer represents a function that returns void and receives two double parameters. The corresponding functions should each display messages indicating which calculation was performed, the values of the parameters, and the result of the calculation.

Explanation / Answer

#include<iostream>


using namespace std;


void add();

void subt();

void divi();

void multip();


void main()

{

int select=4;


cout<<"Select operation :";

cout<<"1. Add 2. Sub 3. Multiply 4. Divide ";


cin>>select;

void (*func[6])();


func[0] = &add;

func[1] = &subt;

func[2] = &divi;

func[3] = &multip;


(*func[select-1])();


}


void add()

{

double a, b;

cin>>a>>b;

cout<<a+b<<" addition!";

}


void subt()

{

double a, b;

cin>>a>>b;

cout<<a-b<<" subtraction!";

}

void divi()

{

double a, b;

cin>>a>>b;

cout<<a/b<<" division!";

}


void multip()

{

double a, b;

cin>>a>>b;

cout<<a*b<<" multiplication!";

}