0% found this document useful (0 votes)
2 views2 pages

Inheritance Problems

The document outlines various C++ programming tasks involving inheritance and virtual functions. It includes creating classes for geometric shapes like Circle, Cone, Cylinder, and others, as well as classes for educational contexts like Student, Exam, and Result. Each task emphasizes the use of derived classes to extend functionality and utilize base class members effectively.

Uploaded by

merlyne.noel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Inheritance Problems

The document outlines various C++ programming tasks involving inheritance and virtual functions. It includes creating classes for geometric shapes like Circle, Cone, Cylinder, and others, as well as classes for educational contexts like Student, Exam, and Result. Each task emphasizes the use of derived classes to extend functionality and utilize base class members effectively.

Uploaded by

merlyne.noel
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

INHERITANCE AND VIRTUAL FUNCTIONS

1. Create a class called Circle with radius as data member and getCircle() and calcArea() as
member functions to read the radius and calculate area of the circle. Create another class called
Cone which is derived from the Circle class. Utilize the data members and the member functions
of the base class by the derived class to find the volume ((1/3)*3.14*r*r*h) of a cone.

2. Create a class Book with necessary data members and member functions. Derive a class
Textbook from the Book class and include the necessary data members and member functions to
get and print the information with the help of base class members.

3. Create a class called Circle with radius as data member and getCircle() and calcArea() as
member functions to read the radius and calculate area of the circle. Create another class called
Cylinder which is derived from the Circle class. Utilize the data members and the member
functions of the base class by the derived class to find the volume (3.14*r*r*h) of a cylinder.

4. Write a C++ program with a class named as “area” to find the area of the room and inherit this
property into another class named as “volume” to find out the volume of the same room and
display both the results.

5. Write a C++ program with two classes named as “add”, “sub” to perform addition and
subtraction of two given numbers and inherit these values to another class named as “remainder”
to find the remainder of these values.

6. Write a C++ program to add and subtract the given two numbers in two separate classes
and multiply and divide the added and subtracted values in the third class

7. Write a C++ program with two classes named as “one”, “two” to find the area of square and
rectangle respectively, and inherit these values to another class named as “cuboid” with its own
property “height” to find the area of the cuboid.

8. Consider an example of declaring the examination result. Design three classes: Student, Exam
and Result. The student class has data members such as roll number, name, etc. Create the class
Exam by inheriting the Student class. The Exam class adds data members to representing the
marks scored in six subjects. Derive the Result class from the Exam class and it has its own data
members such as total_marks. Write an interactive program to model this relationship.

9. Define a class vehicle. Inherit vehicle into two wheelers and four wheelers. Inherit two wheelers
into bicycles and scooters. Inherit four wheelers into diesel vehicle and petrol vehicles. Provide a
virtual function that calculates the mileage of the vehicle. (Mileage=distance travelled in
Km/Fuel consumed).

10. Write a C++ program to find the area of circle using necessary classes with constructor and two
functions named as “putdata()” and “show()” in all the classes and use virtual keyword for any
one of these function and display the result.

11. Create a class student. Inherit that into engineering, arts, commerce and science
[Link] science student into UG and PG and further subdivided into computer
science,electronics and communication and mechanical. Provide methods for enrolment,
examination result processing and granting degree to the students

You might also like