Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solving this task with recursion in c++: PLZ write every class with their own file, you should include the flowing files: Reverse.cpp Reverse.h Fibonacci.cpp Fibonacci.h

Solving this task with recursion in c++:

PLZ write every class with their own file, you should include the flowing files:

Reverse.cpp

Reverse.h

Fibonacci.cpp

Fibonacci.h

EfficientFibonacci.cpp

EfficientFibonacci.h

main.cpp

image text in transcribed

image text in transcribed

1. Reversing the input As the first part of this practical, you are going to implement a class called Reverse which has two recursive functions reverseDigit and reverseString * int reverseDigit(int value): The function takes in an non-negative int value and reverse the digits using recursion. The "reversed" int is then re- turned. For example, reverseDigit(12345) returns 54321 * string reverseString(string letters): The function takes in a std: :string and returns the reversed string Note that, you must make use of recursion in both functions. This means you need to work out how to reduce the problem and what the base case should be 2. Calculating Fibonacci Numbers In mathematical terms, the sequence of Fibonacci numbers is defined by the recur- rence relation where Fo-0 and F-1 (More details are available at http://en.wikipedia.org/wiki/Fibonacci_number) First think about how to recursively determine the values of specific Fibonacci numbers. You are required to construct a class called Fibonacci that reads in a number n and outputs the n-th Fibonacci number Fn 3. More Efficient Fibonacci Calculation In order to calculate Fn, you need to recursively calculate Fn-1 and Fn-2. Then, to calculate F-1, we need F-2 (again!) and F-3. This means that many Fibonacci numbers may be calculated multiple times Reproduce your Fibonacci class in another class called EfficientFibonacci Make this class efficient by storing calculated numbers. The recursive function should not be called for a number that has already been calculated 4. Handling errors Your program may encounter errors, and it should be able to handle them. Modify your code so that when errors do occur, it prints out "ERROR" and does noth ing more for that part of the test. For instance, for input "A" to reverseDigit function, the output would be "ERROR" (since A is not a non-negative integer) For now, you do not need to consider integer overflow. That is, you are safe to assume that you will only be asked to calculate small Fibonacci numbers 5. Main functioin You are asked to create a main function (main.cpp). It takes one line of input The input consists of a non-negative integer i, a string s, a non-negative integer nl and another non-negative integer n2. The string and integers will be separated by spaces. The output should be in one line as well. It should be the reverse of i the reverse of s and the two values of F and Fn2 calculated using Fibonacci and

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions