Question: Need help with this C++ project. Overview: For problems 1(a) of this assignment, you will need a C++ compiler. In order to receive credit, your

Need help with this C++ project. Overview: For problems 1(a) of this assignment, you will need a C++ compiler. In order to receive credit, your program must compile and run; and you must provide the actual source code file so that I can compile and run your program (e.g. the file you modified or created ending in .cpp). Examples on how to import existing source code files into your compiler are provided in the file called Importing Source Code.pdf. The remaining problems for the assignment must be written up within a single Microsoft Word document. You must include your name and course number within all files that you submit, including source code files as a comment at the top of each file that you create or modify.

1. [6 points] Recursion. Read the assigned chapter and notes for Week 1 located in the Learning Modules area in Blackboard. Then provide solutions for the following: (a) [3 points] Download the h.zip file, then implement a recursive function called h(), which can be directly translated into C/C++ from the following mathematical definition:

/** * h.cpp - This progam implements the h() function * as described in the handout. * * */

#include

#include

#include

using namespace std;

int h(int x);

int main(int argc, char **argv)

{ cout << "h(0) is " << h(0) << endl;

cout << "h(1) is " << h(1) << endl;

cout << "h(2) is " << h(2) << endl;

cout << "h(3) is " << h(3) << endl;

cout << "h(4) is " << h(4) << endl;

cout << "h(5) is " << h(5) << endl;

cout << " ** Press any key to continue ** ";

getchar();

return 0; }

int h(int x)

{ // TODO: implement the function h() based on the // mathematical definition provided in the handout. }

(b) [1.5 points] What type of recursion does the h() function in part (a) use? Briefly explain your answer.

(c) [1.5 points] Explain the recursive function design rule that Excessive Recursive functions typically violate. Also, specifically describe why violating this rule is a problem.

2. [5 points] Complexity Analysis. Begin by reading the assigned chapter and notes for Week 2 located in the Learning Modules area in Blackboard. Then answer the following questions:

(a) [2 points] What is the asymptotic complexity (big-O) of the following function? Briefly explain why. Note: No programming is necessary for this problem. Just tell me what the big-O of the function, and provide a couple of sentences explaining how you arrived at the solution.

int pow(int n, int exponent)

{ int result = 1;

for (int i=0; i < exponent; i++)

{ result *= n;

}

return result; }

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!