Using the techniques you learned in Fig 728 page 313314 crea
Using the techniques you learned in Fig. 7.28, page 313-314, 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. Requirements: •Use proper naming convention, spacing and indentation in your source code •Your code should be well commented, with proper naming conventions and spacing •Utilization of the following structures: arrays, functions, and pointers. •Include flowcharts with your project. The flowcharts must match your code. Note each function (module) should have its own specific flowchart.
Solution
Here is the code for the above scenario:
include <stdio.h>
int main()
{
void addition(double number1, double number2); /* create the functions */
void subtraction(double number1, double number2);
void division(double number1, double number2);
void multiplication(double number1, double number2);
int inputfunc=1;
double inputnum1=0;
double inputnum2=0;
while (inputfunc >= 1 && inputfunc <= 4) /* If function to be performed are those below then continue performing loop */
{
printf(\"Press 1 to add two numbers.\ \");
printf(\"Press 2 to subtract two numbers.\ \");
printf(\"Press 3 to multiply two numbers.\ \");
printf(\"Press 4 to divide two numbers.\ \");
printf(\"Press 5 to exit.\ \");
printf(\"Enter your choice\ \");
scanf_s(\"%d\",&inputfunc);
if( inputfunc == 5)
return(0);
printf(\"Enter both numbers with a space in between.\");
scanf_s(\"%lf %lf\", inputnum1, inputnum2);
void(*func[4])(double, double)={&addition, &subtraction, &division, &multiplication};
(*func[inputfunc-1])(inputnum1, inputnum2);
return(0);
}
}
void addition(double number1, double number2)
{
double answer;
answer=number1+number2;
printf(\"Addition of the two numbers = %lf + %lf = %lf\ \", number1, number2, answer);
return;
}
void subtraction(double number1, double number2)
{
double answer;
answer=number1-number2;
printf(\"By subtracting the two numbers results are %lf - %lf = %lf\ \", number1, number2, answer);
return;
}
void multiplication(double number1, double number2)
{
double answer;
answer=number1*number2;
printf(\"By multiplying the two numbers results are %lf * %lf = %lf\ \", number1, number2, answer);
return;
}
void division(double number1, double number2)
{
double answer;
answer=number1/number2;
printf(\"By dividing the two numbers results are %lf / %lf = %lf\ \", number1, number2, answer);
return;
}

