Section 5.2 Essentials of Counter-Controlled Repetition
5.2 Q1: Which of the following does counter-controlled
repetition require?
A condition that tests for the final value.
Counter-controlled repetition requires all of the
above.
An increment or decrement by which the control variable is modified each time
through the loop.
An initial value.
5.2 Q2: The statement
while ( --counter >= 1 )
counter % 2 ? cout << "A" : cout <<
"B";
cannot be rewritten as:
while ( --counter >= 1 )
if ( counter % 2 )
cout << "A";
else
cout << "B";.
while ( counter >= 1 )
if ( counter % 2 )
cout << "A";
else
cout << "B";.
--counter;
while ( --counter >= 1 )
counter % 2 == 0 ? cout << "B" : cout <<
"A";.
while ( counter > 1 )
{
--counter;
if ( counter % 2 )
cout << "A";
else
cout << "B";
}.
5.2 Q3: Which of the following is a bad programming practice?
Using floating-point values for counters in
counter-controlled repetition.
Indenting the statements in the body of each control structure.
Nesting multiple repetition structures one within another.
Placing vertical spacing above and below control structures.
Section 5.3 for Repetition Statement
5.3 Q1: If a variable is declared in the initialization
expression of a for structure, then:
It can not be used in any structures that are nested in that for structure.
It retains its final value after the loop is finished.
The scope of the variable is restricted to that
particular for loop.
It is automatically reinitialized to zero once the loop is finished.
5.3 Q2: Which of the following is not true?
The initialization and increment expressions can be comma-separated lists.
You must declare the control variable outside of the
for loop.
The three expressions in the for structure are optional.
A for loop can always be used to replace a while loop, and vice versa.
5.3 Q3: Consider the execution of the following for loop
for (int x = 1; x < 5; increment )
cout << x + 1 << endl;
If the last value printed is 5, which of the following might
have been used for increment?
Any of the above.
x += 1.
a. x++.
++x.
Section 5.4 Examples Using the for Statement
5.4 Q1: Which of the following for headers is not valid?
for ( int i = 0; i < 10; i++ ).
int i = 0;
for ( ; i < 10; i++ ).
for ( int i = 0; int j = 5; ; i++ ).
for ( int i =
0: i < 10; ).
A Caution about Using Type double for Monetary Amounts
5.4 Q2: float and double variables should be used:
To perform monetary calculations.
To store true/false values.
As imprecise representations of decimal numbers.
As counters.
Using Stream Manipulators to Format Numeric Output
5.4 Q3: Which of the following is a parameterized stream
manipulator used to format output?
setw.
right.
left.
fixed.
Section 5.5 do…while Repetition Statement
5.5 Q1: If a do…while structure is used:
Counter-controlled repetition is not possible.
The body of the loop will execute at least once.
An infinite loop will not take place.
An off-by-one error will not occur.
5.5 Q2: What will the following program segment do?
int counter = 1;
do {
cout << counter << " ";
} while ( ++counter <= 10 );
Cause a syntax error.
Print the numbers 1 through 11.
Print the numbers 1 through 9.
Print the numbers 1 through 10.
Section 5.6 switch Multiple-Selection Statement
5.6 Q1: A switch statement should be used:
As a multiple-selection structure.
As a single-selection structure.
To replace all if and if…else statements.
As a double-selection structure.
5.6 Q2: In a switch structure:
A default case is required.
A break is required after each case.
A break is required after the default case.
Multiple actions do not need to be enclosed in
braces.
5.6 Q3: Which of the following is correct when labeling cases in
a switch structure?
Case1.
Case 1.
case1.
case 1.
5.6 Q4: switch can be used to test:
all types of constants.
int constants.
string constants.
float constants.
5.6 Q5: Which of the following data types can be used to
represent integers?
long.
short.
char.
All of the above.
Section 5.7 break and continue Statements
5.7 Q1: Which of the following
is False?
break statements exit from the loop in which they are embedded.
continue statements skip the remaining statements in current iteration of the
body of the loop in which they are embedded.
continue and break statements may be embedded within
all C++ structures.
break and continue statements alter the flow of control.
5.7 Q2: Which of the following
is False?
Many programmers feel that break and continue violate structured programming.
The effects of break and continue statements can be achieved by structured
programming techniques.
You should always try to write the fastest, smallest
code possible before attempting to make it simple and correct.
break and continue statements can perform faster than their corresponding
structured techniques.
Section 5.8 Logical Operators
5.8 Q1: In C++, the condition ( 4 > y > 1 ):
Evaluates correctly and could be replaced by ( 4 > y && y > 1 ).
Does not evaluate correctly and should not be
replaced by ( 4 > y && y > 1 ).
Does not evaluate correctly and should be replaced by ( 4 > y && y
> 1 ).
Evaluates correctly and could not be replaced by ( 4 > y && y > 1
).
5.8 Q2: The OR (||) operator:
Stops evaluation upon finding one condition to be
true.
Associates from right to left.
Has higher precedence than the AND (&&) operator.
Is a ternary operator.
5.8 Q3: An operator that associates from right to left is:
().
!=.
?:.
,.
5.8 Q4: The expression if ( num != 65 ) cannot be replaced by:
if ( !( num == 65 ) ).
if ( num > 65 || num < 65 ).
d. if ( !( num – 65 ) ).
if ( num – 65 ).
5.8 Q5: An example of a unary operator is:
The < relational operator.
The = assignment operator.
The % arithmetic operator.
The ! logical operator.
Section 5.9 Confusing Equality (==) and Assignment (=) Operators
5.9 Q1: Variables are also known as:
rvalues, and cannot be used as lvalues.
lvalues, but can be used as rvalues.
Constant variables.
lvalues, and cannot be used as rvalues.
5.9 Q2: Consider the following code, assuming that x is an int
with an initial value of 12
if( x = 6 )
cout << x;
What is the output?
12.
6.
A syntax error is produced.
Nothing.
5.9 Q3: Of the following, which is not a logic error?
Failing to initialize counter and total variables before the body of a
loop.
Not placing curly braces around the body of an if that contains two statements.
Using commas instead of the two required semicolons
in a for header.
Using == to assign a value to a variable.
Section 5.10 Structured Programming Summary
5.10 Q1: The ____________, __________ and ____________ are the
only three forms of control necessary.
break, continue, if…else.
sequence, selection, repetition.
switch, if, else.
for, while, do…while.
5.10 Q2: Which of the following is not one of the C++ control
structures?
if.
switch.
do…while.
main.
5.10 Q3: Which of the following is not one the rules for forming
structured programs?
Any action state can be replaced by any control statement.
Any transition arrow can be reversed.
Begin with the “simplest activity diagram.”
Any action state can be replaced by two action states in sequence
Section 5.11 (Optional) Software Engineering Case Study:
Identifying Objects’ States and Activities in the ATM System
5.11 Q1: Which of the following is not a part of a UML state
diagram?
A solid circle indicating the initial state.
Arrows with accompanying event description text representing transitions.
Rounded rectangles representing states.
Fractions beside each state indicating the likelihood
of entering that state.
5.11 Q2: An activity diagram for modeling the actions involved
in executing a balance inquiry transaction using the BalanceInquiry object
should not include:
Retrieving the user’s balance information from the database of accounts.
All of the above actions should be modeled in this activity diagram.
Receiving the user’s main menu input indicating a
desire to inquire the amount of his or her balance.
Displaying the user’s balance information on the screen.
The statement cout
<< yptr will show the __________the yptr points to.
Value
Memory Address
Variabvle
None of given
Value
Memory Address
Variabvle
None of given
char **argv can be read as__________________.
Pointer to Pimter
Pointer to Char
Pointer to Pointer to Char (page 177)
None of given
_______________are
conventional names of the command line parameters of the ‘main()’ function.
‘argb’ and ‘argv’
‘argc’ and ‘argv’
‘argc’ and ‘argu’
None of Given
___________ Returns true if c is a digit and false otherwise.
int isalpha( int c )
int isalnum( int c )
int isxdigit( int c )
int isdigit( int c )
‘argb’ and ‘argv’
‘argc’ and ‘argv’
‘argc’ and ‘argu’
None of Given
___________ Returns true if c is a digit and false otherwise.
int isalpha( int c )
int isalnum( int c )
int isxdigit( int c )
int isdigit( int c )
In the case of pointer to pointer or _______________, the first pointer contains the address of the second pointer, which contains the address of the variable, which contains the desired value.
double dereference (page 175)
Single dereference
dereference
None of the given
_______________________ contains functions for manipulations of character data.
ctype.h
iostream.h
string.h
None of the given
dereferencing operator is represented by _______
*
+
-
None of the given
In_________, we try to
have a precise problem statement
Analysis
Design
Coding
None of the given
Analysis
Design
Coding
None of the given
The stream-insertion
operator is >> and the stream-extraction operator is <Select correct
option:
True
True
False
Reference:
C++, >> is called
the stream extraction operator or simply the extraction operator
C++, << is called
the stream insertion operator or simply the insertion operator.
(DATA STRUCTURES
USING C++ 2nd Edition by D.S.Malik)
When we used eof (end
of file) with the file reading than which of the following is a true
statement?
Select correct option:
This is way to check source of the stream
This is way to check destination of the stream
This is way to check state of the stream
This is way to check type of the stream
Select correct option:
This is way to check source of the stream
This is way to check destination of the stream
This is way to check state of the stream
This is way to check type of the stream
The streams have a state
that can be checked by us. We have used eof (end of file) with the file
reading. This is a way to check the state of the stream.
Question # 1 of
10 Total Marks: 1
< and > both are _________ operators.
Arithmetic
Relational
Logical PG 258
Mathematical
< and > both are _________ operators.
Arithmetic
Relational
Logical PG 258
Mathematical
Question # 2 of
10 Total Marks: 1
Find out the logical error in following lines of code. If (x = 10) cout << “x is 10”;
10 should be enclosed in quotations
There is no semicolon at the end of if condition
Assignment operator should not be used for comparison
Variable x should not be inside parenthesis
Find out the logical error in following lines of code. If (x = 10) cout << “x is 10”;
10 should be enclosed in quotations
There is no semicolon at the end of if condition
Assignment operator should not be used for comparison
Variable x should not be inside parenthesis
Question # 3 of
10 Total Marks: 1
What will be the result of the expression j = i++; if initially j = 0 and i = 5?
0
5
6
4
What will be the result of the expression j = i++; if initially j = 0 and i = 5?
0
5
6
4
Question # 4 of
10 Total Marks: 1
Default mechanism of calling a function by passing it array is call by ________ and in case of passing variable is call by ________.
Reference, Reference
Reference, value PG154, 119
Value, Reference
Value, Value
Question # 5 of 10 Total Marks: 1
When the break statement is encountered in a loop’s body, it transfers the control ________from the current loop.
Inside
Outside
To break statement
To continue statement
Default mechanism of calling a function by passing it array is call by ________ and in case of passing variable is call by ________.
Reference, Reference
Reference, value PG154, 119
Value, Reference
Value, Value
Question # 5 of 10 Total Marks: 1
When the break statement is encountered in a loop’s body, it transfers the control ________from the current loop.
Inside
Outside
To break statement
To continue statement
Question # 6 of
10 Total Marks: 1
________statement is used to terminate the processing of a particular case and exit from switch structure.
If
Goto
Break
Continue
http://msdn.microsoft.com/en-us/library/wt88dxx6(v=vs.80).aspx
________statement is used to terminate the processing of a particular case and exit from switch structure.
If
Goto
Break
Continue
http://msdn.microsoft.com/en-us/library/wt88dxx6(v=vs.80).aspx
Question # 7 of 10
Total Marks: 1
When the if statement consists of more than one statement then enclosing these statement in braces is _________.
Compulsory
Optional
Not required
Relevant
Question # 8 of 10 Total Marks: 1
What will be the value of the variable output in the given piece of code? double output = 0; output = (2 + 2) * 4 + 2 / (4 – 2);
15
17
12
1
Question # 9 of 10 Total Marks: 1
If we assign 2.06721 to an integer variable x, what will be the output if we print x using cout<< statement?
2
2.1
2.06
2.07
When the if statement consists of more than one statement then enclosing these statement in braces is _________.
Compulsory
Optional
Not required
Relevant
Question # 8 of 10 Total Marks: 1
What will be the value of the variable output in the given piece of code? double output = 0; output = (2 + 2) * 4 + 2 / (4 – 2);
15
17
12
1
Question # 9 of 10 Total Marks: 1
If we assign 2.06721 to an integer variable x, what will be the output if we print x using cout<< statement?
2
2.1
2.06
2.07
Question # 10 of
10 Total Marks: 1
__________ will be used for clarity and to force the order of evaluation in an expression.
" "
() PG32
' '
[]
__________ will be used for clarity and to force the order of evaluation in an expression.
" "
() PG32
' '
[]
Post a Comment
Don't Forget To Join My FB Group VU Vicky
THANK YOU :)