Please use c++ and answer accurately as told in instructions! Write the function
ID: 3907402 • Letter: P
Question
Please use c++ and answer accurately as told in instructions!
Write the function reverse (double* a, int a.size ()) described in Problem P7.7. . Write a program that reads in a list of numbers contiguously and saves them in a dynamically allocated array. Do NOT use vectors in this problem (see the explanation of how to handle it in the problem 2). Let double* a be the pointer containing its size. Apply the function reverse to the array located at a to reverse the order of its elements. Then display the numbers using the delimiter ", ". When displaying the numbers of the reversed array use a pointer variable, and not an integer index, to traverse the array elements. » Implement a loop in which the above actions are repeated until the user requests to quit. . Assume that the the user's input is always valid. ·Assume that the character after the last number in the input list is the newline character and that there is exactly one space between the numbers in the list. with the array and int a.size be the variableExplanation / Answer
#include <iostream>
void swap(double* a, double* b)
{
double t = *a;
*a = *b;
*b = t;
}
void reverse(double a[], int a_size)
{
double* p1 = a;
double* p2 = a + a_size-1;
while (p1 < p2) {
swap(p1,p2);
p1++;
p2--;
}
}
void printArray(double* a, int a_size)
{
double* upperEnd = a + a_size;
for (double *p = a; p < upperEnd; p++)
std::cout << *p << " ";
std::cout << " ";
}
int main()
{
double a[] = {
0.1,-1.2,2.3,-3.4,4.5,-5.6,6.7,-7.8,8.9,-9.0
};
reverse(a, 10);
printArray(a, 10);
system("Pause");
}