Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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.

image text in transcribed

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 Paul

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

2. Develop a persuasive topic and thesis

Answered: 1 week ago

Question

1. Define the goals of persuasive speaking

Answered: 1 week ago