Wednesday, October 26, 2011

fibnocci series by using object oriented programming with copy constructor.


We can generate the fibnocci series by using object oriented programming with copy constructor.


#include
#include
class fib

{
int p,q,r;
public:
fib()
{
p=0;q=1;r=p+q;
}
fib(fib &f)
{
p=f.p;
q=f.q;
}
void display()
{
cout<<r<<" ";
r=p+q;
p=q;
q=r;
}
};
void main()
{
clrscr();
int n;
cout<<"Enter a number ";
cin>>n;
fib A;
fib B(A);
cout<<"Fibonacci series"<<endl;
cout<<"Default constructor"<<endl;
for(int i=0;i<n;i++)
A.display();
cout<<endl<<"copy constructor"<<endl;
for(i=0;i<n;i++)
B.display();
getch();
}</n;i++)
</endl<<"copy></n;i++)
</endl;
</endl;
</r<<">

No comments:

Post a Comment

Thank you for your comment