CPP 100
CPP 100
following
Type function_name(argument list); Eg float volume(int x,float y);
47.Define constructor
A constructor is a special member function whose task is to initialize the objects
of its class. It is special because its name is same as class name. The constructor
is invoked whenever an object of its associated class is created. It is called
constructor because it constructs the values of data members of the class
Eg:
integer Class
{
……
public:
integer( );//constructo r
………
}
53.Define destructor
It is used to destroy the objects that have been created by constructor. Destructor
name is same as class name preceded by tilde symbol(~)
Eg;
~integer()
{
}
A destructor never takes any arguments nor it does it return any value. The
compiler upon exit from the program will invoke it. new Whenever operator is
used to allocate memory in the constructor, we should
use delete to free that memory.
61.List out the operators that cannot be overloaded using Friend function.
• Assignment operator =
• Function call operator ( )
• Subscripting operator [ ]
• Class member access operator
try
{
//code raising exception or referring to a function raising exception
}
catch(type_id1)
{
//actions for handling an exception
}
…
…
catch(type_idn)
{
//actions for handling an exception 16
}
68. List out the tasks to be performed for error handling code
1)Detect the problem causing exception(Hit the exception)
2)Inform that an error has occurred(Throw the exception)
3)Receive the error information(Catch the exception)
4)Take corrective actions(Handle the exceptions)
template<class T,…>
ReturnType FuncName(arguments)
{
…..//body of the function template
…..
} 17
private members of B.
Major Types
a.Run-time polymorphism
b.Compile time polymorphism
c.ad-hoc polymorphism
d.Parametric polymorphism
e.Virtual functions
f.Function name overloading
g.Operator overloading
iostream
iostream filebuf
fstreambase
100. What are the flags that do not have bit fields?
a)ios::showbase-Use base indicator on output
b)ios::showpos-Print + before positive integers
c)ios::showpoint-Show trailing decimal point and zeros
d)ios::uppercase-Use uppercase letters for hex output
e)ios::unitbuf-Flush all streams after insertion
g)ios::stdio-Flush stdout and stderr after insertion