Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 9P
Program Plan Intro
- Include required header files.
- Declare the “max()” function for two parameters.
- Declare the “max()” function for three parameters.
- Define a “max()” function with two parameters.
- “if” statement to check “x” is greater than “y”.
- The condition is true, return “x”.
- Otherwise, return “y”.
- Define a “max()” function with three parameters.
- Call “max()” function with two parameters to return the result and store it in “tmp”.
- “if” statement to check “tmp” is greater than “z”.
- The condition is true, return “tmp”.
- Otherwise, return “z”.
- Define a “main()” function.
- Declare the variables “a”, “b” and “c”.
- Get three numbers from the user and input is assigned to the variables.
- Call the “max()” function of two parameters and print the largest of first two numbers.
- Call the “max()” function of three parameters and print the largest of all the numbers.
- “if” statement to check “x” is greater than “y”.
- The condition is true, return “x”.
- Otherwise, return “y”.
- Call “max()” function with two parameters to return the result and store it in “tmp”.
- “if” statement to check “tmp” is greater than “z”.
- The condition is true, return “tmp”.
- Otherwise, return “z”.
- Declare the variables “a”, “b” and “c”.
- Get three numbers from the user and input is assigned to the variables.
- Call the “max()” function of two parameters and print the largest of first two numbers.
- Call the “max()” function of three parameters and print the largest of all the numbers.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a definition for a void-function that has two int value parameters and outputs to the screen the product of these arguments. Write a main function that asks the user for these two numbers, reads them in, calls your function, then terminates. c++
• Write a function for a double function that will accept either two or three parameters of type double. • If it only receives two parameters, then it will return the average of the two numbers. • If it receives three parameters, then it will return the average of the largest number and the smallest number. • Write a complete C++ program to show the use of this function.
Write a function CountEvens() that has four integer parameters, and returns the count of parameters where the value is an even number (i.e. evenly divisible by 2) in c++
Chapter 4 Solutions
Problem Solving with C++ (10th Edition)
Ch. 4.2 - Prob. 1STECh. 4.2 - Convert each of the following mathematical...Ch. 4.2 - Write a complete C++ program to compute and output...Ch. 4.2 - Write and compile short programs to test the...Ch. 4.3 - Prob. 5STECh. 4.3 - Prob. 6STECh. 4.3 - Prob. 7STECh. 4.3 - Prob. 8STECh. 4.3 - Carefully describe the call-by-value parameter...Ch. 4.3 - Prob. 10STE
Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function called...Ch. 4.3 - Write a function definition for a function isDigit...Ch. 4.3 - Write a function definition for a function...Ch. 4.4 - What is the purpose of the comment that...Ch. 4.4 - Prob. 16STECh. 4.4 - Prob. 17STECh. 4.4 - Carefully describe the process of program testing.Ch. 4.4 - Prob. 19STECh. 4.5 - If you use a variable in a function definition,...Ch. 4.5 - Suppose a function named Function1 has a variable...Ch. 4.5 - The following function is supposed to take as...Ch. 4.5 - Prob. 23STECh. 4.6 - Prob. 24STECh. 4.6 - Prob. 25STECh. 4.6 - Prob. 26STECh. 4.6 - Suppose you have two function definitions with the...Ch. 4.6 - This question has to do with the Programming...Ch. 4.6 - Prob. 29STECh. 4 - A liter is 0.264179 gallons. Write a program that...Ch. 4 - Modify your program from Practice Program 1 so...Ch. 4 - The price of stocks is sometimes given to the...Ch. 4 - Write a program to gauge the rate of inflation for...Ch. 4 - Enhance your program from the previous Practice...Ch. 4 - Write a function declaration for a function that...Ch. 4 - The gravitational attractive force between two...Ch. 4 - Prob. 8PCh. 4 - Prob. 9PCh. 4 - Write a program that computes the annual after-tax...Ch. 4 - Write a program that asks for the users height,...Ch. 4 - Modify your program from Programming Project 2 so...Ch. 4 - Write a program that outputs the lyrics for the...Ch. 4 - To maintain ones body weight, an adult human needs...Ch. 4 - You have invented a vending machine capable of...Ch. 4 - Your time machine is capable of going forward in...Ch. 4 - Do Programming Project 11 from Chapter 3 except...Ch. 4 - Your sports league uses the following lottery...Ch. 4 - Do Programming Project 14 from Chapter 3, the Edoc...
Knowledge Booster
Similar questions
- Write a function definition for a function called even that takes one argumentof type int and returns a bool value. The function returns true if its oneargument is an even number; otherwise, it returns false.arrow_forwardWrite a program in JavaScript and make a function and a second function which check the pass argument is of function type or not. You can use instance of opratorarrow_forwardWrite a function example that takes two parameters and return one single parameter of same data type as output. Test that function in main function.arrow_forward
- Write a function that replaces a substring with a new string. Example: >>> replace('The quick brown fox jumps over the lazy dog', 'quick', 'slow') The slow brown fox jumps over the lazy dog The first parameter is the string, second is the substring to be replaced and the third is the string to replace the substring. If there are more than one occurrence of a substring, replace it all.arrow_forwardWrite a function that gets two integer parameters between 1 and 100 and prints their common factors (divisors). need urgent answer.. in c++arrow_forwardWrite a function convertQuartersToDollars that has the noOfQuarters, noOfDollars, and remainingCents as formal parameters of data type int. The noOfQuarters is the number of quarters to be used to calculate noOfDollars, the number of dollars that the total number of quarters can be converted to, and remainingCents , the remaining cents. The noOfDollars and remainingCents are returned from the function,arrow_forward
- Write a function that takes in two integer parameters, x and y, and computes and returns x raised to the y power. Do this without using any <cmath> library functions c++arrow_forwardImplement a function that takes incoefficients A,B,and C for the quadratic equation Ax2 + Bx + C = 0 and computes the two solutions. Have the function return the number of valid (not NaN) solutions and fill in the return arguments so the smaller of the two solutions is first.arrow_forwardWrite a c++ program that takes a date in the following format: December 24th, 2021 and extracts the day, month, and year as 3 integers. Your program should have the following functions: (a) WriteafunctiongetDatethatpromptsausertoenteradateasastringandreturns it. (b) Write a function extract that takes as its parameter a date and returns the day, month, and year as 3 integers. (c) Write a function convertDigits that takes as its parameter a string of digits and converts it to an int. (d) Write a function convertMonths that takes as its parameter a month as a string and returns a corresponding number from 1 to 12 (1 for January, . . . , 12 for Decem- ber).arrow_forward
- Write a program in C Write a function calledsum_average()whichtakesthree input parameters (x,yand z) of type double. This function willreturn the sumof (x,yand z) andthe averageof those threenumbers. You will need to use two output parametersto accomplish this.Write a program that promptsthe user to enter three numbers and then calls the functionsum_average()to display the resulting sum and average of those numbers.arrow_forwardWrite a function named sumDigits which takes three parameters: f, t and x. sumDigits, then, finds the smallest integer between f and t (both inclusive) whose sum of digits is x, and returns that integer.arrow_forwardThis cant be right. first, first function needs to be called "rossOrder" second, the second function requires only 1 parameter. this has 2.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning