Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 4.5, Problem 23STE
Program Plan Intro
- Include required header files.
- Declare a function named “readFilter()”.
- Define a “readFilter()” function.
- Declare a variable “val”.
- Get the input from the user and it is assigned to the variable “val”.
- “if” statement to check the “val” is greater than equal to “0”.
- The condition is true, the
program returns the user entered “val”.
- Otherwise, the program returns “0”.
- Define a “main()” function.
- Call “readFilter()” function and display the result.
- Declare a variable “val”.
- Get the input from the user and it is assigned to the variable “val”.
- “if” statement to check the “val” is greater than equal to “0”.
- The condition is true, the
program returns the user entered “val”.
- The condition is true, the
- Otherwise, the program returns “0”.
- Call “readFilter()” function and display the result.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a function declaration and a function definition for a function that takes one argument of type int and one argument of type double, and that returns a value of type double that is the average of the two arguments.
Write the function header for a function fun1 that will be receiving one number as a parameter. Write the call to the function from main, passing a number to the function.
C++
Write the definition of the function int computerProd() with parameters that receives as arguments two integer values values, computes their product and returns it to the calling function.
Chapter 4 Solutions
Problem Solving with C++ (9th 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...
Knowledge Booster
Similar questions
- Mark the following statements as true or false: a. To use a predefined function in a program, you need to know only the name of the function and how to use it. (1) b. A value-returning function returns only one value. (2, 3) c. Parameters allow you to use different values each time the function is called. (2, 7, 9) d. When a return statement executes in a user-defined function, the function immediately exits. (3, 4) e. A value-returning function returns only integer values. (4) f. A variable name cannot be passed to a value parameter. (3, 6) g. If a C++ function does not use parameters, parentheses around the empty parameter list are still required. (2, 3, 6) h. In C + + , the names of the corresponding formal and actual parameters must be the same. (3, 4, 6) i. A function that changes the value of a reference parameter also changes the value of the actual parameter. (7) j. Whenever the value of a reference parameter changes, the value of the actual parameter changes. (7) k. In C++, function definitions can be nested; that is, the definition of one function can be enclosed in the body of another function. (9) l. Using global variables in a program is a better programming style than using local variables, because extra variables can be avoided. (10) m. In a program, global constants are as dangerous as global variables. (10) n. The memory for a static variable remains allocated between function calls. (11)arrow_forward1) Write a function declaration for a function named getMax:a) Accept two numbers as input parameters.b) Return the largest number.2) Write the function call for the getMax function with input parameters 10 and 15.5.ExampleGiven the arguments 10 and 15.5 return 15.5.arrow_forwardIn C Write a function named “robot”. This function has twointeger parameters named “forward” and “reverse” anda return of type integer. If the value passed to forward is1 and to reverse is 0 then the return should be 127. Ifthe value passed to forward is 0 and to reverse is 1 thenthe return should be -127. If both are 0 or both havenonzero values, then the return should be 0arrow_forward
- Write a function prototype to calculate the volume of a cube. The function receives a long type variable that stores one of the side of the cube and returns the long type volume of the cubearrow_forwardIn C++ Write the definition of a void function that has one double parameter and changes the sign of the parameter (if it is negative it becomes positive, and if it is positive it becomes negative)arrow_forwardA function has different forms such as function call ,declaration, definition .in your opinion which form of function is called prototype and why?arrow_forward
- Should define a main function and end by invoking itarrow_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_forwardWrite the function prototype of the void function named G() that takes an int reference parameter and two char parameters respectively Your answerarrow_forward
- What is the output of a function that replaces a class's operator with another operator?arrow_forwardWrite a code in the main function that would call Function 1 and Function 3 of the Lab class. You can use values of your choice for function arguments (if required). Please write the output of these function calls. class Lab { int time; public: Lab(){ //Function 1 time = 120; cout << "Duration of lab is " << time << “minutes” << endl; } void Demonstration(){ //Function 2 cout << "Lab Demonstration started." << endl; } Lab(int duration){ //Function 3 time = duration; cout << "Duration of lab is " << time << “minutes” << endl; } ~Lab(){ //Function 4 cout << "Thanks. Lab has ended." << endl; } };arrow_forwardIn C/C++, Function overloading is the process of creating several functions that have exactly the same name. In order to overload successfully, each function must have: A. A different parameter list B. A different number of parameters and a different return type C. An integer on the end of the function name, such as func1()and func2() D. Either A or B E. Both A and Carrow_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 LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr