Question: a ) Write a recursive function in C + + with the following prototype: int getWholeNumber ( string s ) ; The function should recognize

a) Write a recursive function in C++ with the following prototype:
int getWholeNumber(string s);
The function should recognize a possibly empty sequence of base 10 digits and return the corresponding value as a nonnegative integer, or return -1 if the string contains any non-digits. For the recursive case, call the function on s.substr(0, s.length-1). In the special case where s is empty string, the function should return 0.(This can be your base case.)
b) Write a function int getInteger(string s, bool & isValid); that recognizes valid integers. That means a nonempty sequence of digits, possibly preceded by a single minus sign. If the string is not a valid integer, then the function should set isValid to false and return 0. If the string is a valid integer then the function will set isValue to true and return the corresponding integer value. Your code should call getWholeNumber from Part a.
a ) Write a recursive function in C + + with the

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 Programming Questions!