In: Computer Science
C++
Code each of the following functions RECURSIVELY (each function should use only the parameter value, and any local function variables you might need ..no variables are to be declared outside the functions).
void upTo(int number)
This function prints all values from 1 up to the number.
upTo(5);
should output: 1 2 3 4 5
HINT: the following functions involve separating a digit from a number. Use of the arithmetic operators % and / are helpful here. Remember a % 10 results in the leftmost digit of a number, and a = a / 10 removes the leftmost digit from a number.
void printRev(int number)
This function prints out the digits of the parameter in reverse. For example, the call
printRev(2367); will print out 7632
int sumDig(int number)
This function returns the sum of the digits in the parameter. For example, the call
cout << sumDig(4372); will print out the value 16.
bool isThere(int number, int digit)
This function returns true if digit occurs in number, and false otherwise.
For example, the following statement will print “it is there”.
if ( isThere(4593, 9) )
cout << “it is there”;
else
cout<< “it is not there”;
int howmany(int number, int digit)
This function returns the number of occurrances of 'digit' in the parameter number.
For example, the following statement will print 3
cout << howmany(22542, 2) << endl;
* prompt the user for a positive integer
* call upTo, sumDig, printRev
* prompt the user for a single digit
* call isThere using this integer (and digit) as parameter values
* call howmany using this integer the digit as parameter values