Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Name the file dynamic.cpp Write a program that declares an array of integers called radii that holds 10 integers representing the radii of 10 different

Name the file dynamic.cpp

Write a program that declares an array of integers called radii that holds 10 integers representing the radii of 10 different circles using pointers. The main function will create the array of radii and pass it to the function calcArea. calcArea will dynamically create a new array to store areas of circles and return a pointer to the new array to main function. main will then pass the pointers of the two arrays to printArrays to display both.

In your main function print the values to the screen in two ways:

1. on the same line separated by a comma (dont display the comma after the last element)

2. on different lines

Coding details:

1. main function:

- Declare an array of 10 ints called radii and initialize it with values multiples of 2.

- Define a pointer of type double to store the returned pointer.

- Call the function calcArea passing a pointer to radii array and the size. The returned pointer will be stored in the double pointer you defined.

- Call the function printArrays.

2. Function calcArea: accepts as its arguments a pointer to the array radii and the size.

The function will return a pointer of type double.

The prototype of the function: double * calcArea(int* , int );

Coded as follows:

- Dynamically allocate an array of doubles using the received size.

- Calculate the areas of the circles using radii array and store them in the created array.

- Return the pointer of the new array to main function.

3. Function printArrays will accept the pointers of the radii and areas array and prints their values on the screen as follows:

r1 a1

r2 a2

r3 a3

...

and so on.

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_2

Step: 3

blur-text-image_3

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

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions