You are on page 1of 6

ELITE POLYTECHNIC INSTITUTE

DEPARTMENT OF COMPUTER SCIENCE AND TECHNOLOGY

SUBJECT CODE: CST/4/S4/LOOP


OBJECT ORIENTED PROGRAMMING LAB
2015

Name: ___________________________________________________
Stream: __________________________________________________
Semester: _________________________________________________
Registration No: ___________________________________________
Roll No: __________________________________________________
INDEX

Sl. No

Lesson

Introduction of C++

Function in C++

Array and Structures in C++

Classes and Objects

Constructors and Destructors

Operator Overloading and Type Conversion

Inheritance: Extending Classes

Pointer, Virtual Function & Polymorphism

Console I/O Operations

10

this pointer

11

File I/O Operations

12

Template

Date

Signature

Remarks

Signature of Subject Teacher

Chapter 1: Introduction of C++


1.1 Write a C++ program to print the following pattern:

****
***

**
*
Source Code
Output:
1.2 Write a C++ program to find the greatest among the three numbers.
Source Code
output:
Q.1 What is Object Oriented Programming (OOP)? Write some of the features of OOP.
Q.2 How does object oriented approach is differ from object based approach?
Q.3 Why do we need the processor directive #include <iostream>?
Q.4 How does the main() function differ in C++ from main() in C?

Signature of Subject Teacher

Chapter 2: Function in C++


2.1 Write a C++ function to swap two integers using call by reference.
Source Code:
Output:
2.2 Write a C++ program to find the multiplication values and the cubic values of two
numbers using inline function.
Source Code:
Output:
2.3 Write a C++ program to find the greatest among three numbers using function that
returns the greatest numbers by reference.
Source Code:
Output:
2.4 Write a C++ program to create a class called COMPLEX that contains two double
data members and implement the following overloading functions ADD, that return
a COMPLEX number.

a. ADD (a, s2) - where a is an integer (real part) and s2 is a complex number.
b. ADD (s1, s2)-where s1 & s2 are complex numbers.1.2 Write a C++ program to
evaluate the following function to 0.0001% accuracy.
Source Code:
Output:
2.5 Create a class COMPLEX that contains two double data members for real and
imaginary part. Write a C++ program to overload unary (-) operator using friend
function.
Source Code:
Output:
Q 2.1 What are the advantages of function prototypes in C++?
Ans:
Q 2.2 What is main advantages of passing arguments by reference?
Ans:
Q 2.3 When will you make a function inline? Why?
Ans:
Q 2.4 When do we need to use default arguments in a function?
Ans:
Q 2.5 What do you meant by overloading a function? When do we use this concept?
Ans:
Q 2.6 What is friend function? Write some characteristics of friend function. What are
the merits and demerits of using friend function?
Ans:
Signature of Subject Teacher

Chapter 3: Array and Structures in C++


3.1 An electricity board charges the following rates to domestic users to discourage
large consumption of energy:
For the first 100 units
: 60P per unit
For next 200 units
: 80P per unit
Beyond 300 units
: 90P per unit
All users are charged a minimum of Rs. 50.00. If the total amount is more than Rs.
300.00 then an additional surcharge of 15% is added. Write a C++ program to read the
number of customers and their names and number of units consumed and print out the
charges with names using array and structure.
Source Code
Output:

Q 3.1 How does structure in C and C++ differ?

Signature of Subject Teacher

Chapter 4: Classes and Objects


4.1 Define a class to represent a vector (a series of float values). Include the member
function to perform the following tasks:
a) To create the vector.
b) To multiply by a given scalar value.
c) To sort the elements of vector.
d) To display the vector in the form ( 10, 20, 30, ).
Write a menu driven program to perform the above task.
Source Code
Output:
4.2 Define a class to represent a bank account that contains name of customer, account
number and balance amount in the account. The class includes the following functions:
1) To assign initial values.
2) To deposit an amount.
3) To withdraw an amount after checking the balance. If minimum balance is less
than Rs. 1000 print You cannot withdraw money due to low balance.
4) To display name and balance.
Write a menu driven main function to perform the above operation.
Source Code
Output:
Q 4.1 What is class? How does it accomplish data hiding?
Ans:
Q 4.2 How does a C++ structure differ from a C++ class?
Ans:
Q 4.3 What are objects? How are they created?
Ans:
Q 4.4 When do we declare a member of a class static?
Ans:
Q 4.5 Write short notes on:
a) Static data members
b) Static member function
c) Memory allocation for objects.
Ans: a) Static data members:
b) Static member function:
c) Memory allocation for objects:
Signature of Subject Teacher

Chapter 5: Constructors and Destructors

5.1 Write a C++ program to invoke Constructor and Destructor.


Source Code
Output
Q 5.1 What is constructor?
Ans:
Q 5.2 How do we invoke a constructor function?
Ans:
Q 5.3 List some of the special properties of constructor?
Ans:
Q 5.4 How dynamic initialization of objects are achieved?
Ans:
Q 5.5 What is dynamic construction of objects?
Ans:
Q 5.6 What is default constructor?
Ans:
Q 5.7 What is parameterized constructor?
Ans:
Q 5.8 What is copy constructor?
Ans:
Q 5.9 What is constructor overloading?
Q 5.10 What is destructor?
Ans: