OOCP Practical List 2017

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Practical List- 2016

Subject Name: Object Oriented Programming With C++


Subject Code: IT0302
Branch & Semester: III IT
Sr.
No.
Topic
Concepts of OOP
1. Write a program to display LJIET using cout statement.
2. Program which get a integer number and display "WELL DONE" that many times
1 3. Program to find even and odd numbers between 100 and 200
4. Program to add the digits of given integer number.
5. Program that convert the temperature from Fahrenheit to Celsius.(F-32)5/9
C++ Basics
1. Program for Use of Scope Resolution Operator (::).
2. Write a program to evaluate the following investment equation V = P(1+r)n
3. An electricity board charges the following rates to domestic users to domestic users to discharge
large consumption of energy.
For the first 100 units 60 P per unit
2 For next 200 units - 80P per unit
Beyond 300 units - 90 P per Unit
All users are charged a minimum of Rs.50.00. If the total amount is more
ThanRs. 300.00 then an additional surcharge of 15% is added. Write a
program to read the names of users and number of units consumed and
printout the charges with names.
4. Program for Analysis of mark sheet using else if ladder.
C++ Functions
1. Program to find factorial of a given number
2. Write a program in C++ to generate Fibonacci Series by using recursion.
3. Write a program using a function with arguments to swap the values of a pair of integers using
call by reference.
4. Explain Call by reference and Return by Reference with suitable example.
5. Write a function power () to raise a number m to a power n. The function takes a double value for
3 m and int value for n, and returns the result correctly. Use a default value of 2for n to make the
function to calculate the square when this argument is omitted. Write a main that gets the value of
m and n from the user to test the function.
6. What is inline function? Where and How it is useful in C++? Give an example.
7. Declare a class called book having members like book_title, publisher and author_name.
Overload extractor and inserter operators (>> and <<) for class book.
8. Explain function overloading with an example.
9. Explain friend function with suitable example.
Objects and Classes
1. Define a class to represent a string with operations string length, compare and reverse. Show its
use by writing main()
4 2. Write a program that demonstrates the Static DataMember And static member function.
3. Write a class called arithmetic having two integer and one character data members. It performs
the operation on its integer members indicated by character member (+, -, *, /). For example *
indicates multiplication on data members as d1 * d2. Write a class with all necessary constructors

1
and methods to perform the operation and print the operation performed in format Ans = d1 op d2.
Test your class using main().
4. Define Class named point which represents 2-D Point, i.e P(x, y). Define Default Constructor to
initialize both data member value 5, Parameterized constructor to initialize member according to
value supplied by user and Copy Constructor.Define Necessary Function and Write a program to
test class Point.
5. Create a class Account. It has three data member account id, name and balance. Define function to
assign value and display value. Define function that search account number given by the user. If
account number exists, print detail of that account. Write a program using array of object. Declare
at least 5 account and print details.
6. Write a single C++ program to explain the concept of both constructor and destructor.
7. Write a program which include class to represent a vector(a serious of float values). Include
member functions to perform the following tasks:
a> To create the vector
b> To modify the value of given elements
c> To Display the given vector in the form(10,20,30)
8. Declare a class called book_details to represent details for a book, having data members like title,
author, edition, price and no_of_copies_available. Define following functions:
- constructor(s)
- display to display all data members
- find_books to find and display details of all books having price less than Rs. 250
- main to create an array of book_details and to show usage of above functions
9. Define a class Time with hours and minutes as two data members, add necessary member functions
to initialize and display data of class. Do not use constructors in a class. Define a member function
sum() which adds two Time objects. Invoke the statements like T3.sum(T1, T2) in main ().
10. Write a C++ program to explain Objects as function arguments. Define a class name VALUE with
two data member variable, two member functions for inputting data and displaying the result.
Define third member function that takes two objects as arguments and adds the objects.
11. What is friend function? Write a program to find out sum of two private data members x and y of
two classes A and B using a common friend function. Assume that the prototype for both the classes
will be void sum (A, B);
12. Define a class complex, having data member as X and Y, Define a friend function sum () to add
two complex numbers and display all numbers using show () friend function Program for
Maximum number using Friend function for two classes.
13. Create two classes DM and DB which store the value of distances. DM stores distances in meters
and centimetres and DB in feet and inches. Write a program that can read values for the class
objects and add one object of DM with another object of DB. Use a friend function to carry out the
addition operation. The object stores the results may a DM object or DB object, depending on the
units in which the results are required. The display should be in the format of feet and inches or
meters and centimeters depending on the object on display.
1Feet = 0.3048Meter 1Meter = 3.28 Feet
1Inch = 2.54 Centimeter 1 Centimeter = 0.3937 Inch(June 2013) [LJIET]
14. Explain Friend function and its characteristics. Define a class matrix
with an integer array of 3X3 as a data member. Define a friend function which adds two matrix
objects and returns resultant matrix object.
15. Create a class student that stores roll_no, name. Create a class test that stores marks obtained in
five subjects. Class result derived from student and test contains the total marks and percentage
obtained in test. Input and display information of a student.

2
16. Write a program in C++ to find the sum of two entered complex numbers from different classes
and display the sum using a common friend function of both classes.
17. Create class Time that has three data members hour, minute and second and two constructors, default
constructor and parameterized constructor to initialize data member. Write a program to add two times
by overloading operator +
18. Define a class complex with real and imaginary as two data member, add necessaryconstructors
and member function to initialize and display data of class. Class should overload the + operator to
add two complex objects and return the results. Invoke the statements like C3=C1+C2 in main ().
19. Write a C++ program to overload the + operator to concatenate two strings.
20. Define a circle class with radius as data member, necessary constructors and member function to
compute area of circle. Class should overload the = = operator to compare two circle objects
whether they are equal in radius. Demonstrate its use in main ().
21. Declare a class called bird having two private data members called name and weight. Define
following functions:
- default constructor for reading data members from key board
- Overloaded constructor with two arguments to be used for initialization of data members.
- display function to display data members.
- overloaded member operator >= to compare weight of two bird objects, returning false if weight
of first bird object is less than that of second & true otherwise.
Define function main to illustrate use of above functions.
22. Declare a class called book having members like book_title, publisher and author_name. Overload
operators << and >> for class book. Define function main.
23. Program to overload a single unary Operator.
24. Define a class complex with real and imaginary as two data member with default & parameterized
constructors, function to initialize display data of class. It should overload the + operator to add
two complex objects. Write a program to demonstrate use of complex class.
Inheritance
1. Program to implement Single Inheritance
2. Program to Implement Hybrid Inheritance...
3. Student class have two derived class named as Test, Sports and both Test, Sports has a derived
class named as Result which display all the details.
4. 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 radius*radius, while volume of cylinder is pie*(radius)2*height.
5. Assume that vehicle class is defined as base class with price and year of manufacturing. Derive
two classes namely bus and truck from base class with bus with seating capacity and truck with
5 loading capacity. Develop classes with necessary member functions to get and put data.
Demonstrate its use in main ().
6. 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 input and display the information of an Employee.

3
7. Create a class student that stores roll_no,name. Create a class test that stores marks obtained in five
subjects. Class result derived from student and test contains the total marks and percentage obtained
in test. Input and display information of a student.
8. Consider the following class structure as shown in the figure. The class Result derives information
from the classes Internal, University and External respectively. The Internal and External
classes access information from the Student class. Define all five classes and write a suitable
program to create and display the information contained in Result object.

9. Declare a class called item having data members item_code, item_name, cost and discount.
Derive two classes from class item, namely employee and customer. The class employee has data
members like employee_id and amount. The class customer has data members like
customer_name and amount. Define following functions
- to initialize data members.
- to display the values of members.
- to compute amount to be paid for purchased item.
- main to create objects of both derived classes and to show usage of above functions.
Polymorphism
1. Write a C++ program demonstrating use of the pure virtual function with the use of base and
derived classes.
2. Program to create a class THREE-D contains data members like X, Y, Z having dimensions.
Include constructor to initialize data. and overload Unary +, -, ++, -- and Binary * Operator
3. Declare a class called logic_gate to represent logic gates. The class has three data members - input1,
input2 and input3 to represent three inputs to the logic gate. The class also has a virtual function
member called get_gate_output. Derive two classes from the base class logic_gate, namely,
and_gate and or_gate to represent logical and gate and logical or gate respectively. Define
function get_gate_output in both of these classes to get the output of the gate. Show use of above
classes and functions to demonstrate dynamic polymorphism in function main.
6
4. Write a complete program to illustrate the use of this pointer
5. Declare a class called my_string having char * str_ptr as a member, used to point to a string. Define
a constructor for initializing member. Define an overloaded operator + to be applied on two
operands of type class my_string for concatenating strings pointed by str_ptr of operands. The
resultant string is placed in a new object of type class my_string which is returned. Define main to
show the usage of these functions
6. Write a C++ program that creates inventory of items by storing item_code, item name and qty.
Access the data using pointers.
7. Create a class ITEM with item_code, item_rate and quantity as a data member. Create an array of
pointers to objects of class ITEM. Write a member function which will calculate the amount of
item. Print item_code and amount of item.

4
I/O and File Management
1. Write a program that reads a text file and creates another file that is identical except that every
character is in upper case.
2. Write a program that reads a text file and creates another text file that is identical except that every
letter must be converted to lower case irrespective of its original case (e.g. a or A will become
a).
7
3. Explain various file mode parameters in C++. Write a program to copy the contents of a source file
student1.txt to a destination file student2.txt character by character.
4. Write a program that opens two text files for reading data. It creates a third file that contains the
text of first file and then that of second file (text of second file to be appended after text of the first
file, to produce the third file).
5. Write a program to show use of manipulators.
Templates, Exceptions
1. What is Generic Programming? How it is implemented in C++.Write General format of class
templates and function Template. Write program to swap Number using Function Template.
Function prototype is given below:
void swap(int, int , float , float )
Swap two integer numbers and swap two float number.
2. What is Exception? Explain Exception Handling Mechanism. Write a program that demonstrates
use of multiple catch. Add at least three catch blocks in your Program.
3. Declare a template class called exam having an array of generic type as a data member, named
elements [10]. Define following generic (template) member functions:
- sort to arrange elements in ascending order
- find_max to find and return maximum from the array
Define main to illustrate usage of these functions to process two different types of data.
4. It is required to find roots of quadratic equation ax2 + bx + c = 0. Write a program that reads values
of a, b & c and finds roots if roots are real; otherwise raises and handles exception (if roots are
complex).
8
5. Create a generic class (using template), called my_class having following data members:
- an array to store numbers
- an array of flags to indicate whether the location is occupied or free
Define following member functions:
- to insert a number at specified location
- to remove a number from specified location, if the specified location is occupied
- to search a number in the array.
Define function main to create two objects of type class my_class to store int& float numbers
respectively. Also show usage of member functions in the main.
6. Explain the mechanism of keywords try, throw and catch to handle Exceptions in C++.Explain with
an example like division by zero situation.
7. Declare a template class called exam having an array of generic type as a data member, named
elements[10]. Define following generic (template) member functions:
- sort to arrange elements in ascending order
- find_max to find and return maximum from the array
8.Write a C++ program that throws an arithmetic exception whenever the result of arithmetic
computation becomes odd.

You might also like