C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 6, Problem 20SA
(a)
Program Plan Intro
To identify the function prototype, function heading, function body and function definition in the given code.
(b)
Program Plan Intro
To identify function call statements, formal parameters, and actual parameters in the given program.
(c)
Program Plan Intro
To identify value parameters and reference parameters from the given program.
(d)
Program Plan Intro
To identify the local variables and global variables for the given program.
(e)
Program Plan Intro
To identify the named constants in the given program.
(f)
Program Plan Intro
Program Plan:
- The variable RATE of double type is used to store a constant value.
- The variable STAR of char type is used to store a constant value.
- The variable s of integer type is used to store s fixed value.
- The variable t of integer type is used to store a fixed value.
- The variable d of double type is passed as a parameter to func() method.
- The variable ch of char type is used to store the value of STAR variable.
Program Description:
The main purpose of the program is to illustrate passing parameters by value and passing parameters by reference.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Which of the following is true regarding functions?
Function definitions are useful because they can reduce duplication of code.
Function definitions are an application of modularity.
Function applications can be used as both statements and expressions.
Every function definition has its own namespace.
All of the above
Set-up and implementation code for a void function MaxYou are not required to write a complete C++ program but must write and submit just your responses to the four specific function related questions below: QC1: Write the heading for a void function called Max that has three intparameters: num1, num2 and greatest. The first two parameters receive data from the caller, and greatest is used to return a value as a reference parameter. Document the data flow of the parameters with appropriate comments*. QC2: Write the function prototype for the function in QC1. QC3: Write the function definition of the function in QC1 so that it returns the greatest of the two input parameters via greatest, a reference parameter. QC4: Add comments to the function definition* you wrote in QC3 that also states its precondition and postcondition.
Answer the following as completely as possible in your own words:1. What is a function declaration?2. What is a function definition?3. Explain function overloading.4. Code two function declarations which demonstrate function overloading.
Chapter 6 Solutions
C++ Programming: From Problem Analysis to Program Design
Ch. 6 - Mark the following statements as true or false:
a....Ch. 6 - Determine the value of each of the following...Ch. 6 - Determine the value of each of the following...Ch. 6 - Consider the following function definition. (4, 6)...Ch. 6 - Consider the following statements:
Which of the...Ch. 6 - Prob. 8SACh. 6 - Prob. 9SACh. 6 - Why do you need to include function prototypes in...Ch. 6 - Prob. 11SACh. 6 - Consider the following function: (4)...
Ch. 6 - Prob. 15SACh. 6 - What is the output of the following program? (4)
Ch. 6 - Write the definition of a function that takes as...Ch. 6 - Prob. 18SACh. 6 - How would you use a return statement in a void...Ch. 6 - Prob. 20SACh. 6 - Prob. 21SACh. 6 - What is the output of the following program?...Ch. 6 - Write the definition of a void function that takes...Ch. 6 - Write the definition of a void function that takes...Ch. 6 - Prob. 8PECh. 6 - The following formula gives the distance between...Ch. 6 - Write a program that takes as input five numbers...Ch. 6 - When you borrow money to buy a house, a car, or...Ch. 6 - Consider the definition of the function main:...Ch. 6 - The statements in the following program are not in...Ch. 6 - Write a program that outputs inflation rates for...Ch. 6 - Write a program to convert the time from 24-hour...Ch. 6 - Jason opened a coffee shop at the beach and sells...
Knowledge Booster
Similar questions
- True or False : The concept of function abstraction hinders our code development by confusing us with the details of the function.arrow_forward9-Given the code segment below, what should be the data type of the formal parameter in the function prototype of func(), given the call from main()? Note that function prototypes need not include the identifier (name of the parameter), so do NOT put any variable name in your answer. Remove any space in your answer. If the accessing is wrong, answer INVALID (in all capital letters). void func( ______ ); int main() { double aData[6][4]; func(&aData[4]); return 0; }arrow_forwardSo I am enrolled in a "principles of programming course" and need help understanding these "side effects". My teacher gave me this definition but I need help elaborating and understanding these side effects. Functional side effects: when a function changes a two-way parameter or a non-local variable• Problem with functional side effects:• When a function referenced in an expression alters another operand of the expression; e.g.,for a parameter change:a = 10;/* assume that fun changes its parameter */b = a + fun(&a); SOMEONE PLEASE PROVIDE EXAMPLES!!!arrow_forward
- Please list real life examples of call by reference and call by value. Explaining the concept of a function, input parameters and output values can be a very difficult topic to teach. A good metaphor can help students understand the notion of parameters, call-by-reference and call-by-value. For example, think about the difference between identity theft and auto theft. If you look at your parking space and your car isn’t there, you know it has been stolen. You don’t have it any more. Yet, if someone steals your identity, you still have it. You can’t even tell it has been stolen until somebody else uses it. In some ways, auto theft is like call by reference because any changes the thief makes to your car, scratched paint, torn upholstery, etc., will still be there when you get it back.arrow_forwardii. Define the terms function header (or heading), function body, and functiondefinition. Use program develop in (a) to describe the elements of a function.iii. Define the terms actual parameter and formal parameter and explain thedifference between the two.arrow_forwardMark 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_forward
- Exercise 9-6: Pass by Reference and Pass by Address In this exercise, you use what you have learned about passing arguments by reference and by address to functions to answer Questions 1-2. 1. Given the following variable and function declarations, write the function call and the function's header a. double price 22.95, increase .10; void changePrice(doubl e&, double); b. double price 22.95, increase .10; void changePrice (double*, double); c. int age = 23; void changeAge(int&); d. int age 23; void changeAge (int*); 2. Given the following function headers and variable declarations, write a function call: a. custNames [] = {"Perez", "Smith", "Patel", "Shaw"}; balances [] = {34.00, 21.00, 45.50, 67.00); void cust (string name [], double bal []) b. int values [] = {1, 77, 89, 321, -2, 34}: void printSum (int nums [])arrow_forwardProvide the function/module header in pseudocode and in C++ code for each of the following. Include comments that describe the parameters and return values (if a value is returned). Please dont define the function, just give the header or prototype and comments. Be sure to indicate if the parameters need to be passed by reference. a. Swaps two reals numbers. b. Calculates and returns the sales tax given the price and the amount of the tax rate (both as reals). c. Returns the concatenation of two strings. d. Performs a search of a string for a character and returns true if the character is found and false otherwise.arrow_forwardConsider proper alignment and indentation of statements when answering the following questions. a) Write a value-returning function with the appropriate parameter(s) to do the following: The function receives an integer and determines whether the integer is in the range 1 through 12 inclusive. It returns true if the integer is in the range, otherwise it returns false. Good names should be used for the function and parameters. b) Consider the following: int monthNum; cin >> monthNum; Write the code segment to call the function in (a) above to determine whether the integer stored in monthNum is in the specified range. If it is, display the month number and a message that the month number is valid., otherwise, display a message that it is invalid.arrow_forward
- I need help in solving this question Question 10 Given the code segment below, what should be the data type of the formal parameter in the function prototype of func(), given the call from main()?Note that function prototypes need not include the identifier (name of the parameter), so do NOT put any variable name in your answeIf the accessing is wrong, answer INVALID (in all capital letters). void func( ______ ); int main() { double aData[6][4]; func(aData[6]); return 0; }arrow_forwardChange this code in C to Create functions and function prototypes to replace each of thecalculator actions. Prototype each function above main and write thefunction (definition) below main.- The input by the user and output statement of each calculation shouldstay in main and not be moved to a function except the output forfunction “iseven” which should be done in the function.- Each function will accept the value(s) supplied by the user as parametersand return the result in a return statement (not a printf statementexcept for “iseven”).- The result returned by each function should be outputted by a printfstatement in main.- Create a function named display that contains: menu displaystatements, the user prompt to select an option, user input. Thisfunction should have no parameters and should return a character asthe option chosen by the user. ----------------------------------------------------------------------------------------------------------…arrow_forwardConsider the definition of the function main. int main() { double rate, hours, amount; . . . } Each of the functions described must have the appropriate parameters to access these variables. Write the following definitions: a. Write the definition of the function getHoursRate that prompts the user to input the hours worked and rate per hour to initialize the variables hours and rate of the function main. b. Write the definition of the value-returning function payCheck that calculates and returns the amount to be paid to an employee based on the hours worked and rate per hour. The hours worked and rate per hour are stored in the variables hours and rate, respectively, of the function main. The formula for calculating the amount to be paid is as follows: For the first 40 hours, the rate is the given rate; for hours over 40, the rate is 1.5 times the given rate. c. Write the definition of the function printCheck that prints the hours worked, rate per hour, and the…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 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