Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

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

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

Step: 3

blur-text-image

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

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions