MCQs
cerr is an object of class ostream that represents the standard error stream. It is associated
with the cstdio stream stderr.
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.
There are three types of guarantees in c++. They are weak, strong and no-throw.
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
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
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
We are not allowed to overload the constructors, So it is arising an exception.
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
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 .
None.
A class that expresses functionality rather than its primary design role is called a mixin.
clog is an object of class ostream that represents the standard logging stream. It is associated
with the cstdio stream stderr, like cerr.