Professional Documents
Culture Documents
C++model Practical Viva Question and Answers
C++model Practical Viva Question and Answers
1.FUNCTION OVERLOAING: A program contains more than one function and each
function has a same function name and having different parameters.
5.OBJECT: an object is an element (or instance) of a class; objects have the behaviors of
their class.
6.HOW TO PASS AN OBJECT TO FUNCTION: We can pass class's objects as arguments and
also return them from a function.
EX: function_name(object_name);
7. COMPLEX NUMBERS are the numbers that are expressed in the form of a+ib where, a,b
are real numbers and 'i' is an imaginary number called “iota”. The value of i = (√-1). For
example, 2+3i is a complex number, where 2 is a real number (Re) and 3i is an imaginary
number (Im).
8. A FRIEND FUNCTION is a function that isn't a member of a class but has access to the
class's private and protected members.
9. The ‘this’ pointer is passed as a hidden argument to all nonstatic member function
calls and is available as a local variable within the body of all nonstatic functions.
~ className( no arguments )
}.
12.OPERATOR OVERLOAING: the ability to provide the operators with a special meaning
for a data type, this ability is known as operator overloading.
13.UNARY OPERATOR OVERLOAING: Unary operators are the operators that perform
operations on a single operand to produce a new value.
1. Unary minus ( – )
2. Increment ( ++ )
3. Decrement ( - - )
16. INHERITANCE: The capability of a class to derive properties and characteristics from
another class is called Inheritance.
17. SINGLE INHERITANCE: In single inheritance, a class is allowed to inherit from only
one class. i.e. one subclass is inherited by one base class only.
18. MULTIPLE INHERITANCE: Multiple Inheritance is a feature of C++ where a class can
inherit from more than one class. i.e one subclass is inherited from more than one base
class.
19. MULTILEVEL INHERITANCE: In this type of inheritance, a derived class is created
from another derived class.
20. HIERARCHICAL INHERITANCE: In this type of inheritance, more than one subclass is
inherited from a single base class. i.e. more than one derived class is created from a single
base class.
22. A VIRTUAL FUNCTION (also known as virtual methods) is a member function that is
declared within a base class and is re-defined (overridden) by a derived class.
Functions are declared with a virtual keyword in a base class.
23. FILE HANDLING IN C++ is a mechanism to create and perform read/write operations
on a file.
#include <fstream>
<fstream> includes two classes for file handling:
ifstream - to read from a file.
ofstream - to create/open and write to a file.
25.READ FILE:
ifstream my_file("example.txt");
while (!my_file.eof()) {
getline(my_file, line); }
26.WRITE FILES:
ofstream my_file("example.txt"); my_file << "Line 1" << endl;
27. COMMAND-LINE ARGUMENTS: are arguments that are passed to a program when it
is executed from the command line. to pass command-line arguments, we typically define
main() with two arguments,
29.TEMPLATE: is to pass the data type as a parameter so that we don’t need to write the
same code for different data types.
30.CLASS TEMPLATE: class templates are useful when a class defines something that is
independent of the data type. template<class T1,class T2>
31.FUNCTION TEMPLATE: a generic function that can be used for different data types.
Examples of function templates are sort(), max(), min()
template<class T>
T max(T a,T b)
Separate Error code from Normal code to help us understand errors easily.