Question

In: Computer Science

C++ Code each of the following functions RECURSIVELY  (each function should use only the parameter value, and...

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

Solutions

Expert Solution

OUTPUT


Related Solutions

note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is...
note: USE C++ WITH USER DEFINED FUNCTIONS AND RECURSIVE FUNCTION ONLY. No C++ library function is allowed. The game of “Jump It” consists of a board with n positive integers in a row, except for the first column, which always contains zero. These numbers represent the cost to enter each column. Here is a sample game board where n is 6: 0 3 80 6 57 10 The object of the game is to move from the first column to...
The code should be written in c++. It should be in only OpenGL // ***** ONLY...
The code should be written in c++. It should be in only OpenGL // ***** ONLY OpenGL PLEASE ******// write a program snippet that accepts the coordinates of the vertices of a rectangle centered around the origin, with edges that are parallel to the X and Y axes, and with aspect ratio W and converts it into a rectangle centered around the origin with aspect ratio of 1/W. The program has to figure W from the given points. You MUST...
Code should be written in C Use pointer variables for parameter passing, where appropriate and pointer...
Code should be written in C Use pointer variables for parameter passing, where appropriate and pointer arithmetic when working with arrays. 1) Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election hold the names of the subdivision hold the vote counts in the Brampton subdivision for each candidate hold the vote counts in the Pickering subdivision for each candidate hold the vote counts in the Markham subdivision...
Please write the code in c++ Write a function with one input parameter that is a...
Please write the code in c++ Write a function with one input parameter that is a vector of strings. The function should count and return the number of strings in the vector that have either an 'x' or a 'z' character in them. For example, when the function is called, if the vector argument contains the 6 string values, "enter", "exit", "zebra", "tiger", "pizza", "zootaxy" the function should return a count of 4. ("exit", "zebra", "pizza", and "zootaxy" all have...
create overloaded functions called lastValue. The first function should take as a parameter a string and...
create overloaded functions called lastValue. The first function should take as a parameter a string and the second function should take as a parameter an int. each of you functions should return an int value. in the case of the function that takes the string as an argument you will return the ascii value of the last character in the string. in the case of the function that takes an int parameter your function will return the last digit in...
Fill in the code for the following C functions. Function srl performs a logical right shifting...
Fill in the code for the following C functions. Function srl performs a logical right shifting using arithmetic right shift (given by value xsra), followed by other operations not including right shifts or division. Function sra performs an arithmetic right shift using a logical right shift (given by value xsrl), followed by other operations not including right shift or division. you may use the computation 8*size of (int) to determine w, the number of bits in data type int. The...
please use text only! Instructions Consider the provided C++ code in the main.cpp file: The function...
please use text only! Instructions Consider the provided C++ code in the main.cpp file: The function func2 has three parameters of type int, int, and double, say a, b, and c, respectively. Write the definition of func2 so that its action is as follows: Prompt the user to input two integers and store the numbers in a and b, respectively. If both of the numbers are nonzero: If a >= b, the value assigned to c is a to the...
DEVELOP A C++ PROGRAM IN PROCEDURAL CODE that will recursively alphabetize a set of strings in...
DEVELOP A C++ PROGRAM IN PROCEDURAL CODE that will recursively alphabetize a set of strings in a user-specified file using the tree sort algorithm explained in the lectures while maintaining a balanced binary tree at all times. The following will test your program with an input file containing: Max Hank Jet Frisky Chata Richard Nan Sam Thomas Karen Gerri Ingrid Alan Dana When done print out the contents of the tree with inorder traversal in a tabular format similar to...
in c++, please provide only a function. the function should be named "tally." it takes no...
in c++, please provide only a function. the function should be named "tally." it takes no parameters but returns an int. the first int should be 0, next being 1, then 2, etc.. will rate if correct. again should only be 1 function.
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT