Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 32

DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++

UNIT – II

ADVANCED OBJECT ORIENTED PROGRAMMING


 Inheritance
 Extending classes
 Pointers
 Virtual functions and polymorphism
 File
 Handling Templates
 Exception handling
 Manipulating strings
2.1. Inheritance
Definition
The mechanism of deriving the new class from an old one is called inheritance. The old class is called as
base class and the new class is called as derived class.
Types of Inheritance
i. Single inheritance
ii. Multiple inheritance
iii. Multilevel inheritance
iv. Hierarchical inheritance
v. Hybrid inheritance
i. Single Inheritance
The new class can be derived from only one base class is called single inheritance.

Fig: Single Inheritance


Defining derived classes:
A derived class is defined by specifying its relationship with the base class in addition to its own details.
The general format is
class derived classname: visibility mode baseclassname
{
. . . . . // body of derived class
};
Visibility mode is optional; it may be either private or public. The default visibility mode is private.
Eg:
class ABC : private xyz {
// body of ABC
};
class ABC : public xyz {
//body of ABC
};
class ABC : xyz // private derivation by default {
//body of ABC
};
Example program
#include <iostream.h>
class A
{
protected:
int data;
public:
void getdata(int x)
{
data1 = x;
}
};
class B: public A
{
public:
void setdata(int y) {data2 = y;}
void display( )
{
cout<<”data1”<<data1;
cout<<”data2”<< data2;
}
};
void main( )
{
B s;
s.getdata(10);
s.setdata(20);
s.display( );}
}
Explanation
The new class ‘B’ can be derived by the base class ‘A’. The base class A publicly inherited to a derived
class ‘A’.
Protected:
The protected data members will be accessible by its own class and which class is immediately derived
from its that class also have the rights to access the protected data member (will be act as protected data
member of a derived class also).
In the program, using the derived class object we can access the member function of getdata and setdata fro
giving the value of data1 and data2. In the display function multiply the value of data1 and data2 and
display the result.

ii. Multilevel inheritance


The multilevel inheritance is defined as, the new class is derived from another derived class.
It is represented as,
Fig: Multilevel Inheritance
Here the class A serves as a base class for the derived class B which in turn serves as a
base class for the derived class C. The derived class is defined as, G.F.
class A{
//body of base class A
};
class B : public A {
//body of intermediate base class B
};
class C : public B {
//body of derived class
};
Example Program
#include <iostream.h>
class student
{
protected:
int rollno:
public:
void getroll(int x)
{
rollno = x;
}
};
void test: public student
{
protected:
float sub1, sub2;
public:
void getmart(int y, int z)
{
sub1 = y; sub2= z;
}
};
void result : public test
{
float total;
public:
void display( )
{
total = sub1 + sub2;
cout<<rollno<<sub1<<sub2;
cout<<total;
}
};
void main( )
{
result s;
s.getroll(101);
s.getmark(90, 100);
s.display( );
}
iii. Multiple Inheritance
A class can inherit the attributes or properties of two or more classes that is a new class can be derived from
more than one base class is called multiple inheritance.
This can be represented as:

Fig: Multilevel Inheritance


Here the class A and class B serves as a base class for the derived class D. The derived class definition
syntax is:
class d: visibility base-1, visibility base 2,…
{
body of class D;
};
Example:
#include<iostream.h>
class A
{
protected:
int rollno;
public:
void getroll(int x)
{
rollno=x;
}
};
class B
{
protected:
int sub1,sub2;
public:
void getmark(int y,int z)
{
sub1=y;
sub2=z;
}
};
class C : public A, public B
{
int total;
public:
void display()
{
total=sub1+sub2;
cout<<”roll no:”<<rollno<<”sub1:”<<sub1<<”sub2:”<<sub2;
cout<<”total”<<total;
}
};
void main()
{
C s;
s. getroll(435);
s.getmark(100,90);
s.display();
}
iv.. Hybrid Inheritance
The hybrid inheritance is defined as a combination of multilevel and multiple inheritances. This new class
can be derived by either multilevel or multiple method or both.
Example program
In this program the derived class (result) object will be inheriting the properties of both test class and sports
class.
#include <iostream.h>
class student
{
protected:
int rollno;
public:
void getroll (int x)
{
rollno = x;
}
};
class test: public student
{
protected:
int sub1, sub2’
public:
void getmark (int y, int z)
{
sub1 = y; sub2 = z;
}
};
class sports
{
protected:
int score;
public:
void getscore (int a )
{
score=a;
}
};
class result: public test, public sports
{
int total;
public:
void display()
{
total= sub1+sub2+score;
cout<<”rollno:”<<rollno<< “total:”<<”Score:”<<total;
}
};
void main( )
{
result S;
s.getroll(101);
s.getmark(90,98);
s.getscore(2000);
s. display( );
}
2.2. Virtual Base Classes
An element of ambiguity can be introduced into a C++ program when multiple base classes are inherited.
For example, consider this incorrect program:
// This program contains an error and will not compile.
#include <iostream>
using namespace std;
class base
{
public:
int i;
};
// derived1 inherits base.
class derived1 : public base
{
public:
int j;
};
// derived2 inherits base.
class derived2 : public base
{
public:
int k;
};
/* derived3 inherits both derived1 and derived2. This means that there are two copies of base in
derived3! */
class derived3 : public derived1, public derived2
{
public:
int sum;
};
int main()
{
derived3 ob;
ob.i = 10;
ob.j = 20;
ob.k = 30;
ob.sum = ob.i + ob.j + ob.k;
cout << ob.i << " ";
cout << ob.j << " " << ob.k << " ";
cout << ob.sum;
return 0;
}

2.3. Pointers

A pointer is a variable that is used to store a memory address. The address is the location of the variable in
the memory. Pointers help in allocating memory dynamically. Pointers improve execution time and saves
space.  Pointer points to a particular data type. The general form of declaring pointer is:-

             type *variable_name;

 type is the base type of the pointer and variable_name is the name of the variable of the pointer. For
example,

             int *x;

 x is the variable name and it is the pointer of type integer.  

Pointer Operators

There are two important pointer operators such as ‘*’ and ‘&’. The ‘&’ is a unary operator. The unary
operator returns the address of the memory where a variable is located.  For example,

             int x*;

            int c;

            x=&c;

 variable x is the pointer of the type integer and it points to location of the variable c. When the statement

                           x=&c;


 is executed, ‘&’ operator returns the memory address of the variable c and as a result x will point to the
memory location of variable c.  The ‘*’ operator is called the indirection operator. It returns the contents of
the memory location pointed to.  The indirection operator is also called deference operator. For example,

             int x*;

            int c=100;

            int p;

x=&c;

            p=*x;

 variable x is the pointer of integer type. It points to the address of the location of the variable c. The
pointer x will contain the contents of the memory location of variable c. It will contain value 100. When
statement

                        p=*x;

 is executed, ‘*’ operator returns the content of the pointer x and variable p will contain value 100 as the
pointer x contain value 100 at its memory location.  Here is a program which illustrates the working of
pointers.

 #include<iostream>

 int main ()

            int *x;

            int c=200;

            int p;

            x=&c;

            p=*x;

            cout << " The address of the memory location of x : " << x << endl;

            cout << " The contents of the pointer x : " << *x << endl;

            cout << " The contents of the variable p : " << p << endl;

            return(0);

}
Pointer Arithmetic

There are only two arithmetic operations that can be performed on pointers such as addition and
subtraction. The integer value can be added or subtracted from the pointer. The result of addition and
subtraction is an address. The difference of the two memory addresses results an integer and not the
memory address. When a pointer is incremented it points to the memory location of the next element of its
base type and when it is decremented it points to the memory location of the previous element of the same
base type. For example,

             int *x;

            int *p;

            p=x++;

 here x and p are pointers of integer type. Pointer x is incremented by 1. Now variable p points to the
memory location next to the memory location of the pointer x. Suppose memory address of x is 2000 and
as a result p will contain memory address 2004 because integer type takes four bytes so the memory
address is incremented by 4. Incrementing the pointer results in incrementing the memory address by the
number of bytes occupied by the base type. For example,

       double *x;

      double *p;

      p=x++;

 variables x and p are pointers of double type. Pointer x is incremented by 1. Now if the memory address of
x was 2000 and after incrementing p will contain memory address 2008 as double takes 8 bytes.
Decrementing the pointer results in decrementing the memory address by the number of bytes occupied by
the base type. You cannot add two pointers. No multiplication and division can be performed on pointers.
Here is a program which illustrates the working of pointer arithmetic.

 #include<iostream>

 int main ()

            int *x;

            int *p,*q;

            int c=100,a;

            x=&c;

            p=x+2;
            q=x-2;

            a=p-q;

            cout << "The address of x : " << x << endl;

            cout << "The address of p after incrementing x by 2 : " << p << endl;

            cout << "The address of q after derementing  x by 2 : " << q << endl;

            cout << " The no of elements between p and q :" << a << endl;

            return(0);

Pointers and Arrays

 The pointers and arrays have a very close relationship. The pointer can be set to the address of the first
element of the array. For example,

             int age[];

            int *p;

            p=&age;

p will point to the address of the first element of the array. For example

             (p+4)

 will point to the fifth element of the array.  Pointers are helpful where size of the array is unknown.
Declaring the array with a size of large value wastes lot of space. Pointers improve the execution time.
Here is a program which illustrates the working of arrays and pointers.

2.4. Polymorphism
Polymorphism is the ability to take more than one form. An operation may exhibit different behaviors in different.
The behavior depends upon the type of data used.

Types of polymorphism

 Runtime polymorphism (eg: Virtual Function)


 Compile time polymorphism (eg: Function and Operator Overloading)

Compile time polymorphism


 The overloaded member functions are selected for invoking by matching arguments both type and number.
This information is known to the compiler at the compile time and therefore compiler is able to select the
appropriate function for a particular call at the compile time itself.This is called early binding or static
binding or static linking. Also known as compile time polymorphism

Examples of compile time polymorphism

 Function overloading
 Operator overloading

2.4.1. Virtual Functions


Virtual functions allow polymorphism. If a function is not declared virtual it will be impossible to
override it in a child class. Virtual method is a method that you should override when inheriting that class.
It uses virtual as a keyword.

Basic rules for virtual functions

 Virtual functions must be member of some class.


 They cannot be static members and they are accessed by using object pointers
 Virtual f unction in a base class must be defined.

 Prototypes of base class version of a virtual function and all the derived class versions must be
identical.
 If a virtual function is defined in the base class, it need not be redefined in the derived class.

To begin, examine this short example:


#include <iostream>
class base
{
public:
virtual void vfunc()
{
cout << "This is base's vfunc().\n";
}
};
class derived1 : public base
{
public:
void vfunc()
{
cout << "This is derived1's vfunc().\n";
}
};
class derived2 : public base
{
public:
void vfunc()
{
cout << "This is derived2's vfunc().\n";
}
};
int main()
{
base *p, b;
derived1 d1;
derived2 d2;
p = &b;
p->vfunc(); // access base's vfunc()
p = &d1;
p->vfunc(); // access derived1's vfunc()
p = &d2;
p->vfunc(); // access derived2's vfunc()
return 0;
}
This program displays the following:
This is base's vfunc().
This is derived1's vfunc().
This is derived2's vfunc().
Pure virtual function

A pure virtual function is a function declared in a base class that has no definition relative to the base class.
In such cases, the compiler requires each derived class to either define the function or re declare it as a pure
virtual function. A class containing pure virtual functions cannot be used to declare any object of its own. It
is also known as “do nothing” function. The “do-nothing” function is defined as follows: virtual void
display ( ) =0;

A pure virtual function is a virtual function that has no definition within the base class. To declare a pure
virtual function, use this general form:
virtual type func-name(parameter-list) = 0;
Example Program
#include <iostream>
class number
{
protected:
int val;
public:
void setval(int i) { val = i; }
// show() is a pure virtual function
virtual void show() = 0;
};
class hextype : public number
{
public:
void show()
{
cout << hex << val << "\n";
}
};
class dectype : public number
{
public:
void show()
{
cout << val << "\n";
}
};
class octtype : public number
{
public:
void show()
{
cout << oct << val << "\n";
}
};
int main()
{
dectype d;
hextype h;
octtype o;
d.setval(20);
d.show(); // displays 20 - decimal
h.setval(20);
h.show(); // displays 14 - hexadecimal
o.setval(20);
o.show(); // displays 24 - octal
return 0;
}
Abstract Classes
A class that contains at least one pure virtual function is said to be abstract. Because an abstract class
contains one or more functions for which there is no definition (that is, a pure virtual function), no objects
of an abstract class may be created. Instead, an abstract class constitutes an incomplete type that is used as a
foundation for derived classes.
Although you cannot create objects of an abstract class, you can create pointers and references to an
abstract class. This allows abstract classes to support run-time polymorphism, which relies upon base-class
pointers and references to select the proper virtual function.
2.5. File Handling

File. The information / data stored under a specific name on a storage device, is called a file.

Stream. It refers to a sequence of bytes.

Text file. It is a file that stores information in ASCII characters. In text files, each line of text is terminated
with a special character known as EOL (End of Line) character or delimiter character. When this EOL
character is read or written, certain internal translations take place.

Binary file. It is a file that contains information in the same format as it is held in memory. In binary files,
no delimiters are used for a line and no translations occur here.    

Classes for file stream operation

ofstream: Stream class to write on files


ifstream: Stream class to read from files
fstream: Stream class to both read and write from/to files.

Opening a file

OPENING FILE USING CONSTRUCTOR


ofstream fout(“results”);    //output only
ifstream fin(“data”);  //input only

OPENING FILE USING open()


Stream-object.open(“filename”, mode)

      ofstream ofile;


      ofile.open(“data1”);
     
      ifstream ifile;
      ifile.open(“data2”);

File mode parameter Meaning


ios::app Append to end of file
ios::ate go to end of file on opening
ios::binary file open in binary mode
ios::in open file for reading only
ios::out open file for writing only
ios::nocreate open fails if the file does not exist
ios::noreplace open fails if the file already exist
ios::trunc delete the contents of the file if it exist

All these flags can be combined using the bitwise operator OR (|). For example, if we want to open the file
example.bin in binary mode to add data we could do it by the following call to member function open():

fstream file;
file.open ("example.bin", ios::out | ios::app | ios::binary);

CLOSING FILE

   fout.close();
   fin.close();

INPUT AND OUTPUT OPERATION

put() and get() function


the function put() writes a single character to the associated stream. Similarly, the function get() reads a
single character form the associated stream.
example :
file.get(ch);
file.put(ch);

write() and read() function


write() and read() functions write and read blocks of binary data.
example:
file.read((char *)&obj, sizeof(obj));
file.write((char *)&obj, sizeof(obj));

ERROR HANDLING FUNCTION

FUNCTIONRETURN VALUE AND MEANING


returns true (non zero) if end of file is encountered while reading;
eof()
otherwise return false(zero)
fail() return true when an input or output operation has failed
returns true if an invalid operation is attempted or any unrecoverable
bad()
error has occurred.
good() returns true if no error has occurred.

FILE POINTERS AND THEIR MANIPULATION

All i/o streams objects have, at least, one internal stream pointer:
ifstream, like istream, has a pointer known as the get pointer that points to the element to be read in the next
input operation.

ofstream, like ostream, has a pointer known as the put pointer that points to the location where the next
element has to be written.
Finally, fstream, inherits both, the get and the put pointers, from iostream (which is itself derived from both
istream and ostream).

These internal stream pointers that point to the reading or writing locations within a stream can be
manipulated using the following member functions:

seekg() moves get pointer(input) to a specified location


seekp() moves put pointer (output) to a specified location
tellg() gives the current position of the get pointer
tellp() gives the current position of the put pointer

 The other prototype for these functions is:

seekg(offset, refposition );
seekp(offset, refposition );

The parameter offset represents the number of bytes the file pointer is to be moved from the location
specified by the parameter refposition. The refposition takes one of the following three constants defined in
the ios class.

ios::beg          start of the file


ios::cur          current position of the pointer
ios::end          end of the file

example:
file.seekg(-10, ios::cur);

Program to read from text file and display it

#include<fstream.h>
#include<conio.h>
int main()
{
     ifstream fin;
     fin.open("out.txt");
     char ch;
     while(!fin.eof())
     {
          fin.get(ch);
          cout<<ch;
     }
     fin.close();
     getch();
     return 0;
}

2.6. Templates
Templates are a feature of the C++ programming language that allows functions and classes to operate with
generic types. This allows a function or class to work on many different data types without being rewritten
for each one.
Types of templates
 Function template
 Class template
Function template
A function template specifies how an individual function can be constructed. The limitation of such
functions is that they operate only on a particular data type. It can be overcome by defining that function as
a function template or generic function.
Syntax of function template
template<class T,…>
ReturnType FuncName(arguments)
{
}
// Function template example.
#include <iostream>
using namespace std;
// This is a function template.
template <class X> void swapargs(X &a, X &b)
{
X temp;
temp = a;
a = b;
b = temp;
}
int main()
{
int i=10, j=20;
double x=10.1, y=23.3;
char a='x', b='z';
cout << "Original i, j: " << i << ' ' << j << '\n';
cout << "Original x, y: " << x << ' ' << y << '\n';
cout << "Original a, b: " << a << ' ' << b << '\n';
swapargs(i, j); // swap integers
swapargs(x, y); // swap floats
swapargs(a, b); // swap chars
cout << "Swapped i, j: " << i << ' ' << j << '\n';
cout << "Swapped x, y: " << x << ' ' << y << '\n';
cout << "Swapped a, b: " << a << ' ' << b << '\n';
return 0;
}
Class template
Classes can also be declared to operate on different data types. Such classes are called class templates. A
class template specifies how individual classes can be constructed similar to normal class specification
// class templates
#include <iostream>
template <class T>
class mypair
{
T a, b;
public:
mypair (T first, T second)
{
a=first; b=second;
}
T getmax ();
};
template <class T>
T mypair<T>::getmax ()
{
T retval;
retval = a>b? a : b;
return retval;
}

int main ()
{
mypair <int> myobject (100, 75);
cout << myobject.getmax();
return 0;
}
2.7. Exception handling

n exception is a situation that would be unusual for the program that is being processed. As a programmer,
you should anticipate any abnormal behavior that could be caused by the user entering wrong information
that could otherwise lead to unpredictable results.

An error result or an unpredictable behavior on your program not caused by the operating system but that
occurs in your program is called an exception. The ability to deal with a program’s eventual abnormal
behavior is called exception handling. C++ provides three keywords to handle an exception.

1. Trying the normal flow: To deal with the expected behavior of a program, use the try keyword as
in the following syntax:

try {Behavior}

The try keyword is required. It lets the compiler know that you are anticipating an abnormal
behavior and will try to deal with it. The actual behavior that needs to be evaluated is included
between an opening curly bracket “{“ and a closing curly bracket “}”. Inside of the brackets,
implement the normal flow that the program should follow, at least for this section of the code.
2. Catching Errors: During the flow of the program as part of the try section, if an abnormal
behavior occurs, instead of letting the program crash or instead of letting the compiler send the error
to the operating system, you can transfer the flow of the program to another section that can deal
with it.

try {
// Try the program flow
}
catch(Argument)
{
// Catch the exception
}
3. Throwing an error: There are two main ways an abnormal program behavior is transferred from
the try block to the catch clause. This transfer is actually carried by the throw keyword. Unlike the
try and catch blocks, the throw keyword is independent of a formal syntax but still follows some
rules.

Facing an Exception

An exception is a behavior that should not occur in your program but is likely to show up. The
simplest exception looks like a conditional statement and here is an example:
#include <iostream>
int main()
{
int StudentAge;
cout << "Student Age: ";
cin >> StudentAge;
try
{
if(StudentAge < 0)
throw;
cout << "\nStudent Age: " << StudentAge << "\n\n";
}
catch(...)
{
}
cout << "\n";
return 0;
}

Catching Multiple Exceptions

The exceptions as we have seen so far dealt with a single exception in a program. Most of the time, a
typical program will throw different types of errors. The C++ language allows you to include
different catch blocks. Each catch block can face a specific error. The syntax used is:
try {
Code to Try
}
catch(Arg1)
{
One Exception
}
catch(Arg2)
{
Another Exception
}
The compiler would proceed in a top-down as follows:
1. Following the normal flow control of the program, the compiler enters the try block.
2. If no exception occurs in the try block, the rest of the try block is executed.
If an exception occurs in the try block, the try displays a throw that specifies the type of error
that happened.
a. The compiler gets out of the try block and examines the first catch
b. If the first catch doesn’t match the thrown error, the compiler proceeds with the next
catch. This continues until the compiler finds a catch that matches the thrown error.
c. If one of the catches matches the thrown error, its body executes. If no catch matches
the thrown error, you have (or the compiler has) two alternatives. If there is no catch
that matches the error (which means that you didn’t provide a matching catch), the
compiler hands the program flow to the operating system (which calls the terminate()
function). Another alternative is to include a catch whose argument is three periods:
catch(…). The catch(…) is used if no other catch, provided there was another,
matches the thrown error. The catch(…), if included as part of a catch clause, must
always be the last catch, unless it is the only catch of the clause.

Multiple catches are written if or when a try block is expected to throw different types of errors.
Imagine a program that requests some numbers from the user and performs some operation on the
numbers. Such a program can be written as follows:
 
#include <iostream.h>
int main()
{
double Operand1, Operand2, Result;
char Operator;
cout << "This program allows you to perform an operation on two numbers\n";
cout << "To proceed, enter a number, an operator, and a number:\n";
cin >> Operand1 >> Operator >> Operand2;
switch(Operator)
{
case '+':
Result = Operand1 + Operand2;
break;
case '-':
Result = Operand1 - Operand2;
break;
case '*':
Result = Operand1 * Operand2;
break;
case '/':
Result = Operand1 / Operand2;
break;
default:
cout << "Bad Operation";
}
cout << "\n" << Operand1 << " " << Operator << " "
<< Operand2 << " = " << Result;
cout << "\n\n";
return 0;
}
2.8. Manipulating strings
 The C++ strings library provides the definitions of the basic_string class, which is a class template
specifically designed to manipulate strings of characters of any character type.

 A string is a sequence of character.


 􀁼We have used null terminated <char> arrays (C-strings or C-style strings) to store and manipulate
strings.
 􀁼ANSI C++ provides a class called string.
 􀁼We must include <string> in our program.

AVAILABLE OPERATIONS
 Creating string objects.
 Reading string objects from keyboard.
 Displaying string objects to the screen.
 Finding a substring from a string.
 Modifying string objects.
 Adding string objects.
 Accessing characters in a string.
 Obtaining the size of string.

COMMONLYUSEDSTRINGCONSTRUCTORS

String();// For creating an empty string.


String(const char *str);// For creating a string object from a null-terminated string.
String(const string &str);// For creating a string object from other string object.
CREATINGSTRINGOBJECTS
1 string s1, s3;// Using constructor with no arguments.
2 string s2(“xyz”);// Using one-argument constructor.
3 s1 = s2;// Assigning string objects
4 s3 = “abc” + s2;// Concatenating strings
5 cin>> s1;// Reading from keyboard (one word)
6 cout<< s2;// Display the content of s2
7 getline(cin, s1)// Reading from keyboard a line of text
8 s3 += s1;// s3 = s3 + s1;
9 s3 += “abc”;// s3 = s3 + “abc”;

MANIPULATINGSTRINGOBJECTS
1 string s1(“12345”);
2 string s2(“abcde”);
3 s1.insert(4, s2);// s1 = 1234abcde5
4 s1.erase(4, 5);// s1 = 12345
5 s2.replace(1, 3, s1);// s2 = a12345e

MANIPULATINGSTRINGOBJECTS
1 insert()
2 erase()
3 replace()
4 append()

RELATIONALOPERATIONS

1 string s1(“ABC”); string s2(“XYZ”);


intx = s1.compare(s2);x == 0 if s1 == s2
x > 0 if s1 > s2
x < 0 if s1 < s2
0
STRING CHARACTERISTICS
2 void display(string &str)
3 {
0 cout<< “Size = ” << str.size() << endl;
1 cout<< “Length = ” << str.length() << endl;
2 cout<< “Capacity = ” << str.capacity() << endl;
3 cout<< “Max Size = ” << str.max_size() << endl;
4 cout<< “Empty: ” << (str.empty() ? “yes” : “no”) << endl;
4 }
ACCESSING CHARACTERS IN STRINGS

COMPARING AND SWAPPING


1There is another overloaded version of compare
2intcompare(intstart_1, intlength_1, string s_2, intstart_2, intlength_2)
3string s1, s2;
4intx = s1.compare(0, 2, s2, 2, 2);
5s1.swap(s2)
6Exchanges the content of string s1 and s2

PART-A (2MARKS)

1) DEFINE BASIC TO CLASS TYPE CONVERSION WITH AN EXAMPLE.

2) DEFINE CLASS TO BASIC TYPE CONVERSION WITH AN EXAMPLE.

3) DEFINE ONE CLASS TO ANOTHER CLASS CONVERSION WITH AN EXAMPLE.

4) WHAT IS MEANT BY INHERITANCE?

5) WHAT IS MEANT BY SINGLE INHERITANCE?

6) WHAT IS MULTIPLE INHERITANCES?

7) WHAT IS HIERARCHICAL INHERITANCE?

8) WHAT IS MULTILEVEL INHERITANCE?

9) WHAT IS HYBRID INHERITANCE?

10) WHAT IS MEANT BY ABSTRACT BASE CLASS?

11) WRITE SHORT NOTES ON VIRTUAL BASE CLASS.

12) WHAT ARE FRIEND FUNCTIONS? WRITE THE SYNTAX

13) WRITE SOME PROPERTIES OF FRIEND FUNCTIONS.

13) WHAT ARE THE VIRTUAL FUNCTIONS?

14) WRITE SOME OF THE BASIC RULES FOR VIRTUAL FUNCTIONS

15) WHAT ARE PURE VIRTUAL FUNCTIONS? WRITE THE SYNTAX.

16) WHAT IS AN EXCEPTION?


17) GIVE ANY RULES FOR VIRTUAL FUNCTIONS.

18) WHAT IS VISIBILITY MODE?

19) DEFINE STREAMS.

20) WHAT ARE THE INPUT AND OUTPUT STREAMS?

21) CLASSIFY THE STREAMS.

22) DIFFERENCE BETWEEN GET (), PUT ().

23) HOW TO OPEN AND CLOSE A FILE?

24) WRITE SOME FILE OPENING MODES.

25) WHAT IS A FILE POINTER?

26) WHAT IS COMMAND-LINE ARGUMENT?

27) WHAT IS AN ERROR AND ERROR HANDLING FUNCTIONS?

28) HOW WILL YOU CREATE MANIPULATORS?

29) WRITE THE SYNTAX AND USE OF GETLINE () AND WRITE () FUNCTIONS.

30) GIVE TWO TYPES OF TEMPLATE.

31) DEFINE TRY AND CATCH.

32) DEFINE EXCEPTION HANDLING.

33) DEFINE FILE MODES.

34) GIVE THE GENERAL SYNTAX FOR THROW.

PART-B (16 MARKS)

1) WHAT ARE THE VIRTUAL FUNCTIONS? EXPLAIN THEIR NEEDS USING A SUITABLE EXAMPLE.WHAT ARE THE
RULES ASSOCIATED WITH VIRTUAL FUNCTIONS?

2) WHAT ARE THE DIFFERENT FORMS OF INHERITANCE SUPPORTED IN C++? DISCUSS ON THE VISIBILITY OF

BASE CLASS MEMBERS IN PRIVATELY AND PUBLICLY INHERITED CLASSES.


3) WHAT ARE ABSTRACT CLASSES? GIVE AN EXAMPLE (WITH THE PROGRAM) TO ILLUSTRATE THE USE OF

ABSTRACT CLASSES.

4) (A) EXPLAIN ABOUT CODE REUSE WITH PROGRAM. (8)

(B) DISCUSS ABOUT RUN TIME TYPE IDENTIFICATIONS. (8)

5) WRITE NOTES ON TYPING CONVERSIONS AND DERIVED CLASS WITH PROGRAM.

6) EXPLAIN ABOUT EXCEPTIONS HANDLERS AND STANDARD EXCEPTIONS.

7) EXPLAIN ABOUT TEMPLATE AND ITS TYPES WITH EXAMPLE.

8) DISCUSS ABOUT STREAMS AND STREAM CLASSES

9) WRITE NOTES ON FORMATTED AND UNFORMATTED CONSOLE I/O OPERATIONS.

10) EXPLAIN ABOUT FILE POINTERS AND MANIPULATIONS WITH EXAMPLE.

11) discuss about manipulators and file streams with program.

12) write on details about file modes and file i/o.

13) details for exception handling with program.

---------------------------------------------

You might also like