B & B Institute of Technology Computer Department: Prepared By: L. A. Bhavnani

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

B & B Institute of Technology

Computer Department

Basic Object Oriented Programming(4320702)

Practical-1:
Basic C++ programming using operators, reference variables, scope resolution, memory
management operator and manipulators.

1. Write a program using to read two numbers using Cin and print sum of numbers using
Cout statement.
2. Write a program to show the effects of manipulator setw() ,setfill() and endl.
3. Write a program to demonstrate use of setprecison() manipulator.
4. Write a program to demonstrate use of reference variable.
5. Write program to demonstrate use of scope resolution operator (::) .
6. Write program to demonstrate use of type cast operator.
7. Write a program for dynamic initialization of variables using memory management
operators.
8. Write a program to read and print array. Use new and delete operator to allocate and
deallocate memory of array at runtime.

Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department

Basic Object Oriented Programming(4320702)

Practical 2:
2.1 Functions:
1. Write a program to swap given two numbers.
a. Using call by value
b. Using call by Address(pointer)
c. Using call by reference(reference variable)
2. WAP to print following using default arguments
a. repchar() // prints 45 times asterisks (*)
b. repchar ('=) // prints 45 times (=)
c. repchar('+',30) // prints 30 times (+)
3. Write a function to find simple interest for given interest rate. Use default
arguments for default interest rate of 15 %.
4. Write a function power() to raise a number m to power n. The function takes a
double value for m and int value for n, and returns the value (results) correctly. Use
default argument 2 for n and m to make a function to calculate squares when
argument is not passed. Write a program for the same.
5. Write a function called zerosmaller() uses two arguments. Use return by reference
to the function concept and set a smaller value to 0.
6. Write a program that prints various types of data using function overloading.
7. Write a program to find area of square, rectangle and cube using function
overloading.
8. Write a program to find volume of cylinder, cube and cuboid using function
overloading.
9. Write a program using inline function to add given two numbers.
10.Write a program to demonstrate use of constant arguments.
11.Write a recursive function to find factorial of a given number.

Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department

Basic Object Oriented Programming(4320702)

2.2 Structure

1. Write a program to reads student roll number, student name, student result .
Print student information on screen.
2. Define a structure student which contain no, name, result. Read at least 5 data of
students and print no, name, marks and result. Write a program to arrange above
data in descending order according to result. (Use function for sorting)
3. Define a structure student which contain no, name, marks of three subjects and
average _marks. Write a function
a) To read at least 5 data of students no, name, marks of three subjects & Calculate
average_marks of each student
b) To print only those students having average marks greater than 50.
4. Write a program which defines a structure that can describe a hotel. It should have
members that include the name, address, grade, average room charge and number
of rooms. The program should perform following operation using function
a) To print out hotels of a given grade in order of charges.
b) To print out hotels with room charges less than the given value

Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department

Basic Object Oriented Programming(4320702)

Practical-3
Classes & Objects
1. Create a class player with the following data members
name, age, runs, hi, lo, tsts, avg
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate the average of the player
2. Create a class item with the following data members
item code, cost, qty, total_price
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate the total price of the item
3. Create a class book with the following data members
bookname, authorname, rate, qty
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate the total price of the book
4. Create a time with the following data members
int h, m , s
Write member functions for each of the following
a. To get the data in number of seconds
b. To set the data in number of seconds
c. To display the data
d. To convert seconds into h, m, s
5. Create a student with the following data members
rollno, name, marks[6], per, class
Write member functions for each of the following
a. To get the data
b. To display the data
c. To calculate percentage
d. To calculate class based on percentage
6. Write a program to count number of objects using static member and static
member function.

Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department

Basic Object Oriented Programming(4320702)

7. Create a class time with the following data members


Hour,minute
Write a member function
a. To read time
b. To display time
c. To add time using object as function arguments
8. Write a program to find the greatest of two given numbers in two different
classes using friend function.
9. Write a program to add two complex numbers using friend function.
10. Write a program to find the sum of two numbers declared in a class and display
the numbers and sum using friend class.

Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department

Basic Object Oriented Programming(4320702)

Practical-4
Constructor and Destructor

1. Write a program to demonstrate use of default constructor.


2. Write a program to demonstrate parameterized constructor.
3. Write a program to demonstrate constructor overloading.
4. Write a program to demonstrate default argument constructor.
5. Write a program to demonstrate use of copy constructor.
6. Write a program to demonstrate use of dynamic constructor.
7. Write a program to demonstrate calling of constructor and destructor.
8. Create a class for shape rectangle. Calculate area of 3 different rectangles. Use
constructors to construct objects.
9. Create a class for shape triangle. Calculate perimeter and area of triangle. Use
constructors to construct objects.

Extra Work : Perform Programs of Practical 3 (1 to 5) using constructor and destructor


at appropriate place.Do not need to write in file.

Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department

Basic Object Oriented Programming(4320702)

Practical-5
Inheritance
1. Assume that Circle is defined using radius and Cylinder is defined using radius and
height. Write a Circle class as base class and inherit the Cylinder class from it.
Develop classes such that user can compute the area of Circle objects and volume
of Cylinder objects. Area of Circle is pie *radius*radius, while volume of Cylinder
is pie*(radius * radius)*height.
2. Consider a class network as shown in figure given below. The class Employee
derives information from both Account and Admin classes which in turn derive
information from the class Person. Define all the four classes and write a program
to create, update and display the information contained in Employee objects.

3. Define class employee which has fname and lname as data member. Define
following:
1. Constructor for employee class with default arguments
2. Print function
Derive a class called hourly_worker (with wage and hours as data members).
Define following:

Prepared By : L. A. Bhavnani
B & B Institute of Technology
Computer Department

Basic Object Oriented Programming(4320702)

1. Constructor for hourly_worker class with default arguments


2. Getpay() function that calculates and returns the pay and
3. A print function
4. Create a class Shape as base having member height and width. Create derived
class Rectangle. Write appropriate member functions in class to read height and
width and find area of rectangle.
5. Write a program to find area and perimeter of rectangle using multiple
inheritance as shown in figure below.

6. Write a program using hierarchical inheritance.


Rectangle and Triangle are derived from Shape class. Use appropriate constructor
and member functions.
7. Write program to prepare mark-sheet for diploma engineering students, create
class student as base class and TW and EXT as derived class from it, result
class is derived from these two classes TW and EXT.
8. Create three different classes with name A, B & C respectively. All classes have
two integer variables as their private data members. Class B is child class of class
A and class C is a child class of class B. Create an object of class C and find the
average of values of all its data members.
9. Create a class Publication that stores the title (a string) and price (type float) of a
publication. Derive a class Book which adds a page count (int), from the above
Publication class. Class should have get_data () function to get its data from the
user at the keyboard and put_data() to display the record. Write a program that
takes record of 50 books and display it.

Prepared By : L. A. Bhavnani

You might also like