Page 482 - Computer science 868 Class 12
P. 482

4.  A base class Array2D is defined to store numbers in a 3 × 3 matrix. A derived class Upper is defined to generate the upper triangle
                    matrix from matrix a[][]. A square matrix whose all elements below the principle diagonal is 0 is called upper triangle matrix.
                    Eg. if matrix a[][] is

                                                            1     2     3
                                                            4     5     6
                                                            7     8     9
                     then its Upper triangle matrix will be
                                                            1     2     3
                                                             0     5    6
                                                             0    0     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                            :   Upper
                     Data Members/Instance variables
                     b[][]                                 :   integer matrix to store the upper triangle matrix of a[][]
                     Methods/Member Functions
                     Upper(.....)                          :   Initialises data members of base and derived classes
                     void generate()                       :   Generates the upper triangle matrix and stores it in b[][]
                     void print()                          :   Prints both the original and upper triangle matrices
                     Using  the concept of  inheritance,  specify  the  class  Upper  giving  details  of  the  constructor  and  the  member  functions void
                    generate() and void print(). Base class and main method need not to be written.
                  5.  A base class Word is defined to store word and print it. Design a derived class ChangeCase to generate a new word by changing
                    the case of the original word. The details of both 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                            :   ChangeCase
                     Data Members
                     nstr                                  :   stores the changed word
                     Member Functions
                     ChangeCase (String s)                 :   constructor to initialise both base and derived class data members
                     void change()                         :   changes case of each character in word str and stores it in nstr
                     void display()                        :   displays both the words
                     Using the concept of inheritance, specify the class ChangeCase giving details of the constructor and the member functions void
                    change() and void display(). Base class and main method need not to be written.
                                                                                                  2
                  6.  A base class Quadratic is defined to enter the numerical coefficients a, b, c of a quadratic equation ax  + bx + c and calculate the
                                   2
                    discriminant d as b  - 4ac. The details of the class is given below.
                     Class name                            :   Quadratic
                     Data Members
                     double a, b, c, d                     :   To store the coefficients and discriminant
                     Quadratic(double aa, double bb, double cc)  :   Constructor to initialize the coefficients
                                                                                                          2
                     void calculate                        :   Calculates discriminant of the quadratic equation ‘d’ as b  - 4ac
                480480  Touchpad Computer Science-XII
   477   478   479   480   481   482   483   484   485   486   487