A program to generate a series of Fibonacci numbers using a copy constructor where the copy constructor is defined within the class declaration itself.
#include<iostream.h>
#include<conio.h>
class fibonacci
{
private:
unsigned long int f0,f1,fib;
public:
fibonacci()
{
f0=0;
f1=1;
fib=f0+f1;
}
fibonacci (fibonacci &ptr)
{
f0=ptr.f0;
f1=ptr.f1;
fib=ptr.fib;
}
void increment()
{
f0=f1;
f1=fib;
fib=f0+f1;
}
void display()
{
cout << fib <<"\t";
}
}; //end of class construction
void main()
{
clrscr();
fibonacci number;
for (int i=1; i<=5;i++)
{
number.display();
number.increment();
}
}
copy constructor video: 5 minutes
https://www.youtube.com/watch?v=2LxU7vroRj0
https://www.youtube.com/watch?v=6ldGLSqQCTo
#include<iostream.h>
#include<conio.h>
class fibonacci
{
private:
unsigned long int f0,f1,fib;
public:
fibonacci()
{
f0=0;
f1=1;
fib=f0+f1;
}
fibonacci (fibonacci &ptr)
{
f0=ptr.f0;
f1=ptr.f1;
fib=ptr.fib;
}
void increment()
{
f0=f1;
f1=fib;
fib=f0+f1;
}
void display()
{
cout << fib <<"\t";
}
}; //end of class construction
void main()
{
clrscr();
fibonacci number;
for (int i=1; i<=5;i++)
{
number.display();
number.increment();
}
}
copy constructor video: 5 minutes
https://www.youtube.com/watch?v=2LxU7vroRj0
https://www.youtube.com/watch?v=6ldGLSqQCTo
No comments:
Post a Comment