Posted in All Posts, Semester 3

Sem 3 – OOCP Unit 3 Programs

OOCP – Object Oriented Concepts & Programming

Unit 3 – Virtual Functions, Operator Overloading

1. Create a class vehicle which stores the vehicleno and chassisno as a member. Define another class for scooter, which inherits the data members of the class vehicle and has a data member for a storing wheels and company. Define another class for which inherits the data member of the class vehicle and has a data member for storing price and company. Display the data from derived class. Use virtual function.
Download | View Code

2. Create a base class 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 get_data() to initialize the base class data members and another member function display_area() to compute and display the area of figures. Make display_area() as a virtual function and redefine this function in the derived class to suit their requirements.
Download | View Code

3. Write a program to demonstrate the use of pure virtual function.
Download | View Code

4. For multiple inheritance, write a program to show the invocation of constructor and destructor.
Download | View Code

5. Create a class string with character array as a data member and write a program to add two strings with use of operator overloading concept.
Download | View Code

6. Create a class distance which contains feet and inch as a data member.
Overhead = =, > and < operator for the same class. Create necessary functions and constructors too. Download | View Code

7. Create a class MARIX of size mxn. Overload + and – operators for addition and subtraction of the MATRIX.
[Will be available soon]

8. Define a class Coord, which has x and y coordinates as its data members. Overload ++ and –- operators for the Coord class. Create both its prefix and postfix forms.
Download | View Code

9. Create one class called Rupees, which has one member data to store amount in rupee and create another class called Paise which has member data to store amount in paise. Write a program to convert one amount to another amount with use of type conversion.
Download | View Code

10. Create two classes Celsius and Fahrenheit to store temperature in terms of Celsius and Fahrenheit respectively. Include necessary functions to read and display the values. Define conversion mechanism to convert Celsius object to Fahrenheit object and vice versa. Show both types of conversions in main function.
Download | View Code

Download All

I hope that you found this article to be helpful.
Please share your thoughts in the Comments Section.

If you liked this article, then please like our Facebook page.

Suggested Reading

Comment your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.