Question: Declare a structure to represent a circle. Each circle stores information about the center and the radius. Center is represented with x and y coordinates.

 Declare a structure to represent a circle. Each circle stores information

Declare a structure to represent a circle. Each circle stores information about the center and the radius. Center is represented with x and y coordinates. Both center and radius uses doubles. Allocate an array of 50 circle pointers and dynamically allocate memory to store a circle pointed by each array entry. Randomly generate circles using the following function.

double rand_float(double a,double b) {

return ((double)rand()/RAND_MAX)*(b-a)+a;

}

We want all the circles to fit an area of 1000x1000. So, x and y coordinates are randomly selected from (100,900) and radius is randomly selected from (0,100) using above function. After you insert the random circles, find the circle with the largest area and print the information for this circle. You can use 3.14 for P I and area of a circle is given as P I radius radius. Dont forget to free the pointers when you are done with the array. Use valgrind to find any memory leaks. Sample execution is given below

Circle with largest area (31380.837301) has center (774.922941,897.436445) and radius 99.969481

Declare a structure to represent a circle. Each circle stores information about the center and the radius. Center is represented with x and y coordinates. Both center and radius uses doubles. Allocate an array of 50 circle pointers and dynamically allocate memory to store a circle pointed by each array entry. Random generate circles using the following function. double rand_float (double a, double b) {return ((double)rand()/RAND_MAX) * (b-a) +a;} We want all the circles to fit an area of 1000 times 1000. So, x and y coordinates are randomly selected from (100, 900) and radius is randomly selected from (0, 100) using above function. After you insert the random circles, find the circle with the largest area and print the information for this circle. You can use 3.14 for PI and area of a circle is given as PI * radius * radius. Don't forget to free the pointers when you are done with the array. Use valgrind to find any memory leaks. Sample execution is given below Circle with largest area (31380.837301) has center (774.922941, 897.436445) and radius 99.969481 Submit your program electronically using the blackboard system

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!