You will write the four functions described below. main function, to demonstrate
ID: 3594034 • Letter: Y
Question
You will write the four functions described below. main function, to demonstrate their correctness Then you will call them from the 1. isSorted: takes an array of integers and its size as arguments. It should return true if the elements of the array are already in ascending order, and false if they are not. Do not use square brackets anywhere in the function, not even the parameter list (use pointers instead). 2· chain: The following function uses reference parameters. Rewrite the function so it uses pointers instead of reference parameters. When you test this function from the main program, demonstrate that it sets the values of the variables passed into it. double chain (int totallnches, int &feet;, int&inches;) feet totallnches/12 return feet 3.49+inches 30; 3. grow: takes an array of integers and the array's size as arguments. It should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array so that each element from the first array occurs twice consecutively in the second array. For example, grow(x,3) where x is 45,6 should return (4.45,5,6,6. The function should return a pointer to the new array 4. subArray: takes an int array, a start index and a length as arguments. It creates a new array that is a copy of the elements from the original array starting at the start index, and has length equal to the length argument. For example, subArray(aa,5,4) would return a new array containing only the elements aa5], aa[6], aa[7), and aa[8]. You must define subArray as follows: Add the code for the duplicateArray function from the lecture slides for chapter 9 to your program. Add the code for the subArray function given below to your program. Fill in the blanks with expressions so that the function subArray behaves as described above. int "subArray (int "array, int start, int length) return result: DO NOT alter duplicateArray, DO NOT alter subArray as defined above. Output: Test these four functions using the main function as a driver. The driver should pass constant test data as arguments to the functions. Select appropriate test data for each function and then call that function using the test data. For each function, you should output the following: a label indicating which function is being tested, the testExplanation / Answer
Please find my answer for frist 2 questions.
Please repost others in separate post
Q1.
bool isSorted(int *a, int n) {
if(n <= 1)
return true;
for(int i=1; i<n; i++){
if(*(a+i-1) > *(a+i))
return false;
}
return true;
}
Q2.
double chain(int totalInches, int *feet, int *inches) {
*feet = totalInches/12;
*inches = totalInches%12;
return (*feet)*3.49 + (*inches)*0.30;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.