Question: Write Units Tests for both codes C++ Code: #include #include std::vector fibonacci(int n) { std::vector fib; if (n > n; std::vector fib = fibonacci(n); std::cout

Write Units Tests for both codes

C++ Code:

#include

#include

std::vector fibonacci(int n) {

std::vector fib;

if (n <= 0) {

return fib;

} else if (n == 1) {

fib.push_back(0);

return fib;

} else if (n == 2) {

fib.push_back(0);

fib.push_back(1);

return fib;

} else {

fib.push_back(0);

fib.push_back(1);

for (int i = 2; i < n; i++) {

fib.push_back(fib[i-1] + fib[i-2]);

}

return fib;

}

}

int main() {

int n;

std::cout << "Enter a positive integer: ";

std::cin >> n;

std::vector fib = fibonacci(n);

std::cout << "The first " << n << " numbers in the Fibonacci sequence are: ";

for (int i = 0; i < fib.size(); i++) {

std::cout << fib[i] << " ";

}

std::cout << std::endl;

return 0;

}

C++ Code:

#include

void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) {

if (n == 1) {

std::cout << "Move disk 1 from rod " << from_rod << " to rod " << to_rod << std::endl;

return;

}

towerOfHanoi(n-1, from_rod, aux_rod, to_rod);

std::cout << "Move disk " << n << " from rod " << from_rod << " to rod " << to_rod << std::endl;

towerOfHanoi(n-1, aux_rod, to_rod, from_rod);

}

int main() {

int n = 3; // number of disks

towerOfHanoi(n, 'A', 'C', 'B'); // A, B, and C are the names of the rods

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!