Page 481 - Computer science 868 Class 12
P. 481
Class name : Grade
Data Members
avg : double type variable to store average marks
grade : character variable to store grade
Member Functions
Grade (....) : parameterised constructor to assign values to data members of both
classes
void calculate() : calculates the average marks obtained as
(marks [0] + marks [1] + marks [2] + marks [3] + marks [4])/5
Grade is calculated on average marks as follows:
Average marks Grade
90 to 100 A
89 to 75 B
74 to 60 C
59 to 40 D
Below 40 E
void display() : displays the student's details, average marks obtained along with grades
Using the concept of inheritance, specify the class Grade giving details of the constructor and the member functions void
calculate() and void display(). Base class and main method need not to be written.
3. A base class Array2D is defined to store numbers in a 3 × 3 matrix. A derived class Transpose is defined to generate the transpose
of matrix a[][]. The transpose of a matrix is obtained by interchanging its rows into columns or columns into rows:
Eg. if matrix a[][] is
1 2 3
4 5 6
7 8 9
then its transpose b[][] will be
1 4 7
2 5 8
3 6 9
Some of the members of the class are given below.
Class name : Array2D
Data Members/Instance variables
a[][] : integer two dimensional matrix
Methods/Member Functions
Array2D(int c[][]) : Initialises matrix a[][]
void print() : Prints matrix a[][]
Class name : Transpose
Data Members/Instance variables
b[][] : integer matrix to store the transpose of a[][]
Methods/Member Functions
Transpose(.....) : Initialises data members of base and derived classes
void generate() : Generates the transpose matrix and stores it in b[][]
void print() : Prints both the original and transpose matrices
Using the concept of inheritance, specify the class Transpose giving details of the constructor and the member functions void
generate() and void print(). Base class and main method need not to be written.
479
Inheritance, Interfaces and Polymorphism 479

