Question: C++ Programming: Here are five functions, with descriptions of what they are supposed to do. They are incorrectly implemented. Replace the incorrect implementations of thes

C++ Programming: Here are five functions, with descriptions of what they are supposed to do. They are incorrectly implemented. Replace the incorrect implementations of thes functions with correct ones that use recursion in a useful way; your solution must not use the key words while, for, or goto. You must not use global variables or variables declared with the keyword static, and you must not modify the function parameter lists. You must not create any auxiliary or helper functions.

// Returns theproduct of two positive integers, m and n,

// using only repeated addition.

int mult(unsigned int m, unsigned int n)

{

return - 1; // This is incorrect.

}

// Returns the number of occurrences of digit in the decimal

// representation of num. digit is an int between 0 and 9

// inclusive.

//

// Pseudocode Example:

// countDigit(18838, 8) => 3

// countDigit(55555, 3) => 0

// countDigit(0, 0) => 0 or 1 (either is fine)

//

int countDigit (int num, int digit)

{

return -1; // This is incorrect.

}

// Returns a string where the same characters next each other in

// string n are separated by "--"

//

// Pseudocode Example:

//pairMinus("goodbye") => "go--odbye"

// pairMinus("yyuu") => "y--yu--u"

// pairMinus("aaaa") => "a--a--a--a"

//

string pairMinus(string n)

{

return ""; // This is not always correct.

}

// str contains a single pair of parenthesis, return a new string

// made of only the parenthesis and whatever those parenthesis

// contain.

//

// Pseudocode Example:

// findParen("abc(ghj)789") => "(ghj)"

// findParen("(x)7") => "(x)"

// findParen("4agh(y)") => "(y)"

//

string findParen(string str)

{

return "*"; // This is incorrect.

}

// Return true if the sum of any combination of elements in the array

// a equals the value of the target.

//

// Pseudocode Example:

// combinationSum({2, 4, 8}, 3, 10) => true

// combinationSum({2, 4, 8}, 3, 12) => true

// combinationSum({2, 4, 8}, 3, 11) => false

// combinationSum({}, 0, 0) => true

//

bool combinationSum(const int a[], int size, int target)

{

return false; // This is not always correct.

}

The program utilizing these functions should all be in a file .cpp , which will have a main() function calling each of the five functions with the test cases

above. It should compile and run, even if you cant match the results of all five functions.

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!