INHERITANCE
1. Imagine a publishing company that markets both books and audio-cassette versions of its works. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class, derive two class: book, which adds a page count (type int) and tape, which adds a playing time in minutes (type float). Each of these three classes should have a getdata() function to get its data from the user at the keyboard, and a putdata() function to display its data. Write a main() program to test the book and tape classes by creating instances of them, asking the user to fill in their data with getdata(), and then displaying the data with putdata().
2. (i) Define a class STUDENT with the following specifications:-
Private Members: Name of type string , RollNo of type unsigned int Protected Members: Class of type unsigned int Public Members: Constructor to assign initial values of Name with “Not Assigned”, RollNo & Class with 0.
A function Input() to input the values all data members
A function Display() to Display the contents of all data members.
(ii) Define another class TEST which is publicly derived from class STUDENT with the following specifications:-
Private Members: English , Maths, Physics , Chemistry , ComputerScience of type float A function Calculate_Total() to calculate TotalMarks
Protected Members: TotalMarks of type float Public Members: Constructor to assign initial values of all data members with 0. A function getData() to input the values all data members & call Calculate_Total() A function displayData() to display the contents of all data members.
(iii) Define one more class RESULT which is publicly derived from class TEST with the following specifications:-
Private Members: Percentage of type float , Grade of type string
Public Members: Constructor to assign initial values of percentage with 0 and grade with ‘E’ A function calcPercentage() & A function calcGrade() according to the following criteria:
%age of Marks Grade
>= 90 A
>= 75 and <90 B
>= 60 and <75 C
>= 40 and <60 D
< 40 E
A function displayResult() to display the values of percentage and grade. Now, write the main function to :
Create an object of class RESULT : To obtain all the values required to display the result of a student. Display the result with all the details
Please click on below link to download CBSE Class 12 Computer Science Inheritance Worksheet Set B