Computer Science, asked by rahulgond5327, 1 year ago

Write a program to generate a fibonacci series using copy constructor. c++


poppop: Brother this is unusual and bothering too. You can do it simply.

Answers

Answered by DoofenshmirtzEvilInc
6
#include‹iostream.h›
Using namespace std;
Int main()
{
Int a=0,b=1,c,n;
Cout‹‹"Enter the no.of elements ";
Cin››n;
Cout‹‹" The Fibonacci series is"‹‹"\n";
Cout‹‹a‹‹" "‹‹b;
For(int i=2;i‹n;i++)
{
C=a+b;
Cout‹‹" "‹‹c;
a=b;
b=c;
}
return 0;
}
Answered by franktheruler
6

Answer:

#include  < iostream >

class fibonacci _series

{

private:

int f1,  f2, f ;

public:

fibonacci_series ( )

{

f1=0;

f2=1;

f = f1 + f2;

}

fibonacci_series ( fibonacci_series & ptr )   // copy constructor

{

f1 = ptr.f1;

f2 = ptr.f2;

f = ptr.f;

}

void increment ( )  // method

{

f1 = f2  ;

f2 = f ;  

f =f1 + f2 ;

}

void show ( )  // method

{

cout << f ;

}

} ; //end of class construction

void main (void)

{

fibonacci_series number;

for ( int j = 0 ; j <= 15 ; i++ )

{

number. show ( ) ;

number. increment ( );

}

}

Similar questions