Page 485 - Computer science 868 Class 12
P. 485
int totrs : To store total rupees
int totps : To store total paisa
Member Methods
AddMoney (.....) : Parameterised constructor to initialise amount of both base class and
derived class
void addamt() : Adds the two amounts
void show() : Displays second amount and the sum amount
Using the concept of inheritance, define AddMoney giving details of the constructor, methods void addamt() and void show(). The
base class and the main method need not be written.
11. A class Student contains marks of a student in five subjects stored in a one dimensional array. Another class BestFour
calculates the total and average marks obtained by the student in best of four subjects. The details of the two classes are
given below.
Class name : Student
Data Members
sroll : stores roll number of the student
sname : stores student’s name
mark[] : double array to store marks in five subjects. Maximum marks in each
subject is 100
Member Functions
Student (....) : parameterised constructor to assign values to data members
void display() : displays the student details
Class name : BestFour
Data Members
tot : to store total marks in best of four subjects
avg : to store average marks in best of four subjects
Member Functions
BestFour(...) : parameterised constructor to assign values to data members of both classes
void calculate() : calculates total and average marks obtained in best of four subjects
void display() : displays the student details, average marks obtained along with grade.
Using the concept of inheritance, specify the class BestFour giving details of the constructor and the member functions void
calculate() and void display(). Base class and main method need not be written.
12. A base class Word is defined to store word in capital letter and print it. Design a derived class ChangeVowel to generate a new
word by changing vowels in the word with next vowel in the character set. So, A will become E, E will change to I, I to O, O to U
and U back to A. The details of both the classes are given below.
Class name : Word
Data Members
str : stores the word
len : stores the length of the word
Member Functions
Word(String s) : Constructor to initialise word
void display() : displays the original word
Class name : ChangeVowel
Data Members
nstr : stores the new word after replacing vowels with the next vowel in the
alphabet
Member Functions
ChangeVowel (String s) : Constructor to initialise both base and derived class data members
void change() : changes the vowels in the word with the next vowel as described above
and stores it in nstr
void display() : displays both the words
Using the concept of inheritance, specify the class ChangeVowel giving details of the constructor and the member functions void
change() and void display(). Base class and main method need not be written.
483
Inheritance, Interfaces and Polymorphism 483

