1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
double radiusFn(double, double, double, double); //4 double values, one for each point. All points are needed for the calculation of distance in this function.
double diameterFn(double); //Only uses one double value - the radius. Both functions below use the same value.
double circumferenceFn(double);
double areaFn(double);
int main()
{
cout << "---------------------------------------------------------" << endl;
cout << " Circle Statistics Program" << endl;
cout << " David Gambino" << endl;
cout << "---------------------------------------------------------" << endl;
ifstream fin;
fin.open("assignment3data.txt");
while (fin)
{
int x1, x2, y1, y2;
fin >> x1 >> y1 >> x2 >> y2;
double radius = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2)); //Distance formula.
double points, diameter, circumference, area;
if (fin)
{
diameter = diameterFn(radius); //Variable diameter is assigned the value outputted by diameterFn using the value of radius which was just determined.
circumference = circumferenceFn(radius); //Variable circumference is assigned the value outputted by circumferenceFn using the value of radius.
area = areaFn(radius); //Variable area is assigned the value outputted by areaFn using the value of radius.
cout << "Statistics for points (" << x1 << ',' << y1 << ") and (" << x2 << ',' << y2 << ')' << endl; //implementations proceeding function main.
cout << fixed << "The radius is: " << setprecision(2) << radius << endl;
cout << "The diameter is: " << diameter << endl;
cout << "The circumference is: " << circumference << endl;
cout << "The area is: " << area << endl << endl;
}
}
fin.close();
}
double diameterFn(double radius) //Implements calculations to find the diameter of the circle which is simply the radius multiplied by 2.
{
double diameter = radius * 2; //Diameter formula.
return diameter;
}
double circumferenceFn(double radius) //Implements calculations to find the circumference of the circle.
{
double circumference = 2 * 3.1416*radius; //Circumference formula. 3.1416 is pi to the forth decimal place.
return circumference;
}
double areaFn(double radius) //Implements calculations to find the circumference of the circle.
{
double area = 3.1416*pow(radius, 2); //Area formula.
return area;
}
|