Question

Design a function named findMax that accepts two integer values as arguments and returns the value...

Design a function named findMax that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. The following modules should be written:


getNum, that accepts a Ref to an integer, prompts the user to enter an integer, and accepts that input


findMax, that accepts two integer values and returns the value that is the greater of the two


showMaximum, that accepts two integer values, calls findMax, and displays the number returned from findMax


The main module, that will call getNum twice to enter two numbers, and showMaximum


Homework Answers

Answer #1

int getNum()

{

int number;

cout<<"Enter a number ";

cin>>number;

return number;

}

int findMax(int firstNumber,int secondNumber)

{

if (firstNumber >secondNumber)

return firstNumber;

else

return secondNumber;

}

int showMaximum(int firstNumber,int secondNumber)

{

int maxNumber;

maxNumber = findMax(firstNumber,secondNumber);

cout<<"Maximum number of both no. is"<<maxNumber;

}

void main()

{

int firstNumber,secondNumber;

firstNumber = getNum();

secondNumber = getNum();

showMaximum(firstNumber,secondNumber);

}

  

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
HI I NEED A FLOWCHART ALONG WITH  PSEUDOCODE Activity 6.2 – Functions and Pseudocode/Flowcharts Pseudocode make pseudocode...
HI I NEED A FLOWCHART ALONG WITH  PSEUDOCODE Activity 6.2 – Functions and Pseudocode/Flowcharts Pseudocode make pseudocode for the program requirements listed below. Maximum of Two Values. Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two...
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N...
Write a function definition for a function named getValidAge that returns an integer to the calling...
Write a function definition for a function named getValidAge that returns an integer to the calling program. The number returned by the function is a valid age (between 0 and 130 inclusive). Inside the function definition, the user is asked to enter their age, the age is validated using a loop, and the valid age is returned.
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in milliseconds. Delay should return a function that, when invoked waits for the specified amount of time before executing. HINT - research setTimeout(); 2.Create a function saveOutput that accepts a function (that will accept one argument), and a string (that will act as a password). saveOutput will then return a function that behaves exactly like the passed-in function, except for when the password string is...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
Question 1 Write functions that do the following: i) A function that takes 2 arguments and...
Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are...
in c++ Write a function that: accepts a string and an integer as it's only arguments...
in c++ Write a function that: accepts a string and an integer as it's only arguments uses the argument to open a file for writing writes the integer to the file if it fails to open the file, returns -1 if it succeeds in opening the file, returns 0 does not interact with the user in any way does not use global variables
C++ problem: Write a function that: accepts two integer variable arguments by reference swaps the contents...
C++ problem: Write a function that: accepts two integer variable arguments by reference swaps the contents of the two variables does not return anything does not interact with the user in anyway
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT