This is from my textbook C++ Programming: From Problem Analysis to Program Desig
ID: 3627333 • Letter: T
Question
This is from my textbook C++ Programming: From Problem Analysis to Program Design (5th) 9780538798099
chapter 6 Programming Exercise 8 pg. 359
By Malik
I am needing a great algorithum for this problem and I don't understand how to do it. What would be the algorithm to it. Here is the problem!
The following formula gives the distance between 2 points x1,x2 and y1,y2 in the cartesian plane:
sqrt(pow(x1-x2,2) - pow(y1-y2,2))
given the center and a point on the circle, you can use this formula to find the radius of the circle. Write a program that prompts user to enter the center a point on the circle. The program should then output the circle radius, diameter, circumference and area. your program must have at least the following function:
a)distance:this function takes as its parameters four numbers that represent tow points in the plane and returns the distance between them.
b)radius:this function takes as its parameters four numbers that represent the center and a point on the circle, calls the function distance to find the radius of the circle, and return the circle radius.
c)circumference: this function takes as its parameter a number that represents the radius of the circle and returns the circle circumference.
d)area: this function takes as its parameter a number that represents the radius of the circle and return the circle area
assume the pi = 3.1416
Explanation / Answer
#include <iostream>
#include <math.h>
using namespace std;
double distance (int p, int q, int r, int s);
double radius (int p, int q, int r, int s);
double circumference (double r1);
double area (double r1);
int main ()
{ //start main
int x1, x2, y1, y2;
double r,d,c,a;
cout<<"Enter the center of circle"<<endl;
cin>>x1>>y1;
cout<<"Enter point on circle"<<endl;
cin>>x2>>y2;
d=distance (x1,y1,x2,y2); //distance function call
r=radius (x1,y1,x2,y2); //radius function call
c=circumference (r); //circumference function call
a=area (r); //area function call
//outputing values
cout<<"distance between points"<<d<<endl;
cout<<"radius of circle"<<r<<endl;
cout<<"circumference of circle"<<c<<endl;
cout<<"area of circle"<<a<<endl;
return 0;
} //end main
//function definitions
double distance (int p, int q, int r, int s)
{ //start function
double d1;
d1=sqrt (pow (r-p, 2) + pow(s-q,2));
return d1;
} //end distance
double radius (int p, int q, int r, int s)
{ //start function
double r1;
r1=distance(p,q,r,s);
return r1;
} //end radius
double circumference (double r1)
{ //start function
double c1;
c1=2*3.1416*r1;
return c1;
} //end circumference
double area (double r1)
{ //start function
double a1;
a1=3.1416*r1*r1;
return a1;
} //end area
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.