adspace


C++ PROGRAM FOR FIBONACCI SERIES USING COPY CONSTRUCTER

Answer Posted / Hari Krishna

Here is a simple example of a C++ program for the Fibonacci series using copy constructor. This code defines a class named Fibonacci, which has a private member 'num' to store the current number in the series.nn```cppn#include <iostream>nusing namespace std;nnclass Fibonacci {nprivate:n int num;npublic:n Fibonacci() { num = 0; }n Fibonacci(const Fibonacci &obj) { num = obj.num; }n void getFibonacci();n};nvoid Fibonacci::getFibonacci() {n if (num <= 1)n cout << num << " ";n else {n Fibonacci first( *this );n Fibonacci second;n first.getFibonacci();n second.num = first.num + this->num;n second.getFibonacci();n }n}nint main() {n Fibonacci fib1, fib2, fib3;n fib1.getFibonacci(); // Prints the first number in the series: 0n fib2 = fib1; // Copy constructor called here.n fib2.getFibonacci(); // Prints the second number in the series: 1n fib3 = fib2; // Copy constructor called here.n fib3.getFibonacci(); // Prints the third number in the series: 1 + 1 = 2.n return 0;n}n```

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Hi dost here Alok Kumar please send question pattern for NIC at godinall.kumar1@gmail.com or alok.iitb07@gmail.com

1950


plz snd me sbi probationofficers papers to my id archpa@gmail.com

2278


sir , i am prparing for IOCL engineergin post please send me the old placement papers

2125


What is the instruction to load the register B?

2442


Why do you want to work here

1835


Iam preparing for Visakhapatnam Management Trainee 2009 entrance exam.. If anybody have Visakhapatnam Management Trainee Interview questions Pls forward to my mail id srikanth.avanthi@gmail.com .. It is kindly request..

2421


if u have question papers/sample papers of any of PSUs,plz send me at dinesh.pandey3@gmail.com

1944


hi, i applied for AIRPORTS AUTHORITY OF INDIA for the post of AIR TRAFFIC CONTROLLER(ATC)..so plz send me the sample questions to my id...88arun@gmail.com

2362


hi, please send me "state bank of india", last 5 years question paper with answers to my mail id.

2147


Please send me the ongc old question papers

3168


can u give me the information about the questions asked by the bally in campus

1957


consiteunts of indian railways

2413


Prepare the UGC CSIR net question papers those are enough. The question paper will be of 50 questions in size each 3 marks and with a negative of -1 for each wrong answer

3106


Hi i want some previous interview questions and answers for KVB Bank.

2708


can you provide me uniken pvt ltd. technical interview question and answer?

3232