Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C++ that asks the user to enter an array of size N and pass t

ID: 3692536 • Letter: W

Question

Write a program in C++ that asks the user to enter an array of size N and pass the array to a function named reverse_array that takes as its arguments an array of floating point values and an integer that tells how many floating point values are in the array. The function must reverse the order of the values in the array. The function should not return any value. Do not forget to write the main function as well. Display the original array and the reversed array in the main function. Please don't use any thing too complicated that I might not have covered in my class add Comments to Help me understand the program better, I have been having problems with it and I want to make sure I fully understand it. Thank You!

Explanation / Answer

Hi below i have written the code for your reference :) #include using namespace std; // struct isn't a return type /*struct*/ void reverse_array( float array[], int arraylength ) { for (int i = 0; i < (arraylength / 2); i++) { float temporary = array[i]; // temporary wasn't declared array[i] = array[(arraylength - 1) - i]; array[(arraylength - 1) - i] = temporary; } } int main() { int /*temporary,*/ arraylength; // unused variable temporary? //float array[50]; /* You need to dynamically allocate memory for the array, as its size is not know at compile time. */ cout > arraylength; float* array = new float[arraylength]; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote