Question: Main program and forward declarations (10 points) You are required to write forward declarations for all the functions in this as- signment. Your C++

Main program and forward declarations (10 points) You are required to writeforward declarations for all the functions in this as- signment. Your C++file should look like this. #include #include // include additional system header

Main program and forward declarations (10 points) You are required to write forward declarations for all the functions in this as- signment. Your C++ file should look like this. #include #include // include additional system header files if you need them using namespace std; // *** FORWARD DECLARATIONS OF ALL FUNCTIONS IN ASSIGNMENT *** int main() { } swap_main(); math_main(); ptr_neg_main(); Paths_ptr_main(); return 0; // *** FUNCTION BODIES OF ALL FUNCTIONS IN ASSIGNMENT *** The questions below contain some math, but not complicated mathematical calculations. Q3 Pointer & negative indices (20 points) In many situations, it is more convenient if the array indices run from i = -n,..., n. This can be useful in physics and engineering, if things are centered on i = 0. 1. Pointers can achieve this functionality. int n ... double arr [2*n+1]; double p&a[n]%; // positive number // p points to midpoint of array 2. We allocate an array and declare a pointer to point to its midpoint. 3. The pointer p points to the midpoint of the array arr. 4. The valid indices of p are p[-n] through p[n]. Write a function void ptr neg main() as follows. void ptr_neg_main() { } int n = 0; // prompt user to enter positive integer and read value from console // test if n > 0 else print error message double a [3]; // prompt user to enter data and read values from console. double arr [2*n+1]; double *p = &arr[n]; set_ptr_neg(p, n, a);B print_ptr_neg (p, n); cout Note the following: 1. To release the dynamic memory correctly, use brr (not p), with the correct form of operator delete. 2. This is because the pointer being deleted must point to the start of the allocated memory block. 3. The functions are called twice, with different values for the parameter n. 4. However, the pointer p is the same in all the function calls. set_ptr neg 1. The function return type is void. 2. The pointer p is not const. 3. The input n is passed by value. 4. The input a is passed as a pointer to const double. 5. Write a loop going from i = n to i = n. 6. Set the value of p[i] to a[0] + a[1]*i + a[2]*i*i (quadratic). print ptr neg 1. The function return type is void. 2. The input p is passed as a pointer to const double. 3. The input n is passed by value. 4. Print the values of p[i] all on one line (-n i n), separated by blank spaces.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!