Concept explainers
Consider the following statements:
Which of the following statements are valid? If they are invalid, explain why. (4)
volume = box (length, width, height);
volume = box (length, 3.8, height);
cout << box(num1, num3, num2) << endl;
cout << box (length, width, 7.0)<< endl;
volume = box (length, num1, height);
cout <<box(6.2, height) << endl;
volume = box (length + width, height)
volume = box (num1, num2 + num3) ;
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
C++ Programming: From Problem Analysis to Program Design
- Why do you need to include function prototypes in a program that contains user-defined functions? (5)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_forwardCan you help me with this question ?arrow_forward
- Explain the difference between the following with simple example 4. Subplot. figure and hold on. 5. built in function and user define function.arrow_forwardMark the following statements as true or false: To use a predefined function in a program, you need to know only the name of the function and how to use it. a. b. A value-returning function returns only one value. Parameters allow you to use different values each time the function is called. C. When a return statement executes in a user-defined function, the function immediately exits. A value-returning function returns only integer values. A function that changes the value of a reference parameter also changes the value of the actual parameter. d. e. f. A variable name cannot be passed to a value parameter. g. J€ a C++ function does not use parameters, parentheses around the h. empty parameter list are still required. In C++, the names of the corresponding formal and actual parameters i. must be the same.arrow_forwardanswer this in c++arrow_forward
- a. How would you use a return statement in a void function? b. Why would you want to use a return statement in a void function?arrow_forwardProblem Statement: The mathematician Conway imagined a game, called game of life, which considered cells that are susceptible to reproduce, disappear, or survive when they obey certain rules. These cells are represented by elements on a grid of squares, where a grid has an arbitrary size. Thus, each cell (except those on the boundaries of the grid) is surrounded by eight squares that contain other cells. The rules are stated as follows: 1. Survival: Each cell that has two or three adjacent cells survives until the next generation.2. Death: Each cell that has at least four adjacent cells disappears (or dies) by overpopulation. Also, each cell that has at most one adjacent cell dies by isolation.3. Birth: Each empty square (i.e., dead cell) that is adjacent to exactly three cells gives birthto a new cell for the next generation.It is worth noting that all births and deaths occur at the same time during a generation. Write a program that simulates this game and displays all successive…arrow_forwardIf you have trouble reading the picture please let me know. 8. (a) Write behavioral Verilog code for a module called “Sort2” (pictured below) with three inputs s, a, b and two outputs x, y. The module’s function is also described below; in the function table, a “–” represents a don’t care. Also the function table has s, a as inputs, but the outputs x, y are expressed in terms of the third input b. In words, the “function table” to the left translates to the following: When s = 0, the smallest value among a and b goes to x and the other value goes to y. When s = 1, the largest value among a and b goes to x and the other value goes to y. (b) Structurally connect copies (or instantiations) of the module Sort2 to construct the module Bitonic with four inputs a0,a1,a2,a3 and four outputs z0,z1,z2,z3 shown below; each box in the figure below represents an instantiation of Sort2. Further, the inputs and outputs of the instantiations are located as in the figure above; namely, input to…arrow_forward
- A recursive function in programming is a function that calls itself during its execution. The following two functions are examples of recursive functions: def function1(length): if length > 0: print(length) function1(length - 1) def function2(length): while length > 0: print(length) function2(length - 1) What can you say about the output of function1(3) and function2(3)? The two functions produce the same output 3 2 1. function1 produces the output: 3 2 1 and function2 runs infinitely. 3. function1 produces the output: 3 2 1 and function2 runs infinitely. 4. The two programs produce the same output: 1 2 3arrow_forwardObjective: Practice writing recursive functions in python3 Make the five recursive functions described below in python3 by using the starter code recursive_functions.py. For each function, figure out how to solve it conceptually : write down the base case (when recursion stops) and how each recursive function-call moves towards the base case. The functions should not print anything (except you may add temporary print statements to help debug them). You can test your program by using the provided program test_recursive_functions.py. Don't edit the test program. Put it into the same directory (folder) with your recursive_functions.py and run it. It will import your functions as a module, test your functions, and tell you when each function is returning correct results. 1. Factorial In math, if you have a number n, the factorial function (written n!) computes n x (n-1) x (n-2) x (n-3) x ... x 1. For example: 0! is defined to be 1 1! = 1 2! = 2 x 1=2 3! = 3 x 2 x 1=6 4! = 4 x 3…arrow_forwardGive an example in which passing an argument by reference would be useful.arrow_forward
- 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