Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please solve the following problem using C++ language. Be sure to include commen

ID: 3876998 • Letter: P

Question

Please solve the following problem using C++ language. Be sure to include comments so that I am able to understand the code. Pleae make sure to label the 3 files as directed. Thanks in advance.

Q3. (30 pts) Make a class called Algorithms on your own, create a public function 'Fibonacci' to calculate the Fibonacci numbers using recursion, and make your private variable based on vour need. Notes: ou need to create at least three files: a·h, and a ".cpp' for your class and a '.cpp' for the main function.

Explanation / Answer

//header
#ifndef ALGORITHM_H
#define ALGORITHM_H
class Algorithm {
   //declarations in header
   private:
       int a,b;
   public:
       Algorithm();
       void Fibonacci(int n);
   };

#endif

//cpp

#include"Algorithm.h"
#include<iostream>
using namespace std;
//method definitions
Algorithm::Algorithm(){a=0;b=1;}//initiating private variables
void Algorithm::Fibonacci(int n)
{
   if(n>0)
   {
       cout<<a<<endl;
       int k=a;
       a=b;
       b=k+b;//generating fibonacci sequence
       Fibonacci(--n);  
   }
}


//main method
int main()
{
   int n;
   cout<<"Enter number:";
   cin>>n;
   cout<<"Fibonacci sequence of "<<n<<" numbers ";
   Algorithm m;//creatin object
   m.Fibonacci(n);//calling fibonacci method
  
   return 0;
}

output:

Enter number:10
Fibonacci sequence of 10 numbers
0
1
1
2
3
5
8
13
21
34


Process exited normally.
Press any key to continue . . .