Material

advertisement
Multiple Choice Questions:
1) The control structure that is used for loops that involve counting is called
a)
b)
c)
d)
if
if/else
for
switch
2) The statement that is executed at the beginning of the loop and never again is called
a)
b)
c)
d)
update
repetition
sequential
initialization
3) The statements in a program are executed one after the other in the order in which they are written
is called
a)
b)
c)
d)
structured execution
parallel execution
sequential execution
dynamic execution
4) The double selection structure that selects between two different actions is called
a)
b)
c)
d)
if
if/else
while
do/while
5) What is the output when the following code fragment is executed?
enum color_type {red, orange, yellow, green, blue, violet};
color_type shirt, pants;
shirt = red;
pants = blue;
cout << shirt <<" "<< pants << endl;
a) red blue
b) blue red
c) 0 4
d) 5
e) 4 0
6) What is the output when the following code fragment is executed?
int i = 5, j = 6, k = 7, n = 3;
cout << i + j * k – k % n;
a) 43
b) 44
c) 45
d) 46
e) 47
7) for ( int i = 0; i < 4; i = i+5 )
cout << “I am in FAST\n”;
Write the output of the above code?
I am in FAST
8) What will be the result, after execution of the following code if a is 10, b is 5 and c is 10?
if ((a>b) && (a<=c))
a = a + 1;
else
c = c + 1;
a) a = 10, c = 10
b) a = 11, c = 10
c) a = 10, c = 11
d) a = 11, c = 11
9) What will be the value of variable count after the following code execution?
int count = 2;
void function1(void);
void main ( void )
{
for ( int loop = 0; loop < 20; loop += 2 )
{
function1( );
loop += 1;
}
cout << “The value of count is = “ << count << endl;
}
void function1(void)
{
count ++;
}
a)
b)
c)
d)
e)
2
10
9
8
7
10) What values will be printed of variables x and y in the following code execution:-
int x = 2, y = 5;
y = x++ + ++x;
cout << ++y <<”…” << x++;
a)
b)
c)
d)
e)
6…3
6…4
6…5
7…4
7…5
Q.No.1 Write for structure C++ statements for the following conditions: (4)
1. Vary the control variable from 68 to 6 in increments of –1
for ( int i = 68; i >= 6; i = i-1 )
2. Vary the control variable from 7 to 77 in steps of 7.
for ( int i = 7; i <= 77; i = i+7 )
3. Vary the control variable from 24 to 2 in steps of –2.
for ( int i = 24; i >= 2; i = i-2 )
4. Vary the control variable over the following sequence of values: 2, 5, 8, 11, 13, 17, 20
Not possible
More Programs
Write a program that takes three integers as inputs and prints the largest of the three
integers.
A worker is paid at the hourly rate of $8 per hour for the first 35 hours worked.
Hereafter overtime is paid at 1.5 times the hourly rate for the next 25 hours worked
and 2 times the hourly rate for further hours worked. Write a C++ program to input
the number of hours worked per week, calculate and output the overtime paid.
Write a loop to print all numbers from 1 to 100, one per line, Write a blank line after
every five lines.
Download