136k views
2 votes
4. Write a program that has a declaration in main() to store the following numbers in an array named prices: 6.51, 7.52, 8.63, 9.45, 5.52 and 10.06. Include a function call to showme() that accepts prices in a parameter named prices and then displays the numbers by using the pointer notation *(prices + i). Also display the sum of the array using a pointer notation such as (*nPt++). Submit .cpp file and sample run. please assist and show me how to sum the array as well using c++

User Hakank
by
7.8k points

1 Answer

2 votes

Final answer:

To solve this problem, declare the array in the main() function and pass it to the showme() function. Use pointer notation to access and display the elements. Calculate the sum of the array using pointer notation.

Step-by-step explanation:

To solve this problem, first, declare an array named prices in the main() function and initialize it with the given numbers. Then, pass the prices array to a function called showme(). Inside the showme() function, use a for loop to access each element of the array and display it using the pointer notation: *(prices + i). To calculate the sum of the array, initialize a variable sum to 0 before the loop. Within the loop, use the pointer notation (*nPt++) to access each element and add it to the sum variable.

User Torez
by
7.9k points