Question
(Put all your work in one .cpp file) All functions must be placed below the main(); The proto types of the functions and the struct
- (Put all your work in one .cpp file)
- All functions must be placed below the main(); The proto types of the functions and the struct should be placed above the main();
- No any C++ reserved words, such as size, min, and end, can be used as the variable names.
- Hard-coding code can only be used for testing the functions.
Requirements:
Use the skeleton code at the bottom to complete all the functions and the data structure design.
int Factorial_nonRecur(int) | Use a loop statement to implement the function. |
int Factorial_Recur(int) | Use a recursive function to implement the function. |
void displayEachDigitOfInt(int)
| This is a recursive function which displays each digit of an integer. For example, the following function call displayEachDigitOfInt(54321); will display 1 2 3 4 5 Hint: When dealing with a string, we can use substr() to get a part of the string. For an integer, we can use the operators + - / % to get the similar results.
|
int getMax_BinRecur(int [], int)
| It returns the biggest integer in the array. Binary recursive function must be used to solve this problem. Hint: Have you noticed that when using binary recursive functions to process and array, we normally need to pass three arguments, i.e. the array name, the begin index and ending index, to the function. But from the perspective of the caller function, only the array name and the size of the array should be passed to the function. So we need a helper function, which passes the array name, begin index and ending index, to solve this problem. This helper function is the one which recursively calls itself. |
Design a data structure which allows us to implement a simplified family tree like the following figure. In this family tree, Mary has two children, i.e. Mary and Michael. Michael has three children, i.e. John, Cindy and Paul. The requirements of this system are listed here. 1. The attributes of a person consists of ID, name, date of birth, gender (or sex), and address. 2. Each person can have unlimited amount of children. 3. The family tree can have unlimited level of hierarchy. Due to the limitation of time, only data structure (by using struct, array and/or array) is required in this test. That is, you do NOT need to provide any function, loop or if statements. |
Code base:
int main()
{
/// display the integer which is equal to 5*4*3*2*1
cout
/// display the integer which is equal to 5*4*3*2*1
cout
/// display 1 2 3 4 5
displayEachDigit(54321);
const int SIZE = 9;
int arr[SIZE] = {5, 8, 2, 11, 9, 4, 7, 13, 12};
cout
return 0;
}
Eve Eve Mary Michael John John Cindy cindy Paul PaulStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started