//Use of copy constructor
#include<iostream.h>
#include<conio.h>
class fibo
{
private:
long int x,y,z;
public:
fibo(); //constructor
fibo(fibo &ptr); //copy constructor
void increment();
void display();
};
fibo::fibo()
{
x=0;y=1;z=x+y;
}
fibo::fibo(fibo &ptr)
{
x=ptr.x;y=ptr.y;z=ptr.z;
}
void fibo::increment()
{
x=y;
y=z;
z=x+y;
}
void fibo::display()
{
cout<<"\n";
cout<<z<<"\t";
}
void main()
{
clrscr();
fibo no;
int i;
for(i=0;i<=15;i++)
{
no.display();
no.increment();
}
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.