Vous êtes sur la page 1sur 3

The server where corresponding programs have been put is 10.203.161.

7 under ~/CPP/
directory.

Session 1 - 2:
1> Write a library class having public, private and protected 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.
passByRef/passByRef_prevnext.cpp
2> Write a program to sort two numbers using call by reference. Smallest number
should be output first.
passByRef/sortAlgo.cpp

CONSTRUCTOR & DESTRUCTOR - DYNAMIC MEMORY COPY


CONSTRUCTOR
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 of 10.

constDest/boxClass.cpp
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.


constDest/consDestNewDel.cpp
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.


constDest/moreThanOneConst.cpp

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.
inheritance/inheritProtectedCalcArea.cpp
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.
inheritance/inheritBaseMemInit.cpp

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.
inheritance/multiInherit.cpp
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 classs Create function.
Inheritance/virtualGeneral.cpp
5> Write a friend function for a class A to access its private data and compute addition on its
private data. Similarly, write a friend class for this class A which accesses its private data
and computes some subtraction on its data.
Inheritance/friendFunction.cpp , friendClass.cpp

4>

Vous aimerez peut-être aussi