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 function findFirstUpper() that takes a string as parameter, finds returns the index of the first uppercase letter in the string. If there is no uppercase letter in the string, then the function will return -1.Example: Function call findFirstUpper("best course is CS104!") will return 15 (index of the 'C').Example: Function call findFirstUpper("good morning!") will return -1.
CODEEE:PYTHON PLEASE
Write a function findFirstUpper() that takes a string as parameter, finds returns the index of the first uppercase letter in the string. If there is no uppercase letter in the string, then the function will return -1.Example: Function call findFirstUpper("best course is CS104!") will return 15 (index of the 'C').Example: Function call findFirstUpper("good morning!") will return -1
CODEE:PYTHON
How we can pass the function pointer as a parameter give example.
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 isRootOf that takes two arguments of type int and returns a bool value. The function returns true if the first argument is the square root of the second; otherwise, it returns false.arrow_forwardWrite a c++ program: Write a function named convertToLowestTerms that inputs two integer parameters by reference named numerator and denominator. The function should treat these variables as a fraction and reduce them to lowest terms. For example, if numerator is 20 and denominator is 60, then the function should change the variables to 1 and 3, respectively. This will require finding the greatest common divisor for the numerator and denominator then dividing both variables by that number. If the denominator is zero, the function should return false, otherwise the function should return true. Write a driver program that uses convertToLowestTerms to reduce and output several fractions.arrow_forwardWrite a function to divide variable ‘a’ with ‘b’. Store the result in a separate variable andreturn it from the function. Practice default parameters by calling your function with 1 argumentand with 2 arguments. Use the concept of function prototyping for this question. The signature offunction is as follows: int divide (int a, int b=2)arrow_forward
- Can not use "and" or "or" in java Language Write the function parrotTrouble.** We have a loud talking parrot. The "hour" parameter* is the current hour time in the range 0..23. We are* in trouble if the parrot is talking and the hour* is before 7 or after 20. Return true if we are* in trouble.** Some Examples:* parrotTrouble(true, 6) returns true* parrotTrouble(true, 7) returns false* parrotTrouble(false, 6) returns false** @param isTalking true if the parrot is talking.* @param hour the time of day from 0..23.* @return true if you're in trouble with your neighbors.arrow_forwardWrite the definition of a void function that takes as input three decimal numbers. The function returns the sum and average of the three numbers. If the average is greater than or equal to 70, it returns "Pass"; otherwise it returns "Fail".arrow_forwardWrite a function that takes two integers and returns True if the integers have a common divisor that is different than 1, otherwise returns False. For example, notRelPrime(3,5) returns False, whereas notRelPrime (8,12) returns True. Because, 3 and 5 have only one common divisor, which is 1, whereas 8 and 12 are both divisible by 1, 2 and 4. def notRelPrime (a, b):arrow_forward
- Write the definition of a void function that takes as input two integer values, say n and m. The function returns the sum and average of all the numbers between n and m (inclusive) .arrow_forwardin c++ write a code that: Define an enumeration type triangleType that has the values scalene, isosceles, equilateral, and noTriangle.Write a function triangleShape that takes as parameters three numbers, each of which represents the length of a side of the triangle. The function should return the shape of the triangle. (Note: In a triangle, the sum of the lengths of any two sides is greater than the length of the third side.)Write a program that prompts the user to input the length of the sides of a triangle and outputs the shape of the triangle.arrow_forwardWrite the definition of a void function that takes as input two parameters of type int, say sum and testScore the function updates the value of sum by adding the value of testScore. The new value of sum is reflected in the calling environment.arrow_forward
- Write a function, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversedarrow_forwardINSTRUCTIONS: Write a C++ script/code to do the given problems. MOVIE PROBLEM: Write a function that checks whether a person can watch an R18+ rated movie. One of the following two conditions is required for admittance: The person is atleast 18 years old. • They have parental supervision. The function accepts two parameters, age and isSupervised. Return a boolean. Example: acceptIntoMovie(14, true) → true acceptIntoMovie(14, false) → falsearrow_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
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