Question: C ++ 1. Write down the missing code according to the comments. #include #include using namespace std; void fun1(int radius) { /* dynamic memory management

C ++

1. Write down the missing code according to the comments.

#include

#include

using namespace std;

void fun1(int radius)

{

/*

dynamic memory management

*/

double * dmptr;

double circumference;

/*

add the code below to:

- allocate a memory location for a double and nameless variable in heap and assign its address to the pointer

- assign 3.14 to the variable in heap via the pointer.

*/

/*

add the code below to:

- calculate the circumference of a circle. Its radius is from the parameter of this function and the value of pi is from the nameless variable in heap

*/

/*

print the area

*/

cout<<" circumference = "<< circumference <

delete dmptr;

}

void fun2(int n)

{

int sum = 0;

int *dmptr;

/* add the code below to:

allocate n memory locations for an integer and nameless array in heap via a pointer

*/

/* add the code below to:

inializate the array in heap

*/

for(int i=0; i

{

dmptr[i] = i * 2;

}

/*

calculate the sum of the elements of the array in heap

*/

/*

print the sum

*/

cout<<"sum="<

delete[] dmptr;

}

int main()

{

fun1(2);

fun2(5);

return 0;

}

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 Databases Questions!