Sail E0 Webinar

MCQs

Total Questions : 10
Question 1.

What does the cerr represent?


  1.    Standard error stream
  2.    Standard logging stream
  3.    Input stream
  4.    Output stream
 Discuss Question
Answer: Option A. -> Standard error stream

cerr is an object of class ostream that represents the standard error stream. It is associated 

with the cstdio stream stderr.


Question 2.

Which operator is used to create the user-defined streams in c++?


  1.    >>
  2.    &
  3.    Both a & b
 Discuss Question
Answer: Option D. -> Both a & b

We can make user-defined types with streams by overloading the insertion operator (<<) to put

 objects into streams and the extraction operator (>>) to read objects from streams.


Question 3.

How many types of guarantees are there in exception class can have?


  1.    1
  2.    2
  3.    3
  4.    4
 Discuss Question
Answer: Option C. -> 3

There are three types of guarantees in c++. They are weak, strong and no-throw.


Question 4.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
string s = "a long string";
7.
s.insert(s.size() / 2, " * ");
8.
cout
  1.    a long* string
  2.    a long st*ring
  3.    Depends on compiler
  4.    None of the mentioned
 Discuss Question
Answer: Option C. -> Depends on compiler

In this program, We are placing the string based on the size of the string and it is a string hierarchicy.
Output:
$ g++ class2.cpp
$ a.out
a long* string


Question 5.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class MyException
4.
{
5.
public:
6.
MyException(int value) : mValue(value)
7.
{
8.
}
9.
int mValue;
10.
};
11.
class MyDerivedException : public MyException
12.
{
13.
public:
14.
MyDerivedException(int value, int anotherValue) : MyException(value), mAnotherValue(anotherValue)
15.
{
16.
}
17.
int mValue;
18.
int mAnotherValue;
19.
};
20.
void doSomething()
21.
{
22.
throw MyDerivedException(10,20);
23.
}
24.
int main()
25.
{
26.
try
27.
{
28.
doSomething();
29.
}
30.
catch (MyDerivedException &exception)
31.
{
32.
cout
  1.    Caught Base Class Exception
  2.    Caught Derived Class Exception
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Caught Derived Class Exception

As we are throwing the value from the derived class, it is arising an exception in derived class
Output:
$ g++ class1.cpp
$ a.out
Caught Derived Class Exception


Question 6.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
class Base
4.
{
5.
public:
6.
Base(){}
7.
~Base(){}
8.
protected:
9.
private:
10.
};
11.
class Derived:public Base
12.
{
13.
public:
14.
Derived(){}
15.
Derived(){}
16.
private:
17.
protected:
18.
};
19.
int main()
20.
{
21.
cout
  1.    The program executed
  2.    Error
  3.    Runtime error
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Error

We are not allowed to overload the constructors, So it is arising an exception.


Question 7.


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
int main()
5.
{
6.
stringstream mys(ios :: in | ios :: out);
7.
std :: string dat("The double value is : 74.79 .");
8.
mys.str(dat);
9.
mys.seekg(-7, ios :: end);
10.
double val;
11.
mys >> val;
12.
val = val*val;
13.
mys.seekp(-7,ios::end);
14.
mys
  1.    5593.54
  2.    Error
  3.    Runtime error
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> 5593.54

In this program, We have used the string hierarchicy to compute the square of the number.
Output:
$ g++ class.cpp
$ a.out
The double value is : 5593.54 .


Question 8.

What will happen when introduce the interface of classes in a run-time polymorphic hierarchy?


  1.    Separation of interface from implementation
  2.    Merging of interface from implementation
  3.    Separation of interface from debugging
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Separation of interface from implementation

None.


Question 9.

Which classes are called as mixin?


  1.    Represent a secondary design
  2.    Classes express functionality which represent responsibilities.
  3.    Both a & b
  4.    None of the mentioned
 Discuss Question
Answer: Option B. -> Classes express functionality which represent responsibilities.

A class that expresses functionality rather than its primary design role is called a mixin.


Question 10.

What is the use of clog?


  1.    Standard logging stream
  2.    Error stream
  3.    Input stream
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> Standard logging stream

clog is an object of class ostream that represents the standard logging stream. It is associated 

with the cstdio stream stderr, like cerr.


Latest Videos

Latest Test Papers