Question: Answer each question. Multiple Choice (For each question, there is only one correct answer) (3 x 10 = 30) Every C++ program must contain: A

Answer each question.

  1. Multiple Choice (For each question, there is only one correct answer) (3 x 10 = 30)
  1. Every C++ program must contain:
  1. A cin statement
  2. A cout statement
  3. A main function
  4. All of the above

ii) Given:

double x = 9/5;

cout << x << endl;

  1. 1
  2. 1.8
  3. 2
  4. 4

  1. Evaluate the following expression for the values of a and b as given below:

float a = 3;

float b = 6;

float z = 1/2*(a + b);

cout << Z = << z << endl;

What will the program display?

  1. Z = 4.5
  2. Z = 4
  3. Z = 0
  4. None of the above

  1. Which header file is required to use the rand( ) function?
  1. cmath
  2. iomanip
  3. cstdlib
  4. ctime

iv) Given a switch statement as below:

int x;

cin >> x;

switch(x % 3)

{

case 0:

cout << Option 1 << endl;

break;

case 1:

cout << Option 2 << endl;

break;

default:

cout << Option 3 << endl;

}

Predict the output when x = 2

a) Option 1

b) Option 2

c) Option 3

d) none of the above

  1. What will be the display for the statement given below:

int x = 10;

cout << x++ << endl;

  1. 11
  2. 10
  3. x = 10
  4. 9

vi) Given the following program segment:

int count = 7;

while(count > 1)

{

cout << count << , ;

count /= 2;

}

What will be the output from the above program segment?

  1. 7, 6, 5, 4, 3, 2
  2. 7, 5, 3,
  3. 7, 3, 1,
  4. 7, 3,

vii) Which of the following C++ logical expression is correct to expresses the following description:

X is greater than 5 but less than 10

a) X > 5 || X < 10

b) X > 5 && < 10

c) X > 5 && X < 10

d) X > 5 || < 10

viii) Which operator given below is not a relational operator?

a) >

(b) !=

(c) ==

(d) ++

ix) What will the following statement display:

float x = 24.5397;

cout << x = << x << setprecision(2);

  1. x = 24.54
  2. x = 24.5397
  3. x = 53;
  4. None of the above.

x) The body of a C++ main function is surrounded by:

  1. paranthesis
  2. square brackets
  3. angle brackets

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!