Question

C++ Q3. (30 pts) Make a class called Algorithms on your own, create a public function...

C++

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 your need.

Notes:

          You need to create at least three files: a ‘.h’ and a ‘.cpp’ for your class and a ‘.cpp’ for the main function.

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

Algorithms.h

#ifndef ALGORITHMS_H
#define ALGORITHMS_H


class Algorithms
{
public:
Algorithms();
virtual ~Algorithms();
int get_n();
int recursion(int x);
protected:
private:
int n = 5;
};

#endif // ALGORITHMS_H

Algorithm.cpp

#include "Algorithms.h"

Algorithms::Algorithms()
{
//ctor
}

Algorithms::~Algorithms()
{
//dtor
}
int Algorithms::get_n() {return n;}

int Algorithms:: recursion(int x)
{
if((x==1)||(x==0))
{
return(x);
}
else
{
return(recursion(x-1)+recursion(x-2));
}
}

main.cpp

#include <iostream>
#include "Algorithms.h"
using namespace std;

int main() {
Algorithms obj;
int n = obj.get_n();
int i = 0;
cout<<"Fibonacci Series is:\n";
while (i < n)
{
cout<<obj.recursion(i)<<" ";
i++;
}
return 0;
}

CAUsers LENOVO Downloads\fiblbin\Debuglfib.exe Fibonacci Series is: 0 1 1 2 3 Process returned e (exe) Press any key to conti

**Comment for any further queries. Upvote if the answer is satisfactory.

Add a comment
Know the answer?
Add Answer to:
C++ Q3. (30 pts) Make a class called Algorithms on your own, create a public function...
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
  • Question 3: Q3 (Polymorphism & virtual function) a) Consider the class, derived class, and the virtual functions as shown in Display for Q3. Create a derived class (of Sale) called 'Mailorder...

    Question 3: Q3 (Polymorphism & virtual function) a) Consider the class, derived class, and the virtual functions as shown in Display for Q3. Create a derived class (of Sale) called 'MailorderSale' having one private member variable called 'shipping charge'. It should have constructor function and virtual function 'bill' (this function adds shipping charge to the price). Define all these functions (no need of default constructors). b) In the main function, define one object of DiscountSale with (11,10) initial values and...

  • {C++} Create a base class called Person with a public member function called sayHi which outputs...

    {C++} Create a base class called Person with a public member function called sayHi which outputs “Hi, I am a person.” Create a derived class called Student which inherits from the Person class (public inheritance) and overwrites the sayHi function and outputs “Hi, I am a student.” Create another derived class called EngineeringStudent which inherits from the Student class (public inheritance) and overwrites the sayHi function and outputs “Hi, I am an engineering student.” In the main program, create a...

  • Programming: Create a class called City with two public variables: a string to store the name...

    Programming: Create a class called City with two public variables: a string to store the name of the city and a float to store the average temperature in Fahrenheit. Create one object of the class that you create and ask the user to enter the city name and the average temperature in Fahrenheit. Store these in the object of the class that you create. Then display the contents of the class. Once that is working, make the variables private and...

  • Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( );...

    Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width,...

    FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Add a recursive Boolean function called checkRecurse to class IntegerLinkedList to check if any two consecutive...

    Add a recursive Boolean function called checkRecurse to class IntegerLinkedList to check if any two consecutive integers in the linked list are equal (return true in this case, false otherwise). You may assume that the list is not empty. A recursion “helper” function is already included in class IntegerLinkedList. You only need to write the recursive function. For example, checkRecurseHelper() should return true for the linked list shown below. A main function (prob3.cpp) is given to you to add data...

  • Java using data structures The objective is to create your own Hash Table class to hold...

    Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...

  • The class declaration (interface) and the function definitions (implementation) must be in separate files - the...

    The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...

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
Active Questions
ADVERTISEMENT