0% found this document useful (0 votes)
58 views2 pages

10FIBONACCI

This document contains code to generate a Fibonacci series using a copy constructor in C++. The code defines a Fibonacci class with data members to store Fibonacci numbers. It includes a default constructor, a parameterized constructor to set the length, and a copy constructor. The main function takes user input for the length, creates an object using the parameterized constructor, and passes it to the copy constructor to generate and display the Fibonacci series up to the given length using recursion.

Uploaded by

nike123cool
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views2 pages

10FIBONACCI

This document contains code to generate a Fibonacci series using a copy constructor in C++. The code defines a Fibonacci class with data members to store Fibonacci numbers. It includes a default constructor, a parameterized constructor to set the length, and a copy constructor. The main function takes user input for the length, creates an object using the parameterized constructor, and passes it to the copy constructor to generate and display the Fibonacci series up to the given length using recursion.

Uploaded by

nike123cool
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICAL NO 10 AIM: W.a.p to generate a Fibonacci series using copy constructor.

SOURCE CODE:
#include <iostream.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> class Fibonacci { int f,f1,f2,m; public: Fibonacci() { } Fibonacci(int n) { m=n; } Fibonacci( Fibonacci &x) { x.f1=0; x.f2=1; cout<<"\n the required Fibonacci series is as follows: \n\n "; cout<<" "<<x.f1<<" "<<x.f2; for(int i=2;i<=x.m;i++) { x.f=x.f1+x.f2; cout<<" "<<x.f; x.f1=x.f2; x.f2=x.f; } } void display(); void display1(); void series(int); }; void main() { char ch; int n;

do { clrscr(); cout<<"\n Enter the length of series:"; cin>>n; clrscr(); Fibonacci A(n); Fibonacci B(A); cout<<"\n \n Want to enter more(y/n): "; cin>>ch; }while(ch=='y'||ch=='Y'); }

OUTPUT

Enter the length of series:10 The Required Fibonacci series is as follows: 0 1 1 2 3 5 8 13 21 34 55 Want to enter more(y/n): N

You might also like