The server where corresponding programs have been put is 10.203.161.7 under ~/CPP/
Session 1 - 2:
1> Write a library class having public and private data members and functions. The
class should allow basic operations like entering book details, displaying book
details. Instantiate objects of this library class and perform operations on them.
2> Write a Intgr class to imitate the behavior of an int object. Define add, subtract and
multiply class members for this class. Instantiate objects of this class and perform
addition, subtraction and multiplication operations on them.
3> Implement a resource allocator using the concept of static data member and static
member function. A Resource class should have a static data member to keep track
of resource allocation (Boolean variable). Instances of this class will be allocated
resource only if no other instance is holding the resource.
Session 3 - 4:
MEMORY OPERATIONS USING NEW DELETE
1> Write a program to copy data from one int array to another. Use the concept of new
and delete to allocate and deallocate memory for the arrays.
PASS BY REFERENCE
1> Passing by reference is also an effective way to allow a function to return more than
one value. Write a program that returns the previous and next numbers of the first
parameter passed using the concept of pass by reference.
2> Write a program to sort two numbers using call by reference. Smallest number
should be output first.
CONSTRUCTOR & DESTRUCTOR - DYNAMIC MEMORY – COPY
1> Write a box class with class members length, breadth, height and a function to
calculate the volume of the box. Constructor should be passed arguments for length,
breadth, height. Also define a second constructor which takes default height value
2> Write a class with a “int *” member function whose constructor takes a int
argument and allocates memory using “new” and destructor frees that memory.
Note : Copy constructor should also be defined for this class.
3> Write a class with a simple integer as class member and a member function that
returns that value. There should be two overloaded constructors one which takes an
integer as argument and the other taking a “char *” as argument.
Note : Can use atoi function to convert “char *” to int.
Session 5 - 6 - 7:
1> Write a base class with protected class members length and breadth. Derived class
should have a function to calculate the area using length and breadth of base class.
2> Write a base and derived class with simple integer class members. Implement
concept of base class constructor initialisation in the derived class constructor. Both
the classes should have member function to display their class member values. This
method should be protected in the base class and invoked from the base class.
3> Implement multiple and multi-level inheritance. Derived class derived should have
protected and private inheritance from base classes base1 and base2, where base1
and base2 have protected data members. Derived class derivedL2 should in turn
publicly inherit from class derived. Try and access protected data members of
base1 and base2 classes in derivedL2. Write destructor functions to see the
sequence of destructor calls.
4> Implement concept of virtual function using base class named Window and derived class
named CommandButton. Base class will have a virtual member function named Create
which should be over ridden in derived class. In the main function, declare two base class
pointers, one should invoke the base class Create function and the other should invoke
derived class’s Create function.
5> Write a friend function for a class A to access it’s private data and compute addition on it’s
private data. Similarly, write a friend class for this class A which accesses it’s private data
and computes some subtraction on it’s data.
Inheritance/friendFunction.cpp , friendClass.cpp
Session 8 -9 - 10:
1> Write an overloaded volume function to calculate the volume of a cube
(side*side*side), a cuboid (l*b*h) and a circle.
2> Overload the ‘+’ operator to add two user defined objects.
3> Define a person class with class members as name and age. Define a member
function “greater” which takes one parameter (object of class person) as function
argument. The function should compare the ages of two persons and return the
object whose age is greater. Achieve the above using “this” pointer.
4> Define a class shape with 2 data members to store length and height. Define
member functions get_data() and display_area(). Display_area() should be virtual
function. Define 2 derived classes from shape, triangle and rectangle which
redefine display_area() for their own specific area calculation.
5> Extend the above program to calculate are of a circle by introducing a new derived
class called circle. The get_data() function in the shape class can be modified by
taking default value for the second parameter.