Page 605 - Computer science 868 Class 12
P. 605

PROGRAMS ON INHERITANCE


                   Program 16    Simple Interest and Compound Interest using Inheritance
                                 A base class called account is defined as follows:
                                 Data Members
                                 intacc_no                    :   To store account number
                                 double principle             :   To store principle
                                 Member Functions
                                 account(int a1, double b1)    :   To initialise acc_no and principle with a1 and b1
                                 void display()               :   To display acc_no and principle
                                 A subclass called simple_interest is derived from this base class.
                                 Data Members
                                 double rate                  :   To store rate of interest
                                 double time                  :   To store time for interest
                                 Member Functions
                                 simple_interest()            :   A parameterised constructor to initialise rate and time
                                 double interest()            :   To calculate and return simple interest
                                 void display()               :   To display rate and time
                                 A subclass called compound_interest is derived from this base class.
                                 Data Members
                                 double rate                  :   To store rate of interest
                                 double time                  :  To store time for interest
                                 Member Functions
                                 compound_interest            :   a parameterised constructor to initialise rate and time
                                 double interest()            :   To calculate and return compound interest
                                 void display()               :   To display rate and time
                                 Write a  menu-driven program which  will  calculate simple and  compound  interest  using
                                 above methods and classes and concept of inheritance.

                   1       class Account
                   2       {

                   3       protectedintacc_no;

                   4       protected double principle;
                   5       Account(int a1,double b1) //Constructor
                   6       {

                   7       acc_no=a1;
                   8       principle=b1;

                   9       }
                   10      void display() //To Display Account Number and Principle

                   11      {
                   12      System.out.println("The Account Number is " + acc_no);

                   13      System.out.println("The Principle Amount is Rs." + principle);





                                                                                                                       603
                                                                                                   Internal Assessment  603
   600   601   602   603   604   605   606   607   608   609   610