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 Problem Analysis to Program Design
- Q/ Fill in the table below with the correct answers for the network devices and components required, then draw the topology diagram for the network of this three-story building: I want a drawing Cisco Packet tracer Ground Floor: This floor will house the main server room, reception area, and a few conference rooms. The server room should contain the core network devices that will connect the entire building. The reception area and conference rooms need network access require access for mobile devices for visitors and guests with devices. First Floor: This floor is dedicated to offices with workstations, each needing reliable network connectivity for staff computers, IP phones, IP camera, and printers. Second Floor (Education Department): This floor consists of educational spaces requiring controlled internet access. Only the educational website (https://uokerbala.edu.iq) should be accessible, with all other sites restricted.. Device Media type Location floor Type of IP Static/dynamic…arrow_forwardProblem Statement You are working as a Devops Administrator. Y ou’ve been t asked to deploy a multi - tier application on Kubernetes Cluster. The application is a NodeJS application available on Docker Hub with the following name: d evopsedu/emp loyee This Node JS application works with a mongo database. MongoDB image is available on D ockerHub with the following name: m ongo You are required to deploy this application on Kubernetes: • NodeJS is available on port 8888 in the container and will be reaching out to por t 27017 for mongo database connection • MongoDB will be accepting connections on port 27017 You must deploy this application using the CL I . Once your application is up and running, ensure you can add an employee from the NodeJS application and verify by going to Get Employee page and retrieving your input. Hint: Name the Mongo DB Service and deployment, specifically as “mongo”.arrow_forwardI need help in server client project. It is around 1200 lines of code in both . I want to meet with the expert online because it is complicated. I want the server send a menu to the client and the client enters his choice and keep on this until the client chooses to exit . the problem is not in the connection itself as far as I know.I tried while loops but did not work. please help its emergentarrow_forward
- I need help in my server client in C languagearrow_forwardExercise docID document text docID document text 1 hot chocolate cocoa beans 7 sweet sugar 2345 9 cocoa ghana africa 8 sugar cane brazil beans harvest ghana 9 sweet sugar beet cocoa butter butter truffles sweet chocolate 10 sweet cake icing 11 cake black forest Clustering by k-means, with preprocessing tokenization, term weighting TFIDF. Manhattan Distance. Number of cluster is 2. Centroid docID 2 and docID 9.arrow_forwardChange the following code so that there is always at least one way to get from the left corner to the top right, but the labyrinth is still randomized. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. Take care that the player and the dragon cannot start off on walls. Also the dragon starts off from a randomly chosen position public class Labyrinth { private final int size; private final Cell[][] grid; public Labyrinth(int size) { this.size = size; this.grid = new Cell[size][size]; generateLabyrinth(); } private void generateLabyrinth() { Random rand = new Random(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { // Randomly create walls and paths grid[i][j] = new Cell(rand.nextBoolean()); } } // Ensure start and end are…arrow_forward
- Change the following code so that it checks the following 3 conditions: 1. there is no space between each cells (imgs) 2. even if it is resized, the components wouldn't disappear 3. The GameGUI JPanel takes all the JFrame space, so that there shouldn't be extra space appearing in the frame other than the game. Main(): Labyrinth labyrinth = new Labyrinth(10); Player player = new Player(9, 0); Dragon dragon = new Dragon(9, 9); JFrame frame = new JFrame("Labyrinth Game"); GameGUI gui = new GameGUI(labyrinth, player, dragon); frame.add(gui); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); public class GameGUI extends JPanel { private final Labyrinth labyrinth; private final Player player; private final Dragon dragon; //labyrinth, player, dragon are just public classes private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");…arrow_forwardMake the following game user friendly with GUI, with some simple graphics. The GUI should be in another seperate class, with some ImageIcon, and Game class should be added into the pane. The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return…arrow_forwardDiscuss the negative and positive impacts or information technology in the context of your society. Provide two references along with with your answerarrow_forward
- A cylinder of diameter 10 cm rotates concentrically inside another hollow cylinder of inner diameter 10.1 cm. Both cylinders are 20 cm long and stand with their axis vertical. The annular space is filled with oil. If a torque of 100 kg cm is required to rotate the inner cylinder at 100 rpm, determine the viscosity of oil. Ans. μ= 29.82poisearrow_forwardMake the following game user friendly with GUI, with some simple graphics The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return isWall; } public void setWall(boolean isWall) { this.isWall = isWall; } @Override public String toString() {…arrow_forwardPlease original work What are four of the goals of information lifecycle management think they are most important to data warehousing, Why do you feel this way, how dashboards can be used in the process, and provide a real life example for each. Please cite in text references and add weblinksarrow_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