C++ mcqs

Mar 26th, 2014
Steve1995
Category:
Programming
Price: $20 USD

Question description

What is the termination condition for the following While loop?

while (beta > 0 && beta < 10)
{
     cout << beta << endl;
     cin >> beta;
}

		
beta > 0 && beta < 10

		
beta >= 0 && beta <= 10

		
beta < 0 || beta > 10

		
beta <= 0 || beta >= 10
===
Indicate where (if at all) the following loop needs a priming read.

count = 1;                                         // Line 1
while (count <= 10)                         // Line 2
{                                                        // Line 3
     cin >> number;                           // Line 4
     cout << number * 2;                   // Line 5
     counter++;                                   // Line 6                 
}                                                        // Line 7
		
between lines 1 and 2

		
between lines 3 and 4

		
between lines 5 and 6

		
between lines 6 and 7

		
No priming read is necessary.

===
Give the input data

25 10 6 -1

What is the output of the following code fragment? (All variables are of type int.)

sum = 0;
cin >> number;
while (number != -1)
{
     cin >> number;
     sum = sum + number;
}
cout << sum << endl;

		
15

		
41

		
40

		
16

		
no output--this is an infinite loop

====
After execution of the following code, what is the value of length? (count and length are of type int.)

length = 5;
count = 4;
while (count <= 6)
{
     if (length >= 100)
         length = length - 2;
     else
         length = count * length;
     count++;
}

		
600

		
100

		
98

		
20

		
none of the above

====
What is the output of the following code fragment? (finished is a Boolean variable, and firstInt and secondInt are of type int.)

finished = FALSE;
firstInt = 3;
secondInt = 20;
while (firstInt <= secondInt && !finished)
     { if (secondInt / firstInt <= 2)    // Reminder: integer division
           finished = TRUE;
     else
           firstInt++; }
cout << firstInt << endl;

		
3

		
5

		
7

		
8

		
9

====
In the following code fragment, a semicolon appears at the end of the line containing the While condition.

cout << 'A';
loopCount = 1;
while (loopCount <= 3);
{
     cout << 'B';
     loopCount++;
}
cout << 'C';

The result will be:

		
the output AC

		
the output ABC

		
the output ABBBC

		
a compile-time error

		
an infinite loop

======

What is the output of the following code fragment? (All variables are of type int.)

sum = 0;
outerCount = 1;
while (outerCount <= 3)
{
    innerCount = 1;
    while (innerCount <= outerCount)
    {
         sum = sum + innerCount;
         innerCount++;
    }
    outerCount++;
}
cout << sum << endl;

		
1

		
4

		
10

		
20

		
35

====
In the C++ program fragment

count = 1;
while (count < 10)
    count++;
    cout << "Hello";

the output statement that prints "Hello" is not part of the body of the loop.
 True
 False
====
In C++, an infinite loop results from using the assignment operator in the following way:

while (gamma = 2)
{
     . . . 
}

 True
 False
====
The body of a do...while loop is always executed (at least once), even if the while condition is not satisfied:

 True
 False
=====
What is the out put of the following c++ code fragment?

int count = 3;

while (count-- > 3)

cout << count<<" " ;

		
1 2 3

		
0 1 2

		
3 2 1

		
2 1 0

		
none of above.this code fragment returns a syntax error.

====
what is the out put of the following code fragment:

int count = 3;

while (-- count > 0)

cout<< count<<" "<<endl;
		
0 1 2 

		
2 1 0

		
1 2 

		
2 1

		
none of the above.this loop returns a syntax error.

==

Tutor Answer

(Top Tutor) Daniel C.
(997)
School: Cornell University
PREMIUM TUTOR

Studypool has helped 1,244,100 students

8 Reviews


Summary
Quality
Communication
On Time
Value
pmallory
Dec 3rd, 2016
" Totally impressed with results!! :-) "
mixedballz
Nov 24th, 2016
" excellent work as always thanks for the help "
Five Star Tutor
Nov 22nd, 2016
" Outstanding Job!!!! "
kiln82
Nov 10th, 2016
" awesome work thanks "
darnay
Nov 1st, 2016
" The best tutor out there!!!! "
likeplum4
Oct 28th, 2016
" Excellent work as usual "
kpcutie
Oct 5th, 2016
" Excellent job "
Joemoe
Sep 26th, 2016
" <3 it, thanks for saving me time. "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1823 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors