Question

In: Computer Science

Write a C program to store the parameters of a circle on a 2D plane: the...

Write a C program to store the parameters of a circle on a 2D plane: the x and y coordinates of the center point and r, the radius. All three parameters are real (floating point) numbers.

-Define a type to store the parameters of a circle. Write a function that receives the parameters of two circles as function parameters, and returns whether the two circles overlap or not. (Two circles overlap if the distance between their center points - computed by the Pythagorean theorem - is less than the sum of their radius.)

-Write a function that asks the user to enter the parameters of a circle, creates the circle, and returns it.

-Expand the type definition and the functions to a program that reads the data of two circles, decides if they overlap, and displays a message accordingly.

Solutions

Expert Solution

Thanks for the question.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks!
===========================================================================

#include<stdio.h>
#include<math.h>
//-Define a type to store the parameters of a circle.
typedef struct circle{
   double x;
   double y;
   double radius;
} Circle;

//-Write a function that asks the user to enter the
//parameters of a circle, creates the circle, and
// returns it.
Circle getCircle(){
  
   Circle c;
   printf("Enter the x coordinate of the center:")   ;
   scanf("%lf", &c.x);
   printf("Enter the y coordinate of the center:")   ;
   scanf("%lf", &c.y);
   printf("Enter the radius of the circle:")   ;
   scanf("%lf", &c.radius);
  
   return c;
}


//Write a function that receives the parameters of
//two circles as function parameters, and returns
//whether the two circles overlap or not.
int overlaps(Circle c1, Circle c2){
   double centerDistance, radiusSum;
   centerDistance = sqrt(pow(c1.x-c2.x,2) + pow(c1.y-c2.y,2));
   radiusSum = c1.radius+c2.radius;
   if(centerDistance<=radiusSum){
       return 1;
   }else{
       return 0;
   }
}


int main(){
  
   Circle c1,c2;
   printf("Enter details for Circle #1\n");
   c1 = getCircle();
   printf("\nEnter details for Circle #2\n");
   c2 = getCircle();
  
   if(overlaps(c1,c2)==1){
       printf("\nThe circles overlap.\n");
   }else{
       printf("\nThe circles DONOT overlap.\n");
   }


   return 0;
}


Related Solutions

Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
Write a program in C that computes the area of a circle (Area = pi *...
Write a program in C that computes the area of a circle (Area = pi * r2) and the volume of a sphere (Volume = 4/3 * pi * r3). Both formulas use r which is the radius. Declare a float variable pi = 3.14159. Get the value of r from the keyboard and store it in a float variable. Display both the area of the circle and the volume of the sphere.
Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
write parametric equations in 2D for a particle moving in a clockwise motion along a circle...
write parametric equations in 2D for a particle moving in a clockwise motion along a circle radius 2 such that at t=0 , the particle is at point (-2,0) Please I need the answer with steps and explanation.. Clear handwriting please.. Thank you
3. Write a C++ program that takes in the name of a store, and the following...
3. Write a C++ program that takes in the name of a store, and the following details for 4 employees working at the store; their first name, last name, number of hours they worked that week and how much they are paid per hour. Your program should output the name of the store, along with each employee's full name and how much they earned that week in the manner below. Monetary values should be format to 2 decimal places. Also...
1. (50 pts) Write a C program that generates a 2D array-of-double and finds the indexes...
1. (50 pts) Write a C program that generates a 2D array-of-double and finds the indexes of the largest value stored in the 2D array. Specific requirements: (1) Your main function defines the 2D array a. You will need to prompt the user to specify the size of the 2D array b. You will need to prompt the user to put in numbers to initialize the array (2) Write a function to display the array that is visualized as rows...
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Write a simple C program to generate a chart of circle properties. Output chart “iteration” is...
Write a simple C program to generate a chart of circle properties. Output chart “iteration” is to be specified by user input. Your chart will include the radius, diameter, circumference, and Area values in a single table, and radius values will range from 0 to 50, floating point values, with three-decimal-place precision. Table should have all column entries right-justified and each column will have a heading above the entries. For example, assuming user enters a incrementation value of 5, the...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size 3x3 as private member.        There should be two public methods within the class definition namely: void setMatrixValue(int i, int j); that should set m[i][j] with user defined values int getMatrixValue(int i, int j); that should return m[i][j] Make a global function named ‘CrossProduct(Matrix m1, Matrix m2)’ that should compute the marix multiplication
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT