Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ code Please... ALL INFO NEEDED ARE HERE! a) In the file homework_part_1.cpp (available on Canvas), add header comments and function comments b) Implement the

C++ code Please... ALL INFO NEEDED ARE HERE!

  1. a) In the file homework_part_1.cpp (available on Canvas), add header comments and function comments

  1. b) Implement the function initializeArray that receives two parameters: an array of integers and the array size. Use a for loop and an if statement to put 0s in the odd positions of the array and 5s in the even positions. You must use pointers to work with the array. Hint: review pointers as parameters.

  1. c) Implement the function printArray that receives as parameters an array of integers and the array size. Use a for statements to print all the elements in the array. You must use pointers to work with the array. Hint: review pointers as parameters.

  1. d) Implement the function arrayInsertionSort that receives as parameters an array of integers and the array size, and order the arrays elements in descending order. Implement Insertion Sort algorithm. It should be Insertion Sort, not Selection Sort, not Quick Sort, etc.

  1. e) Implement the recursive function that calculates and returns the factorial of a number. The function receives the number (integer number) as parameter

  1. f) Compile and run the code for homework_part_1.cpp

#include

using namespace std;

void initializeArray(int* array, int length)

{

}

void printArray(int* array, int length)

{

}

void insertionSort(int* array, int length)

{

}

int factorial(int num)

{

return 0;

}

int main()

{

int a[] = {2, 5, 7, 9, 12, 13, 15, 17, 19, 20};

int b[] = {18, 16, 19, -5, 3, 14, 6, 0};

int c[] = {4, 2, 5, 3, 1};

/* testing initialize_array */

printArray(a, sizeof(a)/sizeof(a[0])); /* print: 2, 5, 7, 9, 12, 13, 15, 17, 19, 20 */

initializeArray(a, sizeof(a)/sizeof(a[0]));

printArray(a, sizeof(a)/sizeof(a[0])); /* print: 5, 0, 5, 0, 5, 0, 5, 0, 5, 0 */

/* testing insertionSort */

printArray(b, sizeof(b)/sizeof(b[0])); /* print: 18, 16, 19, -5, 3, 14, 6, 0 */

insertionSort (b, sizeof(b)/sizeof(b[0]));

printArray(b, sizeof(b)/sizeof(b[0])); /* print: 19, 18, 16, 14, 6, 3, 0, -5 */

/* testing factorial */

cout << factorial(5) << endl; /* print: 120 */

c[0] = factorial (c[0]);

c[1] = factorial (c[2]);

printArray(c, sizeof(c)/sizeof(c[0])); /* print: 24, 120, 5, 3, 1 */

return 0;

}

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

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago