You are on page 1of 5

CIVIL 2nd Sem

COMP 116
Object Oriented Programming

Assignment Set #0
1. What is Structured Programming? How does Object Oriented Programming differ from it?
2. What is namespace and what is its use?

Assignment Set #1
1. List the features of OOP. Explain each in detail.
2. What is the difference between structure and class? What are the advantages of using
class over structure?
3. What do the keywords public, protected and private mean? What is their significance?
4. Define inline function with an example. What is the advantage of using inline functions?
5. Define function overloading with an example. In what kind of scenario would you
overload a function?

Assignment Set #2
1. Differentiate between constructor and destructor. Describe the different types of
constructors with suitable examples.
2. What is friend function? Illustrate its use in overloading binary operators.
3. What is overriding function? How does it differ from function overloading?
4. What sort of ambiguity can be resolved by defining virtual base classes?
5. What are static types? What are its uses? Illustrate using code.

Assignment Set #3
1. What is Inheritance? Why is it important? Briefly describe the different types of
Inheritance with suitable examples?
2. What do you mean by Polymorphism? Illustrate with an example how pure virtual
function can be implemented.
3. What is Composition? How does it differ from Inheritance? Illustrate with an example.
4. What do you mean by Function Template and Class Template? Illustrate with examples.
5. Why do you need to handle exception? What is the mechanism in C++ to handle it?

Assignment Set #4
Assignment 4 will be declared in class.

[Deadlines for submission of all assignments and labs will be declared in the class. Late
submission will not be entertained. Students are expected to compile all assignments and lab
sheets into a file and bring it during their practical finals and viva.]
Lab Work #0
1. WAP to take 2 numbers input from the user and display its product.
2. Write a function to add 2 numbers.
3. Write an array with capacity with 7 and display the largest number.
4. WAP to read a string and display it.

Lab Work #1
1. WAP which contain a class “Car” with attributes: name, gear, speed. It should have the
functions to gear_up, gear_down, show_gear and show_speed. Attributes should be of
data type int and string only. Write a driven program as well.

2. Define a class called "Rectangle" with following attributes: length and breadth of data
type integer. Also include the following member functions:
void setSize(int length, int breadth); // this function should set the value of length
and breadth of the Rectangle.
int getArea( ); // this function should return the area of the rectangle.
int getPerimeter( ); // this function should return the perimeter of the rectangle.
// formula to calculate: area = length * breadth.
// formula to calculate: perimeter = 2 * (length + breadth).
Write a driven program as well.

Lab Work #2
class Complex
Private:
int x;
int y;
public:
Complex( );
Complex( int x, int y);

1. Define a class called Complex.


2. Define member functions that overload the following operators:
 Minus unary operator. Returns void
 Scalar multiplication. (you may use friend function) and returns Complex
 Plus binary operator (+). => Returns Complex
 Minus binary operator. => Returns Complex
 += Shorthand operator. => Returns void
 == Equals to operator. => Returns TRUE or FALSE
 Greater than operator. => Returns TRUE or FALSE
 ! = Not equals to operator. => Returns TRUE or FALSE
 Pre Increment operator. => Returns Complex
 Post Increment operator. => Returns Complex
Write a main( ) function to implement the above overloaded operators.
Lab Work #3
Create a base class called Shape. Use this class to store two double type values that could be
used to compute the area of figures, Derive two specific classes called Triangle and Rectangle
from the base Shape. Add to the base class, a member function set_data() to initialize base class
data members and another member function display_data() to compute and display the area of
figures. Make display_area() as a virtual function and redefine this function in the derived classes
to suit their requirements. Using these three classes, design a program that will accept
dimensions of a triangle or a rectangle interactively, and display the area.

Class Shape
public side_one :double
public side_two :double
public Shape() :Constructor
public Shape(double, double) :Constructor
public set_data(double, double) :void
public virtual display_area() :void

Class Triangle : Shape


public display_area() :void

Class Rectangle : Shape


public display_area() :void
Lab Work #4
class Shape
protected:
int x;
int y;
public:
Shape( ){ }
Shape( int, int );
virtual void draw ( ) = 0;

Class Circle : public Shape


protected:
int radius;
public:
Circle( ){ }
Circle( int, int, int);
void draw( );

Class Ellipse : public Shape


Protected:
int xradius;
int yradius;
public:
Ellipse( ) { }
Ellipse( int, int, int, int );
void draw( );

class Rectangle : public Shape


protected:
int x1;
int y1;
public:
Rectangle( ) { }
Rectangle(int, int, int, int);
void draw( );

Define the above classes and save the file as shape.h


Write a C++ program that displays the following menu.
1. Circle
2. Ellipse
3. Rectangle
4. Exit
Enter Your Option:
After entering the option, user then enters the position and size of corresponding shape. Now,
your program should dynamically (use pointer) allocate the memory and draw that shape. (Use
graphics if possible.)
Lab Work #5
1. Write a function template sort( array[ ] ) that sorts the given list of numbers. Write a
program that inputs, sorts and outputs an int array and a float array.
// algorithm for sorting
for(m=0; m<size-1; m++)
{
for(n=m+1; n<size; n++)
{
if(array[m]>array[n]) // for ascending order
{
T temp;
temp = array[m];
array[m] = array[n];
array[n] = temp;
}
}
}

2. Write a program that illustrate the concept of Exception Handling in C++.

SYLLABUS: http://ku.edu.np/cse/LEVEL100/comp%20116.pdf

TEXT BOOKS:
1. John R. Hubbard, Theory and Problems of Programming with C++, 2/e, McGraw-Hill.
2. H. M. Deitel, “C++ How to Program”, D and D.
3. Friedman and Koffman, “Problem Solving, Abstraction and Design using C++ , 5/e,
Addison-Wesley.
4. E. Balagurusamy, “Object Oriented Programming in C++, 6/e” Tata McGraw-Hill
Education

ONLINE REFERENCES
1. http://www.cplusplus.com/doc/tutorial/
2. http://www.tutorialspoint.com/cplusplus/index.htm
3. https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83

You might also like