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 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 systemStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started