
Concept explainers
Mark 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. (1)
A value-returning function returns only one value. (2, 3)
Parameters allow you to use different values each time the function is called. (2, 7, 9)
When a return statement executes in a user-defined function, the function immediately exits. (3, 4)
A value-returning function returns only integer values. (4)
A variable name cannot be passed to a value parameter. (3, 6)
If a C++ function does not use parameters, parentheses around the empty parameter list are still required. (2, 3, 6)
In C + +, the names of the corresponding formal and actual parameters must be the same. (3, 4, 6)
A function that changes the value of a reference parameter also changes the value of the actual parameter. (7)
Whenever the value of a reference parameter changes, the value of the actual parameter changes. (7)
In C++, function definitions can be nested; that is, the definition of one function can be enclosed in the body of another function. (9)
Using global variables in a program is a better
programming style than using local variables, because extra variables can be avoided. (10)In a program, global constants are as dangerous as global variables. (10)
The memory for a static variable remains allocated between function calls. (11)
(a)

To find whether the given statement is true or false.
False.
Explanation of Solution
Given information:
The name of the function and the definition of the function are given.
Explanation:
To use a predefined function in a program, the complete signature of a function should be known. The signature of a function comprises the return type, the name of the function, and the number and data types of the parameters required by the function if any.
Hence, the given statement is FALSE.
(b)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
The function returns a value hence the return type is not void.
Explanation:
A function can either return a value or not return any value. A function that does not returns a value has the return type of void whereas a function that returns a value has a return type such as int, float, and so on. The return type can be any valid data type supported by the language.
A non-void function can have only one return statement. That means, a function can return only one value.
Hence, the given statement is TRUE.
(c)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
A function that takes parameters.
Explanation:
A function that takes parameters can take any value of the specified data type of the parameter. Hence, such a function can be called many times using a different set of values, and calling the same function multiple times with a different list of parameters is called function overloading.
An example program is as follows:
void display(int n) { cout<<n<<endl; } int main() { display(1); display(2); return 0; }
Output:
The output of the above example program is as follows:
1
2
In the above program, the display() function is called multiple times with different values and generates different outputs.
Conclusion:
Hence, the given statement is TRUE.
(d)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
A function that returns a value.
Explanation:
A function that returns a value ends with a return statement. The return statement is the last in a value-returning function. The return statement returns a value and passes the control outside of the function. Therefore, it can be said that after executing the return statement, the function exits.
Hence, the given statement is TRUE.
(e)

To find whether the given statement is true or false.
False.
Explanation of Solution
Given information:
A function that returns a value.
Explanation:
The nature of the value returned by a function depends upon the return type of the function. The return type of a function can be any valid data type supported by the language. It can be of primitive data type such as int, float, char, and so on and it can also be of a user-defined type such as an object.
Conclusion:
Therefore, a value-returning function will always return a value having type as of return type of function and will not always be an integer. Hence, the given statement is FALSE.
(f)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
A function that takes parameters.
Explanation:
A function that takes value parameters must be passed values and not variable names. A variable name can be passed as a reference variable using the & symbol. This is not acceptable to a function that takes value parameters.
Hence, the given statement is TRUE.
(g)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
A function that does not takes parameters.
Explanation:
A set of parenthesis identifies a function irrespective of whether a function takes parameters or not. A function is always defined and declared using the parenthesis after the function name. If a function is not having any parameters, then the parenthesis will be blank otherwise variables can be declared in the parenthesis. Hence, parentheses in a function are always required.
Thus, the given statement is TRUE.
(h)

To find whether the given statement is true or false.
False.
Explanation of Solution
Given information:
A function that takes parameters.
Explanation:
When a function takes parameters, the formal variables refer to the names of the parameters included in the function definition. While the actual variables are the names of the variables that are passed as parameters while calling the parameterized function.
When a function that takes parameters is called, the parameters are passed either using direct values or variable names that have been initialized. In case, variables are passed when calling the parameterized function, the name of the actual variables doesn't have to be the same as the names of the formal variables.
Hence, the given statement is FALSE.
(i)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
A function that takes parameters.
Explanation:
When a variable is passed by reference to a parameterized function, the address of the actual parameter is passed via the reference variable. Any change made to the value at the given address will reflected in the actual parameter also.
Hence, the given statement is TRUE.
(j)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
A function that takes parameters by reference.
Explanation:
Whenever a function to which parameters are passed by reference, the address of the actual parameters is passed. Any change to the value at the given address will reflect in the actual parameter.
Hence, the given statement is TRUE.
(k)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
Nested functions.
Explanation:
C++ allows functions to be nested. That is, the body of one function can be placed inside the body of another function.
An example program is as follows:
int main() { void outside() { cout << “outside” << endl; void inside() { cout << “inside” << endl; } } inside(); return 0; }
Output:
inside
outside
In the above example, it is seen that the inside() function is defined within the outside() function. While calling the function, the function that is nested, that is inside() function is called.
Conclusion:
Hence, the given statement is TRUE.
(l)

To find whether the given statement is true or false.
False.
Explanation of Solution
Given information:
Global variables.
Explanation:
C++ allows global variables to be used in a program. However, there are some issues associated with the usage of global variables. First, the use of global variables makes the maintenance of the code difficult. Secondly, it is difficult to track global variables throughout the program. To avoid such issues, local variables are used.
Hence, the given statement is FALSE.
(m)

To find whether the given statement is true or false.
False.
Explanation of Solution
Given information:
Global variables.
Explanation:
C++ allows global constants to be used in a program. Such constants are declared at the beginning of the program outside all the functions. Such constants help in the faster execution of the program and make the code compact since the constant is defined only once throughout the program.
Hence, the given statement is FALSE.
(n)

To find whether the given statement is true or false.
True.
Explanation of Solution
Given information:
Static variables.
Explanation:
C++ allows static variables in a program. The value of a static variable remains unchanged in between the function calls. This is possible since the memory remains allocated to the static variables even between the function calls.
Hence, the given statement is TRUE.
Want to see more full solutions like this?
Chapter 6 Solutions
C++ PROGRAMMING:FROM...(LL) >CUSTOM<
- a database with multiple tables from attributes as shown above that are in 3NF, showing PK, non-key attributes, and FK for each table? Assume the tables are already in 1NF. [Hint: 3 tables will result after deducing 1NF -> 2NF -> 3NF]arrow_forwarda database with multiple tables from attributes as shown above that are in 3NF, showing PK, non-key attributes, and FK for each table? Assume the tables are already in 1NF. [Hint: 3 tables will result after deducing 1NF -> 2NF -> 3NF]arrow_forwardIf a new entity Order_Details is introduced, will it be a strong entity or weak entity? If it is a weak entity, then mention its type (ID or Non-ID, also Justify why)?arrow_forward
- Which one of the 4 Entities mention in the diagram can have a recursive relationship? Order, Product, store, customer.arrow_forwardInheritance & Polymorphism (Ch11) There are 6 classes including Person, Student, Employee, Faculty, and Staff. 4. Problem Description: • • Design a class named Person and its two subclasses named student and Employee. • Make Faculty and Staff subclasses of Employee. • A person has a name, address, phone number, and e-mail address. • • • A person has a class status (freshman, sophomore, junior and senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString() method in each class to display the class name and the person's name. 4-1. Explain on how you would code this program. (1 point) 4-2. Implement the program. (2 point) 4-3. Explain your code. (2 point)arrow_forwardSuppose you buy an electronic device that you operate continuously. The device costs you $300 and carries a one-year warranty. The warranty states that if the device fails during its first year of use, you get a new device for no cost, and this new device carries exactly the same warranty. However, if it fails after the first year of use, the warranty is of no value. You plan to use this device for the next six years. Therefore, any time the device fails outside its warranty period, you will pay $300 for another device of the same kind. (We assume the price does not increase during the six-year period.) The time until failure for a device is gamma distributed with parameters α = 2 and β = 0.5. (This implies a mean of one year.) Use @RISK to simulate the six-year period. Include as outputs (1) your total cost, (2) the number of failures during the warranty period, and (3) the number of devices you own during the six-year period. Your expected total cost to the nearest $100 is _________,…arrow_forward
- Which one of the 4 Entities mention in the diagram can have a recursive relationship? If a new entity Order_Details is introduced, will it be a strong entity or weak entity? If it is a weak entity, then mention its type (ID or Non-ID, also Justify why)?arrow_forwardPlease answer the JAVA OOP Programming Assignment scenario below: Patriot Ships is a new cruise line company which has a fleet of 10 cruise ships, each with a capacity of 300 passengers. To manage its operations efficiently, the company is looking for a program that can help track its fleet, manage bookings, and calculate revenue for each cruise. Each cruise is tracked by a Cruise Identifier (must be 5 characters long), cruise route (e.g. Miami to Nassau), and ticket price. The program should also track how many tickets have been sold for each cruise. Create an object-oriented solution with a menu that allows a user to select one of the following options: 1. Create Cruise – This option allows a user to create a new cruise by entering all necessary details (Cruise ID, route, ticket price). If the maximum number of cruises has already been created, display an error message. 2. Search Cruise – This option allows to search a cruise by the user provided cruise ID. 3. Remove Cruise – This op…arrow_forwardI need to know about the use and configuration of files and folders, and their attributes in Windows Server 2019.arrow_forward
- Southern Airline has 15 daily flights from Miami to New York. Each flight requires two pilots. Flights that do not have two pilots are canceled (passengers are transferred to other airlines). The average profit per flight is $6000. Because pilots get sick from time to time, the airline is considering a policy of keeping four *reserve pilots on standby to replace sick pilots. Such pilots would introduce an additional cost of $1800 per reserve pilot (whether they fly or not). The pilots on each flight are distinct and the likelihood of any pilot getting sick is independent of the likelihood of any other pilot getting sick. Southern believes that the probability of any given pilot getting sick is 0.15. A) Run a simulation of this situation with at least 1000 iterations and report the following for the present policy (no reserve pilots) and the proposed policy (four reserve pilots): The average daily utilization of the aircraft (percentage of total flights that fly) The…arrow_forwardWhy is JAVA OOP is really difficult to study?arrow_forwardMy daughter is a Girl Scout and it is time for our cookie sales. There are 15 neighbors nearby and she plans to visit every neighbor this evening. There is a 40% likelihood that someone will be home. If someone is home, there is an 85% likelihood that person will make a purchase. If a purchase is made, the revenue generated from the sale follows the Normal distribution with mean $18 and standard deviation $5. Using @RISK, simulate our door-to-door sales using at least 1000 iterations and report the expected revenue, the maximum revenue, and the average number of purchasers. What is the probability that the revenue will be greater than $120?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 PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning




