Page 292 - ComputerScience_Class_11
P. 292

12.  A class SeriesSum is designed to calculate the sum of the following series:

                    Sum =  x 2  +  x 4  +  x 6  + . . .   x n
                          1!  3!  5!    (n-1)!

                     Some of the members of the class are given below:
                     Data Members/Instance variables
                     x                       :   Stores an integer number
                     n                       :   Stores the number of terms
                     sum                     :   double variable to store the sum of the series
                     Member Functions
                     SeriesSum(int xx, int nn)   :   Constructor to assign x=xx and n=nn
                     double find fact(int m)   :   Returns the factorial of m using the recursive technique
                     double find power(int x, int y)  :   Returns x raised to the power of y using the recursive technique
                     void calculate()        :   Calculates the sum of the series by invoking the recursive functions respectively
                     void display()          :   Displays the sum of the series
                     Also, define the main() function to create an object and call the functions accordingly to enable the task.
                 13.  Design a class to overload a function compare() with the specifications given as follows:
                     void compare(int, int)   :   Compares two integer values and prints the greater of the two integers
                     void compare (char, char)   :     Compares  the  numeric  values  of  two  characters  and  prints  the  character  with  a  higher
                                                numeric value
                     void compare (String, String)   :   Compares the length of the two strings and prints the longer of the two.




















































                  290  Touchpad Computer Science (Ver. 3.0)-XI
   287   288   289   290   291   292   293   294   295   296   297