Question
Please complete the following programming in C++ with clear explanations. Thanks! Primitive Types, Searching and Recursion a) Create a class Homework (in a file homework.h
Please complete the following programming in C++ with clear explanations. Thanks!
Primitive Types, Searching and Recursion a) Create a class Homework (in a file homework.h and homework.cpp). b) Create a function initialize_array that receives two parameters: an array of integers and the array size. Use a for loop and an if statement to put 1s in the odd positions of the array and 0s in the even positions. (Use pointers to pass an array of integers as parameter) c) Create a function print_array that receives as parameters an array of integers and the array size. Use a for statements to print all the elements in the array. (Use pointers to pass an array of integers as parameter). d) Create a function selection_sort that receives as parameters an array of integers and the array size and order the array element in descending order. Implement Selection Sort algorithm. It should be Selection Sort, not Bubble Sort, not Quick Sort, etc. e) Create a RECURSIVE function that calculate and returns the factorial of a number. The function receives the number (integer number) as parameter f) Create a file main_part1.cpp. Copy the following main function in your class, int main() {
int a [10] = {3, 5, 6, 8, 12, 13, 16, 17, 18, 20};
int b [6]= {18, 16, 19, 3 ,14, 6};
int c [5]= {5, 2, 4, 3, 1};
Homework h; // testing initialize_array
h.print_array(a, 10); // print: 3, 5, 6, 8, 12, 13, 16, 17, 18, 20
h.initialize_array(a, 10);
h.print_array(a, 10); // print: 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 // testing initialize_array
h.print_array(b, 6); // print: 18, 16, 19, 3 ,14, 6
h.selection_sort (b, 6);
h.print_array(b, 6); // print: 19, 18, 16, 14, 6, 3 // testing factorial
cout <<"Factorial of 5 = << h.factorial (5) < c[1] = h.factorial (c[2]); h.print_array(c, 5); // print: 120, 24, 4, 3, 1 return 0; }
Step 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