Page 669 - Computer science 868 Class 12
P. 669

cap                                       :   stores the capacity of the array
                     f                                         :   to point to the index of the front
                     r                                         :   to point to the index of the rear
                     Members Functions
                     Repeat(int m)                             :    constructor to initialise the data members cap=m, f=0, r=0 and to create
                                                                  the integer array
                     void pushvalue(int v)                     :    to add integers from the rear index if possible else display the message
                                                                  “overflow”
                     int popvalue()                            :    to remove and return element from the front, if array is empty then
                                                                  return -9999
                     void disp()                               :   displays the elements present in the list
                     Specify the class Repeat giving details of the constructor(int), member function void pushvalue(int), and int popvalue()
                  Ans.  import java.util.*;
                     class Repeat
                     {
                     int st[]=new int[100];
                     int cap, f, r;
                     Repeat (int m) // constructor
                     {
                     cap = m;
                     f=0;
                     r=0;
                     st = new int[cap];
                     }
                     void pushvalue (int v)
                     {
                     if (r == cap)//Queue full
                     {
                     System.out.println ("OVERFLOW");
                     }
                     else
                     {
                     st[++r] = v; // insert from rear end
                     }
                     }
                     int popvalue()
                     {
                     if (f == r) // underflow condition
                     {
                     return -9999;
                     }
                     else
                     { // deletion from front end
                     return st[f++];
                     }
                     }}
                 Question  10.                                                                                         [5]
                     A base class Quadratic is defined to enter a, b, c the numerical coefficients of a quadratic equation ax2+ bx+c and calculate the
                     discriminant d as b2-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 initialise the coefficients
                     void calculate()                          :      Calculate discriminant of the quadratic equation  as b2- 4ac
                     void display()                            :   Print coefficients a,b and c and discriminant d




                                                                                                                       667
                                                                                                        Sample Paper   667
   664   665   666   667   668   669   670   671   672   673   674