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.
- Multiple Choice (For each question, there is only one correct answer) (3 x 10 = 30)
- Every C++ program must contain:
- A cin statement
- A cout statement
- A main function
- All of the above
ii) Given:
double x = 9/5;
cout << x << endl;
- 1
- 1.8
- 2
- 4
- 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?
- Z = 4.5
- Z = 4
- Z = 0
- None of the above
- Which header file is required to use the rand( ) function?
- cmath
- iomanip
- cstdlib
- 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
- What will be the display for the statement given below:
int x = 10;
cout << x++ << endl;
- 11
- 10
- x = 10
- 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?
- 7, 6, 5, 4, 3, 2
- 7, 5, 3,
- 7, 3, 1,
- 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);
- x = 24.54
- x = 24.5397
- x = 53;
- None of the above.
x) The body of a C++ main function is surrounded by:
- paranthesis
- square brackets
- angle brackets
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
