Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 5.2, Problem 12STE
Program Plan Intro
void Functions:
- A function must either return a single or no value.
- A function where no value is returned is termed as “void” function.
- The “void” function is been defined in same way as function that would return a value.
- It implements only subtask for complete problem.
- If a “void” function is called, formal parameters are substituted with arguments.
- The statements in function body are executed.
- The “return” statement specifies value that is been returned.
Call-by-Reference:
- It is a method for substituting arguments.
- The argument is substituted for formal parameter.
- The function call arguments may be a variable.
- This argument variable is substituted for formal parameter.
- It is similar to copying of argument variables into function definition body in place of formal parameter.
- The function body code is been executed once argument is substituted.
- This code can change argument variable value.
- The ampersand sign (&) is attached to end of type name in formal parameter list in both function declaration as well as function header definition.
Call-by-value:
- It copies actual value of an argument into function’s formal parameter.
- The changes made to parameter inside function have no effect on argument.
- This technique is used in default in programs.
- The code within a function could not alter arguments that are used for calling function.
Program Plan Intro
void Functions:
- A function must either return a single or no value.
- A function that would not return a value is termed as “void” function.
- The “void” function is been defined in same way as function that would return a value.
- It implements only subtask for complete problem.
- If a “void” function is called, formal parameters are substituted with arguments.
- The statements in function body are executed.
- The “return” statement specifies value that is been returned.
Call-by-Reference:
- It is a method for substituting arguments.
- The argument is substituted for formal parameter.
- The function call arguments may be a variable.
- This argument variable is substituted for formal parameter.
- It is similar to copying of argument variables into function definition body in place of formal parameter.
- The function body code is been executed once argument is substituted.
- This code can change argument variable value.
- The ampersand sign (&) is attached to end of type name in formal parameter list in both function declaration as well as function header definition.
Call-by-value:
- It copies actual value of an argument into function’s formal parameter.
- The changes made to parameter inside function have no effect on argument.
- This technique is used in default in programs.
- The code within a function could not alter arguments that are used for calling function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Function Call Operator with code?
What is the difference between a formal parameter and an argument?
Group of answer choices
A function’s argument is referred to as the formal argument to distinguish it from the value that is passed in during the function call.
The parameter is the passed value.
A function’s parameter is referred to as the formal parameter to distinguish it from the value that is passed in during the function call.
The argument is the passed value.
A function’s parameter is used for passing by reference.
The argument is used for passing by value.
A function’s parameter is used for passing by value.
The argument is used for passing by reference.
They are identical but using different terms.
in c++, "Overload of functions"
Write an overloaded function that returns a value based on a set of formal parameters: .
z={ x - a;
x + a - b
Chapter 5 Solutions
Problem Solving with C++ (9th Edition)
Ch. 5.1 - What is the output of the following program?...Ch. 5.1 - Are you required to have a return statement in a...Ch. 5.1 - Suppose you omitted the return statement in the...Ch. 5.1 - Prob. 4STECh. 5.1 - Prob. 5STECh. 5.1 - Is a call to a void function used as a statement...Ch. 5.2 - What is the output of the following program?...Ch. 5.2 - What would be the output of the program in Display...Ch. 5.2 - What would be the output of the program in Display...Ch. 5.2 - Prob. 10STE
Ch. 5.2 - Write a void function definition for a function...Ch. 5.2 - Prob. 12STECh. 5.3 - Prob. 13STECh. 5.3 - Prob. 14STECh. 5.3 - Rewrite the function declaration comment for the...Ch. 5.3 - Prob. 16STECh. 5.4 - Prob. 17STECh. 5.4 - Prob. 18STECh. 5.4 - Prob. 19STECh. 5.4 - Prob. 20STECh. 5.4 - Prob. 21STECh. 5.4 - Write a stub for the function whose function...Ch. 5.5 - Prob. 23STECh. 5.5 - Prob. 24STECh. 5.5 - Prob. 25STECh. 5 - Write a function that computes the average and...Ch. 5 - Write a program that reads in a length in feet and...Ch. 5 - Write a program like that of the previous exercise...Ch. 5 - (You should do the previous two Practice Programs...Ch. 5 - Write a program that reads in a weight in pounds...Ch. 5 - Write a program like that of the previous exercise...Ch. 5 - (You should do the previous two Practice Programs...Ch. 5 - (You need to do Practice Programs 4 and 7 before...Ch. 5 - The area of an arbitrary triangle can be computed...Ch. 5 - Write a program that converts from 24-hour...Ch. 5 - Write a program that requests the current time and...Ch. 5 - Modify your program for Programming Project 2 so...Ch. 5 - Write a program that tells what coins to give out...Ch. 5 - In cold weather, meteorologists report an index...Ch. 5 - Prob. 6PPCh. 5 - Write a program that inputs a date (for example,...Ch. 5 - Complete the previous Programming Project and...
Knowledge Booster
Similar questions
- In 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_forwardPure functions are beneficial.arrow_forwardExplain the purpose of a function parameter. What’s the difference between a parameterand an argument?arrow_forward
- Write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. What is the data type of the value-returning function isVowel? What are the formal parameters to the function? What are the data types on the formal parameters? What passing technique is used on those parameters? Write the definition for the isVowel function in the space below.arrow_forwardThe Issue: You have a function that accepts a variety of parameters. It is impractical to provide them as traditional parameters. So, what are you going to do?arrow_forwardHow does a value-returning function differ from the void functions?arrow_forward
- operators are overloaded when there are too many variables in the function.arrow_forward13. What is the difference between a formal parameter and an argument? Group of answer choices A function’s argument is referred to as the formal argument to distinguish it from the value that is passed in during the function call. The parameter is the passed value. They are identical but using different terms. A function’s parameter is used for passing by reference. The argument is used for passing by value. A function’s parameter is referred to as the formal parameter to distinguish it from the value that is passed in during the function call. The argument is the passed value. A function’s parameter is used for passing by value. The argument is used for passing by reference.arrow_forwardWhy is passing by reference preferred for passing an object to a function?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author: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