Problem Solving with C++, Student Value Edition
10th Edition
ISBN: 9780134543680
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 5.2, Problem 10STE
Program Plan Intro
void Functions:
- A function must either return a single or no value at all.
- 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 corresponding argument is substituted for formal parameter.
- The argument for a function call might 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 code in function body is 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 the actual value of an argument into function’s formal parameter.
- The changes made to parameter inside function have no effect on argument.
- This method is used in default in programs.
- The code within a function could not alter arguments used for calling function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write the function prototype of the void function named G() that takes an int reference parameter and two char parameters respectively
Your answer
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++
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)
Chapter 5 Solutions
Problem Solving with C++, Student Value 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
- How we can pass the function pointer as a parameter give example.arrow_forwardWrite 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.arrow_forwardC++ 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.arrow_forward
- Please written by computer source How should each type of variable be passed to a function under the parenthesized situation? One answer will be used twice . Group of answer choices string (changes parameter) [ Choose ] double (doesn't change parameter) [ Choose ] user-defined class object (doesn't change parameter) [ Choose ] int (changes parameter) [ Choose ] options by value by reference (no const) by reference to constant objectarrow_forwardWrite a function prototype for a function named my_function that accepts two integers (a,b) as parameters and returns a integer? (C++)arrow_forwardAll of the functions in the class A(n)_ are virtual functions. Let us know what you think by filling in the gaps.arrow_forward
- Write 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_forwardExplain the purpose of a function parameter. What’s the difference between a parameterand an argument?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
- Write declarations for two overloaded functions named bar(). They both return type int. The first takes one argument of type char, and the second takes two arguments of type char. If this is impossible, say why?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_forwardGive an example from your own idea, of a program that use a void function (does not return avalue), based on your understanding. (You must include a main 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