a)
To prove whether the given statement is true or false.
a)
The given statement is True.
Explanation of Solution
Explanation:
The flow of control in
In procedural programming, the flow of control is same as the sequence in which the instructions and statements are written.
But in an object-oriented programming language, the flow of control differs due to function calls.
Conclusion:
Hence, in object-oriented programming paradigm also, the flow of control indicates the order in which statements execute in a program.
b)
To prove that the given statement is true or false.
b)
The given statement is False.
Explanation of Solution
Explanation:
The equality operator in C++ comprises of two equal symbols, that is, ==. The equality operator is used together with if statement in order to verify whether the values of two variables are equal or not.
The single equal symbol, =, is called the assignment operator which is used to assign values to variables.
Conclusion:
Hence, the given statement is False.
c)
To prove that the given statement is true or false.
c)
The given statement is False.
Explanation of Solution
Explanation:
When an if statement is written, the expression is written inside a pair of round brackets that does not ends with a semicolon. Whereas if the semicolon is placed after the expression in the if statement, it will not generate an expected result. Ending an if statement with a semicolon means ending the condition. It will check the condition but will end it in the same line and the logic will not be applied to the further statements.
Conclusion:
Hence, the given statement is False.
(d)
To prove that the given statement is true or false.
(d)
The given statement is False.
Explanation of Solution
Explanation:
An if statement should have a corresponding else or not is decided by the requirements of the program. If the program requires, then every if statement will have a corresponding else statement. Otherwise, if the program does not require, the if statement will not have a corresponding else part.
Whether an if statement will have a corresponding else part or not, is only decided by the program requirements and is not mandatory. A program will execute properly if only an if statement is written.
Conclusion:
Hence, the given statement is False.
(e)
To prove whether the given statement is true or false.
(e)
The given statement is False.
Explanation of Solution
Given statement:
The expression in the if statement:
if(score=30)
grade = ‘A’;
Explanation:
The expression inside the if statement assigns the variable score with a value of 30. The assignment statement is always True. Hence, in all the scenarios, the if statement will always evaluate to True and the grade variable will be assigned value ‘A’.
Conclusion:
Thus, the given statement is True.
(f)
To prove whether the given statement is true or false.
(f)
The given statement is True.
Explanation of Solution
Given statement:
The expression:
if(ch>=’A’ && ch<=’Z’)
Explanation:
The given if statement contains two conditions that are combined by “&&” operator. That is, when both the conditions are satisfied only then the if statement will evaluate to True.
For input ch<’A’, the first condition is not satisfied hence the if statement evaluates to False.
For input ch>=’Z’, both the conditions are satisfied only and only if ch=’Z’ but not for ch>’Z’.
Thus, for either of the inputs, the if statement evaluates to False.
Conclusion:
Hence, the given statement is True.
g)
To prove whether the given statement is true or false.
g)
The given statement is True.
Explanation of Solution
Given statement:
The given code is as follows.
cin >> num; if(num > 5) cout << num; num=0; else cout << “Num is zero” << endl;
Explanation:
In the given code, the if statement will be executed only when the input is greater than 5, otherwise the else statement will be executed.
The input for the given code is 5. Since the input is not greater than 5, the if statement will not be executed.
Here, for the input of 5, the else statement will be executed, and the output will be “Num is zero”.
Conclusion:
Hence, the given statement is True.
(h)
To prove whether the given statement is true or false.
(h)
The given statement is True.
Explanation of Solution
Explanation:
The result of a logical expression is either True or False. That is, a logical expression will always give a Boolean result.
A Boolean value can only be assigned to a Boolean variable but not to an int variable.
Conclusion:
Hence, the given statement is True.
(i)
To prove whether the given statement is true or false.
(i)
The given statement is True.
Explanation of Solution
Explanation:
The given expression is a combination of two statements. The first statement is x>0 which checks if the value of x is greater than 0. The second statement is “!” which inverts the result of the expression, x>0. It means that the “!” operator makes the expression as x<0.
Hence, the expression, x<0, can only be true for negative numbers.
Conclusion:
Thus, the given statement is True.
(j)
To prove whether the given statement is true or false.
(j)
The given statement is False.
Explanation of Solution
Explanation:
In C++, there are three logical operators. They are “&&”or AND operator, “||” or OR operator, and “!” or NOT operator.
The “!” operator is a logical operator.
The “!=” operator is an equality operator since it checks if one value is not equal to another value.
Conclusion:
Hence, the given statement is False.
(k)
To prove whether the given statement is true or false.
(k)
The given statement is True.
Explanation of Solution
Explanation:
In C++, there are four types of simple data types. They are integer, float, string, and boolean.
The expression in the switch statement is usually a variable. A variable can have any one of the simple data types.
In some cases when the switch contains an expression, the result of the expression can only evaluate to a value of the simple data type.
Conclusion:
Hence, the given statement is True.
Want to see more full solutions like this?
Chapter 4 Solutions
C++ Programming: From Problem Analysis to Program Design
- Change 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_forwardChange 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_forward
- Discuss the negative and positive impacts or information technology in the context of your society. Provide two references along with with your answerarrow_forwardA 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_forward
- Please 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_forwardThe following is code for a disc golf program written in C++: // player.h #ifndef PLAYER_H #define PLAYER_H #include <string> #include <iostream> class Player { private: std::string courses[20]; // Array of course names int scores[20]; // Array of scores int gameCount; // Number of games played public: Player(); // Constructor void CheckGame(int playerId, const std::string& courseName, int gameScore); void ReportPlayer(int playerId) const; }; #endif // PLAYER_H // player.cpp #include "player.h" #include <iomanip> Player::Player() : gameCount(0) {} void Player::CheckGame(int playerId, const std::string& courseName, int gameScore) { for (int i = 0; i < gameCount; ++i) { if (courses[i] == courseName) { // If course has been played, then check for minimum score if (gameScore < scores[i]) { scores[i] = gameScore; // Update to new minimum…arrow_forwardIn this assignment, you will implement a multi-threaded program (using C/C++) that will check for Prime Numbers and Palindrome Numbers in a range of numbers. Palindrome numbers are numbers that their decimal representation can be read from left to right and from right to left (e.g. 12321, 5995, 1234321). The program will create T worker threads to check for prime and palindrome numbers in the given range (T will be passed to the program with the Linux command line). Each of the threads works on a part of the numbers within the range. Your program should have some global shared variables: • numOfPrimes: which will track the total number of prime numbers found by all threads. numOfPalindroms: which will track the total number of palindrome numbers found by all threads. numOfPalindromic Primes: which will count the numbers that are BOTH prime and palindrome found by all threads. TotalNums: which will count all the processed numbers in the range. In addition, you need to have arrays…arrow_forward
- How do you distinguish between hardware and a software problem? Discuss theprocedure for troubleshooting any hardware or software problem. give one reference with your answer.arrow_forwardYou are asked to explain what a computer virus is and if it can affect computer’shardware or software. How do you protect your computer against virus? give one reference with your answer.arrow_forwardDistributed Systems: Consistency Models fer to page 45 for problems on data consistency. structions: Compare different consistency models (e.g., strong, eventual, causal) for distributed databases. Evaluate the trade-offs between availability and consistency in a given use case. Propose the most appropriate model for the scenario and explain your reasoning. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440AZF/view?usp=sharing]arrow_forward
- 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 LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT