Flow Of Control
(Sumita Arora) Textbook Solutions 7th Edn
credits:openclipart |
SHORT ANSWER QUESTIONS
Q1: What is null statement and a compound statement? What is the alternate name of the compound statement?Answer: The simplest statement is null statement or empty statement. It is represented as just semicolon (;).
e.g. ; // null statement
A compound statement is a sequence of statements enclosed by pair of braces ({}). Alternate name of the compound statement is block.
Q2: What is the significance of a null statement?
Answer: A null statement is useful where the language requires a statement but the program's logic does not.
e.g. a program keeps on reading a value till it encounters a particular value or end-of-file. while (cin >> val && val != required_vale) ;
Q3: What are the three constructs that govern statement flow?
Answer: sequence, selection and iteration
Q4: What is the significance of a test-condition in a loop?
Answer: The test-condition in a loop decides whether the loop-body will be executed or not based on the truth value. If the test-condition evaluates to true i.e., 1, the loop-body will execute, otherwise the loop is terminated.
Q5: What is a selection statement? Which selection statement does C++ provides?
Answer: The selection statement conditionally executes another statement (or block of statements) based on whether a specified expression is true. C++ provides two types of selection statements: if and switch.
Q6: Can a conditional operator replace an if statement always?
Answer: No in conditional operator usually replaces if statement but not always.
Q7: Correct the following code fragment:
if (x=1) k=100; else k=1O;
Answer: it should be if (x == 1)
Q8: What will be the output of the following code fragment?
cin >> a; if (a=5) cout << "Five"; else cout << "Not Five"; if the input given is (1)7 (ii)5?
Answer: (Note: Please see if (a=5) assigns 5 to a. An assignment operator is used instead of equality operator. That's why if (condition) is always true.)
(1) Five
(2) Five
Q9: What will be the output of the following code fragment?
int year; cin >> year; if (year%100 == 0) if(year%400 == 0) cout << "LEAP"; else cout << "Not century year"; if the input given is (i)2000 (ii)1900 (iii) 1971?
Answer:
(i) LEAP
(ii) Not century year
(iii) No output
Q10: What will be the output of the following code fragment?
int year; cin >> year; if (year%100 == 0) { if(year%400 == 0) cout << "LEAP"; } else cout << "Not century year"; if the input given is (i)2000 (11)1900 (iii) 1971?
Answer: (i) LEAP
(ii) No output
(iii) Not century year
(In progress...)
meh.. incomplete...
ReplyDeletepl complete the remaining questions...
ReplyDeletenice please complete
ReplyDeletewe are waiting and our exam is in progress !!!!!
ReplyDeleteincomplete
ReplyDeleteincomplete
ReplyDelete