Class Hierarchies Introduction(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option D. -> Both a & bWe 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.
Explanation:-
Answer: Option C. -> Depends on compilerIn 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
Explanation:-
Answer: Option B. -> Caught Derived Class ExceptionAs 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
Explanation:-
Answer: Option B. -> ErrorWe 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
Explanation:-
Answer: Option A. -> 5593.54In 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 .