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, Loose-leaf Version
- For below facts, rules, and goals write English Meanings. (1) color(carrots, orange). (2) likes(Person, carrots):-vegetarian(Person). (3) pass(Student) :- study_hard(Student). (4) ?- pass(Who). (5) ?- teaches(professor, Course). (6) enemies(X, Y) :- hates(X, Y), fights(X, Y). What answers do you get for below queries for given program.Program : vegetarian(jose). vegetarian(james). vegetable(carrot). vegetable(egg_plant). likes(jose, X) :- vegetable(X). loves(Who, egg_plant) :- vegetarian(Who).Queries : ?- vegetable(X). ?- vegetable(potato). ?- vegetarian(_). ?- likes(jose, What). ?- likes(Who, egg_plant). ?- loves(Who, egg_plant)arrow_forward7. The rules of writing 'if-then-else', 'case-switch', 'while-until' and 'for' control flow statements are called _____ . a. Comments b. Functions c. Line length and wrapping d. Control Structurearrow_forwardLet p be “It is cold” and let q be “It is raining”. Give a simple verbal sentence which describes each of the following statements: a) ~p b) p ∧ q c) p ∨ qarrow_forward
- A lady behaves like a teacher in a classroom, mother or daughter in a home and customer in a market. Here, a single person is behaving differently according to the situations. Consider a above real-life example and which concept you will use in cpp. Elaborate the concept write the program in C++arrow_forwardThe principles that govern the construction of control flow statements, such as "if-then-else," "case-switch," "while-until," and "for," are collectively referred to as "____," and their definitions are as follows:arrow_forwardAn initial block statement can no longer be used after a certain point in time has passed.arrow_forward
- The use of computers in education is referred to as computer-assisted instruction (CAI). One problem that develops in CAI environments is student fatigue. This problem can be eliminated by varying the computer's dialogue to hold the student's attention. Modify the program in Exercise 9.22 to print one of a variety of comments for each correct answer and each incorrect an- swer. The set of responses for correct answers is as follows: Very good! Excellent! Nice work! Keep up the good work! The set of responses for incorrect answers is as follows: No. Please try again. Wrong. Try once more. Don't give up!No. Keep trying. Use random number generation to choose a number from 1 to 4 that will be used to select an appropriate response to each answer. Use a switch statement to issue the responses.arrow_forwardWhen are conditional statements used? What are the advantages of utilizing if-then statements? What ement7| differences exist between each statem?arrow_forward1.You should write a C-program to create a fixed maze of size 25 × 40 and place the @ symbol atthe entrance of the maze as shown in diagram below 2.You should define four keys on the keyboard for moving in the left/right/up and down directionsso that you can move the @ character in order to find your way through the maze till the exitpoint,3. The program should time how long it takes for a player to reach the exit point and should comparethis value to the previous scores which may exist in a text file and inform the player how manypeople who have played before has done better than him/her. Last player’ score should also beappended to the existing scores of the earlier players that are already in the text file.arrow_forward
- EXERCISE WEEK 7 (USE C++ CODING) Based on the image attached, shows a statement of a program are in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter; for a circle, it outputs the area and circumference; and for a cylinder, it outputs the volume and surface area. After rearranging the statements, your program should be properly indented.arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. In C++ A county collects property taxes on the assessment value of property, which is 60 percent of the property's actual value. If an acre of land is valued at $10,000, its assessment value is $6,000. The property tax is then 75 cents for each $100 of the assessment value. The tax for the acre assessed at $6,000 will be $45. Write a C++ program that asks for the actual value of a piece of property, then displays the assessment value and property tax. Just write the body of the main, no includes needed. The property tax should be a constant.arrow_forwardDescription This lab assignment is loosely based on the End-of-Chapter Exercises Engineering P4.25. Review the instructions there for helpful information, such as the formula for radioactive decay. The example provided is Technetium-99 with a half-life of 6 hours. Your program should allow the user to enter the name of the radioisotope and the half-life (in hours). Write a program in c++ that will 1. a) Greet the user by name. Provide the user with a brief description of the program. 2. b) Invite the user to try the program. Allow user to choose. 3. c) Ask the user for the name of the radioisotope and the half-life (in hours). 4. d) Based on the given formula for radioactive decay in the text, print out a table of time and remaining relative level of radioactivity. (You may choose the increment for time. Provide an explanation of your choice.) At hour 0, the relative amount is 1.000. Ask the user for the length of time, in hours, since exposure. The table should have rows for as many…arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr