Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Computer Performance Engineering 10th European Workshop Epew 2013 Venice Italy September 17 2013 Proceedings

Authors: Maria Simonetta Balsamo ,William Knottenbelt ,Andrea Marin

2013 Edition

3642407242, 978-3642407246

Students also viewed these Programming questions

Question

=+How sensitive is Pats decision?

Answered: 1 week ago