Question: need help with a computer science lab that deals with recursion. this lab is in C++ language here is the file that we are working
need help with a computer science lab that deals with recursion. this lab is in C++ language here is the file that we are working with. WE CAN NOT MAKE ANY CHANGES FROM WHAT IS GIVEN TO US. NEED TO WORK WITH WHAT IS GIVEN. ALSO STATES WE CAN NOT USE ANY CONDITIONAL STATEMENTS. Lab: Recursion Fun - TEST YOUR MIGHT! No loops allowed for this lab: -no for loops -no while loops -no do-while's -no while-do's -no for-while's -no while-for-do's #1: Write a method void lineOfStars(int n) that prints a line of n stars. You may not use a loop. lineOfStars(5); // should display: ***** #2: Write a method void stars(int n) that prints the weird shape below. You may not use a loop. You may call lineOfStars as a subroutine. stars(4); should display: **** *** ** * * ** *** **** #3: Write a recursive function 'int power(double x, int n)' which returns x^n assuming n is a non-negative integer. #4: Write a recursive function int numOnes(int n) that returns the number of 1's in the binary expansion of n. cout << numOnes(5325) << endl; //should display 7, because 5325 is 1010011001101 in binary. #5: Write a recursive function 'void reverseArray(doulbe * numbers, int start, int end)' which reverses the order of elements in the given array from index start to index end (inclusive). #6: Write a function 'int threeSum(int n)' which returns the value 1+2+3+4+...+ 3n. #7: Write recursive "printForward(node *p)" and "printBackward(node * p)" methods for the linked list class provided below so that the following test code words as specified in the comments: linkedList list; list.push_front(8); list.push_front(7); list.push_front(6); list.push_front(5); list.push_front(4); list.push_front(3); list.push_front(2); list.push_front(1); list.printForwards(); //1,2,3,4,5,6,7,8, cout << endl; list.printBackwards(); //8,7,6,5,4,3,2,1, cout << endl; class linkedList { private: class node { public: double data; node * next; node(double x) { data = x; next = NULL; } }; node * head; //print the contents of the list from p to the end (no loops!) void printForwards(node * p) { } //print the contents of the list from p to the end but in reverse order! void printBackwards(node * p) { } public: linkedList() { head = NULL; } void push_front(double x) { node * babyNode = new node(x); babyNode->next = head; head = babyNode; } void printForwards() { printForwards(head); } void printBackwards() { printBackwards(head); } };
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
