Question

Make a Code in C++ language. The Code should not copy paste from internet. The code...

Make a Code in C++ language. The Code should not copy paste from internet. The code should complete and should run. Also provide output. Make the code in easy way and also provide comments. The code should complete and Don't forget to provide output.

1. Make a cpp class TTT.
2. In that class, you will have two functions. one main function and one function named fib().
3. Get the value of n from user in main function. n specifies the number of elements to be displayed in fibonnaci numbers.
4. pass that value of n to fib(). and then by recursion keep printing the fibonacci sequence.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

answer to the above question is attached below : -

c++ code : -

#include <iostream>
using namespace std;
class TTT //class declarations
{
   //public Functions()
   public:
   int fib(int n) //recursive method to find nth fibpnacci number
   {
   if (n==0) //if n is 0 return 0
   return 0;
   else if (n==1) //if n is 1 return 1
   return 1;
   return (fib(n-1) + fib(n-2)); //return fib(n-1)+fib(n-2)

   }
   //main method for TTT class
   void main() {
   int n; //variable declaration
   cout<<"Enter the numeber of elements in sequence"<<endl;
   cin>>n; //taking user input
   int i=0; //variable
//    printing fibonacci number
   while(i<n) //while i is less than n
   {
   cout<<fib(i)<<" "; //call fib function for each value of i
   i++; //increment in i
   }
}
};
// main driver method of c++ program
int main() {
   // Declare an object of class TTT
   TTT obj;
   // accessing member function
obj.main();
   return 0;
}

code screenshot : -

code output : -

if my answer hellped then pleae upvote and comment for any queries

Thankyou !

Add a comment
Know the answer?
Add Answer to:
Make a Code in C++ language. The Code should not copy paste from internet. The code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi using...

    Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi using stack implementation. The code should not copied means code should unique. Code should not copy paste from any where. Write the code in easy way means coding should of beginner level. Also use more and more comments in the code for better understanding. The code should complete and should able to run. Also provide output of the program. ( 1 ) Code should not...

  • Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi using...

    Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi using stack implementation. The code should not copied means code should unique. It is very neccessary to make code by own. Code should not copy paste from any where. Write the code in easy way means coding should of beginner level. Also use more and more comments in the code for better understanding. The code should complete and should able to run. Also provide output...

  • Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi. Write...

    Make a Complete Code in C++ language. Create a Complete program of Tower of Hanoi. Write the code in easy way means coding should of beginner level. Also use more and more comments in the code for better understanding. The code should complete and should able to run. Also provide output of the program.

  • CMPS 290 Programming Assignment Arrays and Recursion – Fibonacci Numbers In this programming assignment you will...

    CMPS 290 Programming Assignment Arrays and Recursion – Fibonacci Numbers In this programming assignment you will be working with arrays and multiple function calls, including a recursive function call. The goal of the assignment will be to, using a pre-set array of sequence numbers, calculate the Fibonacci sequence number for each value in the array (see the example at the bottom if this isn’t clear). Instructions and Requirements: • Create a program that assembles and runs to find the correct...

  • Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to...

    Extra Credit - Fibonacci Function (Lec. 5 topic: Recursive function and runtime stack. Use recursion to calculate the Fibonacci Function 1.) Use a recursive function called fib() to calculate the Fibonacci Function for the following values for the variable n. int n = 10; int n = 20; int n = 30; int n = 40; int n = 45; int n = 46; 2.) In addition to calculating and displaying the results, use a "timer" to see how long...

  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 file...

    Provide code and full projects neatly and in proper form and in the correct header and cpp files((we have to make 3 files header file , one .cpp file for function and one more main cpp file) Operator Overloading – Chapter 14 Design a class Complex for representing complex numbers and the write overloaded operators for adding, subtracting, multiplying and dividing 2 complex numbers. Also create a function that will print a complex number on the screen. Provide appropriate constructors...

  • PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1...

    PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you...

  • 5 matlab codes 18, Suppose I seed to fetch a mmumerical variable named hours from the user This vaniable needs to be son-orgative Ioe the emaining code in the projert to work property. so before S...

    5 matlab codes 18, Suppose I seed to fetch a mmumerical variable named hours from the user This vaniable needs to be son-orgative Ioe the emaining code in the projert to work property. so before So, we will got the vue of hours fromm the user, and if it is segative, we will tell the user that it ut be non-aegative, and reprompt for a value We will hoep doing this until the uer gots it correct Give the code...

  • CSC 252 Week 4 HW Provide code and full projects neatly and in proper form and...

    CSC 252 Week 4 HW Provide code and full projects neatly and in proper form and in the correct header and cpp files. Code must compile, link and run for any credit.This is Microsoft visual Studio C++ and needs to be done correctly and neatly and I need to be able to copy and paste code to visual studio and this is for a grade so if you don't know the answer don't answer please and thank you. Exception Handling...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT