Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following formula gives the distance between two points, (x,y) and (x,y) in the Cartesian plane: sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} ( Given

The following formula gives the distance between two points,(x,y)and(x,y)in the Cartesian plane:

\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

(

Given the center and a point on the circle, you can use this formula to find the radius of the circle.

Instructions

Write a program that prompts the user to enter the center and a point on the circle. The program should then output the circle's radius, diameter, circumference, and area. Your program must have at least the following functions:

  • distance: This function takes as its parameters four numbers that represent two points in the plane and returns the distance between them.
  • radius: This function takes as its parameters four numbers that represent the center and a point on the circle, calls the functiondistanceto find the radius of the circle, and returns the circle's radius.
  • circumference: This function takes as its parameter a number that represents the radius of the circle and returns the circle's circumference. (Ifris the radius, the circumference is2r.)
  • area: This function takes as its parameter a number that represents the radius of the circle and returns the circle's area. (Ifris the radius, the area isr.) Assume that = 3.1416.

Format your output withsetprecision(2)to ensure the proper number of decimals for testing!

Answer is given with code and sample output.

Explanation:

Code :

#include

#include

#include

using namespace std;

const float PI = 3.1416;

float distance(float x1,float x2,float y1,float y2){

float Distance;

//condition of points i.e. either of them is center or boundary points.

if((x1 != 0 || y1 !=0) && (x2 != 0 || y2 != 0))

Distance = sqrt(pow((x2-x1),2)+pow((y2-y1),2));

else

Distance = 2*sqrt(pow((x2-x1),2)+pow((y2-y1),2));

return Distance;

}

float radius(float x1,float x2,float y1,float y2){

float Radius;

//condition of points i.e. either of them is center or boundary points.

if((x1 == 0 && y1 ==0) || (x2 == 0 && y2 == 0)){

Radius = sqrt(pow((x2-x1),2)+pow((y2-y1),2));

}

else

Radius = sqrt(pow((x2-x1),2)+pow((y2-y1),2))/2;

return Radius;

}

float circumference(float R){

return 2*PI*R;

}

float area(float R){

return PI*pow(R,2);

}

int main() {

//variable declaration..

float x1,x2,y1,y2,Distance,Radius,Circuference,Area;

//Taking user input...

cout<<" Enter 1st point x-coordinate : ";

cin >> x1;

cout<<" Enter 1st point y-coordinate : ";

cin >> y1;

cout<<" Enter 2nd point x-coordinate : ";

cin >> x2;

cout<<" Enter 2nd point y-coordinate : ";

cin >> y2;

Radius = radius(x1,x2,y1,y2);

cout<

cout<

cout<

cout<

return 0;

}

  • Code PatternIncomplete

Check for function usedistance

Description

Searched your code for a specific pattern:

double.+distance\(.+

  • Check for function useradius

Description

Searched your code for a specific pattern:

double.+radius\(.+

  • Check for function usecircumference

Description

Searched your code for a specific pattern:

double.+circumference\(

  • Check for function usearea

Description

Searched your code for a specific pattern:

double.+area\(

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions