Page 483 - Computer science 868 Class 12
P. 483

void display()                        :  Prints coefficients a, b and c and discriminant d
                        A derived class Roots is defined to calculate the roots of the quadratic equation (if possible) with appropriate message. The details
                       of the class is as follows:
                        Class name                            :  Roots
                        Data Members
                        double r1, r2                         :  To store the roots
                        Member Methods
                        Roots(……)                             :   Parameterised constructor to initialise variables of base and derived classes
                        void calculate()                      :  Calculates the roots r1 and r2 of the equation using formula

                                                                     b
                                                                    −± b  2  − ac
                                                                            4
                                                                 x =
                                                                         2 a
                                                                 along with appropriate message as given below:
                                                                 d < 0             Roots are imaginary
                                                                 d = 0             Roots are real and equal
                                                                 d > 0             Roots are real and unequal
                        void display()                        :   Displays the roots r1 and r2 and the base class data
                        Using the concept of inheritance, specify the class Roots details of the constructor and the member functions void calculate() and
                       void display(). Base class and main method need not to be written.
                    7.  A superclass Detail has been defined to store the details of a customer. Define a subclass Bill to compute the monthly telephone
                       charge of the customer as per the chart given below.                                      [ISC 2012]
                        Number of calls : Rate
                        1 – 100     Only rental charge
                        101 – 200   60 paise per call + rental charge
                        201 – 300   80 paise per call + rental charge
                        Above 300   1 rupee per call + rental charge
                        The details of both the classes are given below.
                        Class name                            :   Detail
                        Data Members/instance variables
                        name                                  :   to store the name of the customer
                        address                               :   to store the address of the customer
                        telno                                 :   to store the phone number of the customer
                        rent                                  :   to store the monthly rental charge
                        Member Functions
                        Detail (…)                            :   parameterised constructor to assign values to data members
                        void show ()                          :   to display the details of the customer
                        Class name                            :  Bill
                        Data Members/Instance variables
                        amt                                   :   to store the amount to be paid by the customer
                        Member Functions
                        Bill (…)                              :     parameterised constructor to assign  values to data members of both
                                                                 classes and to initialise amt = 0.0
                        void cal()                            :   to calculate the monthly telephone charge as per the chart given above
                        void show()                           :   to display the details of the customer and amount to be paid
                        Using the concept of inheritance, specify the class Bill giving details of the constructor(), void cal() and void show(). You need not
                       write base class and main method.
                    8.  A super class Worker has been defined to store the details of a worker. Define a subclass Wages to compute the monthly wages
                       for the worker. The details/specifications of both the classes are given below.
                        Class name                            :   Worker
                        Data Members/instance variables
                        name                                  :   to store the name of the worker
                        basic                                 :  to  store the basic pay in decimals
                        Member Functions
                        Worker (…)                            :   parameterised constructor to assign values to the instance variables


                                                                                                                       481
                                                                                  Inheritance, Interfaces and Polymorphism  481
   478   479   480   481   482   483   484   485   486   487   488