Question

In: Computer Science

Part 1: Getting started and calling a function from a function. In this part, you will...

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.

Solutions

Expert Solution

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.


Related Solutions

University Backpacks (Part 1) You are the owner-manager of University Backpacks, a company that you started...
University Backpacks (Part 1) You are the owner-manager of University Backpacks, a company that you started this year (20X1). The company sells backpacks to students attending several local colleges in the area. Your company sells two types of backpacks: those for transporting laptop computers and smaller ones not intended for laptop storage. The latter type comes in two styles, with dividers and zippered pockets and without. All back-packs carry the unique logos of the colleges in the community. For this...
You and 99 friends are on a three hour boat tour when the weather started getting...
You and 99 friends are on a three hour boat tour when the weather started getting rough and you were stranded on a desert island. Three of you friends are carriers of the gene for albinism, but no one on the trip is albino. What percentage of the island’s population in the next generation do you expect to be albino? Carriers of this gene?   Assume that the albinism gene above also allowed individuals who are carriers to avoid a deadly...
A template (generic) function for insertion sort is given to you. Part-1: design a function to...
A template (generic) function for insertion sort is given to you. Part-1: design a function to compare 2 strings using case-insensitive comparison, a function to test if 2 records are not equal (using case-insensitive string comparison). Part-2: define your own compare function required by the template insertionSort function. #include <iostream> #include <string> #include <cstdlib> #include <iomanip> #include <ctime> #define BASE 1000000000LL // long long int using namespace std; struct record { long long value; string str; }; // Part-1: case-insensitive...
Part 1: You are a diligent saver who started with nothing but manages to put away...
Part 1: You are a diligent saver who started with nothing but manages to put away $250 at the end of each month, owed largely to your total abstinence from avocado toast and fancy coffee. If you keep up this habit for a total of 15 years with your savings growing at 7.50% (monthly compounded), what nominal wealth can you look forward to in your investment account at the end of your savings efforts? $ Part 2: Allowing for an...
You are getting together to start a company that sells widgets for consumer products. As part...
You are getting together to start a company that sells widgets for consumer products. As part of the management team, you need to write a memo that shares the company vision with the employees and the public. Write a 200-word memo and submit it to the group chat for review.  
We can build a heap by repeatedly calling the insert function to insert the elements into...
We can build a heap by repeatedly calling the insert function to insert the elements into the heap. Here is pseudocode: buildHeap(A) h = new empty heap   for each element e in A       h.insert(e)             What is the Big-O runtime of this version of buildHeap? Justify your answer.
C Program: Write your own stringLength function (without calling a pre-written library function) that returns the...
C Program: Write your own stringLength function (without calling a pre-written library function) that returns the length of the string argument in characters, not including the terminating ‘\0’ character.   Write four versions of a void printString function (i.e., printString1, printString2, etc) each of which prints its string argument character-by-character but using the following techniques: printString1: array indexing printString2: pointer/offset with the array name as a pointer, printString3: pointer indexing, and printString4: pointer/offset with a pointer Write a void function called...
Given the Demand function from Part 1: D(p) = 64 2p , The monopolist's cost is...
Given the Demand function from Part 1: D(p) = 64 2p , The monopolist's cost is equal to C(Q) = Q2 + 2Q: PART II. Now take the same demand function as in Part I but imagine that the market has two firms instead of 1. Also assume that the marginal cost of each firm is equal to 4. Market structure is therefore characterized as a duopoly. Suppose that firms compete by choosing their output levels simultaneously. (14) (2 points)...
A channel of distribution is the part of the supply chain that focuses on getting the...
A channel of distribution is the part of the supply chain that focuses on getting the product to the ultimate consumers. Over the past 10 years, retailers have seen a shift from brick and mortar to online buying of goods by consumers. As a result, more than 7000 retailers have closed up physical shop this year. Please are some advantages and disadvantage of online versus on ground shopping. If you are hired to slow and increase the number of on...
Mr Kaur started a software business. He decided to incorporate. He did so, calling his company...
Mr Kaur started a software business. He decided to incorporate. He did so, calling his company Kaur and Sons Pty Ltd. Mr Kaur sold the assets and goodwill of his software business to Kaur and Sons Pty Ltd for $30,000. Rather than the company paying him $20,000 in cash, the company issued 20,000 shares worth $1.00 each to Mr Kaur. At the time of the sale, the company still owes $10,000 to Mr Kaur. This debt relates to $10,000 of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT