In: Computer Science
Part 1: Getting started and calling a function from a function.
In this part, you will work with functions and functions that call functions. All code will be in main.cpp. Testing and grading will be via zyLab. Start with the template in zyBook. Write the following function:
FindMax4(double num1, double num1, double num3, double num4)
that returns the max of the arguments. Implement FindMax4() such that the body of the function comprises only a return statement that invokes FindMax() multiple times.
The program should input four values and output the max of the four.
Example
Input
1 2 3 4
Output
Enter 4 numbers:
maxVal is: 4
Part 2: Overloading function names.
In this part, you will deal with overloaded function names. All code will be in main.cpp. Testing and grading will be via zyLab.
Start with the template in Part 0. Change FindMax() and FindMax4() so that the arguments cannot be changed by the functions.
Write two additional overloaded functions, FindMax() and FindMax4() that have string arguments.
Input a char, typeChoice that will be 'd' or 's' or 'x'. If typeChoice == 'd', then input four doubles and output the max. If typeChoice == 's', then input four strings and output the max. If typeChoice == 'x', then end the program. If typeChoice is neither 'd' nor 's' nor 'x', then request typeChoice again until a correct choice is indicated. Use a switch statement to implement typeChoice branching. Loop requesting typechoice until 'x' is input.
Part 1)
Program Code Screenshot:
Sample output:
The screenshots are attached below for reference.
Please follow them for proper indentation and output.
Program to copy:
#include <iostream>
using namespace std;
int FindMax4(double num1,double num2,double num3,double
num4){
if(num1>num2 && num1>num3 &&
num1>num4)//compare with each and every other number
return num1;
if(num2>num1 && num2>num3 &&
num2>num4)
return num2;
if(num3>num2 && num3>num1 &&
num3>num4)
return num3;
return num4;
}
int main()
{
cout<<"Enter 4 numbers:"<<endl;
double n1,n2,n3,n4;
cin>>n1>>n2>>n3>>n4;//read 4 numbers from
user and call function
cout<<"maxVal is: "<<res;
}
Note:
Please see that as per the guidelines, only one question can be solved.
In case of multiple choice type questions, upto 4 questions or four sub parts can be answered. Thank you.