Description
Fibonacci numbers are the sequence of no.s such that each no. in the sequence is the
sum of previous 2 no.s.
The first 2 fibonacci no.s are 0 and 1. The third fibonacci no. is 0+1 = 1. The fourth
fibonacci no. is 1+1 = 2 (ie sum of 2nd and 3rd terms). The fifth fibonacci no. is 1+2=3
(ie sum of 3rd and 4th term).
Given below is a fibonacci sequence:
0,1,1,2,3,5,8,13,21,34… and so on.
Using the object oriented programming approach, perform the following tasks:
1) Define a class fibonacciClass. This class should be capable of holding
fibonacci no.s in an array called fibo.
The data members of this class should be as given below:
• max_size: It stores the maximum size of fibo array (ie. max no. of elements
that can be stored in fibo).
• curr_size: It stores the details about the no. of elements currently present in
fibo. Set the default value of max_size to 100.
2) Define a getter method to retrive the value of curr_size.
3) Define a method generateSequence. This method accept an integer parameter
N (which specifies how many no.s needs to be generated in the sequence). This
method should check if N<=max_size. If N<=max_size, then it should
generate N fibonacci no.s and store no. in fibo array. If N>max_size, then
generate max_size fibonacci no.s and store them in fibo array.
4) Define a method displaySequence. This method should display the fibonacci
sequence stored in fibo.
5) main() method creates an instance of fibonacci class. It accepts the value of N
( which specifies how many no.s needs to be generated in the sequence) from
the user, invokes the necessary methods to generate and display the fibonacci
sequence.