C++ PROGRAM FOR FIBONACCI SERIES USING COPY CONSTRUCTER



C++ PROGRAM FOR FIBONACCI SERIES USING COPY CONSTRUCTER..

Answer / 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

More Engineering AllOther Interview Questions

Please. Does someone know how to inicialize tapes in ATL? I need have 100 tapes to init inside the ATL, how is the process to complete this request?

1 Answers   EDS,


why view is created in database

1 Answers   Daraz.pk,


what happens if an error occurs in constructor or destructor.

1 Answers   Microsoft,


What is the pressure in co2 cartridge in a DCP 5 kg extinguisher.

1 Answers   L&T, Samsung,


How can I get know that my pc contains dram or sram..?

1 Answers  


What will be the sql query to list the employee names those are getting 3rd highest salary ?

1 Answers  


what is active dirctory?

2 Answers   jetking,


Apply Newton?s method to compute the approximate value of root 2. Start the iteration from x0=1, and obtain two iterations.

1 Answers  


Implement the dictionary operations INSERT, DELETE, and SEARCH using singly linked, circular lists. What are the running times of your procedures?

1 Answers  


What is meant by STL?

1 Answers  


who are egoless programmers?

1 Answers  


Can anyone tell me the exact formulae with explanation for the questions related to cube which is asked for CTS? I have seen varieties of formulae in different sites.I need the exact on... So pls help me out!!!

0 Answers   CTS,


Categories
  • Civil Engineering Interview Questions Civil Engineering (5086)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4453)
  • Electrical Engineering Interview Questions Electrical Engineering (16638)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)