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
Hi dost here Alok Kumar please send question pattern for NIC at godinall.kumar1@gmail.com or alok.iitb07@gmail.com
plz snd me sbi probationofficers papers to my id archpa@gmail.com
sir , i am prparing for IOCL engineergin post please send me the old placement papers
What is the instruction to load the register B?
Why do you want to work here
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..
if u have question papers/sample papers of any of PSUs,plz send me at dinesh.pandey3@gmail.com
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
hi, please send me "state bank of india", last 5 years question paper with answers to my mail id.
Please send me the ongc old question papers
can u give me the information about the questions asked by the bally in campus
consiteunts of indian railways
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
Hi i want some previous interview questions and answers for KVB Bank.
can you provide me uniken pvt ltd. technical interview question and answer?