- noncompiling (-25) - no documentation (-5) - Incorrect Output (-3 for each pie
ID: 3909239 • Letter: #
Question
- noncompiling (-25)
- no documentation (-5)
- Incorrect Output (-3 for each piece of output that is wrong, up to -12)
- Not having a constant for PI (-2)
- Not being clear on how to enter the X, Y coordinates for each of the two points (-2)
- Not having 4 functions (radius, circumference, area, distance) (-2.5 for each one missing)
- Not using setprecision for output (can be either 2 or 3 places, just must be there) (-1)
- distance and radius take in 4 parameters, circumference and area take in the radius only (-2 if anything different. just -2, not -2 for each one)
- Distance should never be called from main. Only radius, area, and circumference (-4 if distance is in main. -2 if radius has anything other than a call to distance in it and a return statement of course).
- Must have a main function that tests the functions and outputs the results neatly formatted. Part of the output is diameter, but that’s not a required function. Main should only either get the points, then call the functions, or simply call all functions. No daisy chaining functions permitted (-4 if so)
- Any Call by Reference Parameters in this one (-3) unless you use a getInput function to read in the points from the circle
- No global variables other than constants (PI) allowed (-2)
- Any other extraneous or odd coding behaviors, inefficient code, noted and take off up to 5 points.
Explanation / Answer
ScreenShot
--------------------------------------------------------
Program
/* This program to calculate radius diameter circumference and area of a circle
inputs are the cen point(x1,y1) of the circle and any one point in the circle(x2,y2)
distance betwee this points generate radius(sqrt((x2-x1)^2+(y2-y1)^2)
2*radius generate diameter
2Pi*r generate circumference
Pi*r^2 generate area*/
//Header files for I/O and setprecision of float numbers
#include<iostream>
#include<iomanip>
using namespace std;
//Global variable
double Pi =3.1416;
//Function prototypes
double distance(double x1, double y1, double x2, double y2);
double Radius(double x1, double y1, double x2, double y2);
double Circumference(double rad);
double Area(double rad);
//Main method to test all functions and display output
int main()
{
//Variable to take user input
int x1, y1, x2, y2;
//User prompt
cout << "Please enter circle's cenr point(x1 y1):";
cin >> x1 >> y1;
cout << "Please enter circle's point(x2 y2):";
cin >> x2 >> y2;
//Call radius function to get radius
double radius = Radius(x1, y1, x2, y2);
//Call circumference function to get radius
double circumference=Circumference(radius);
//Call area function to get radius
double area = Area(radius);
//Calculate diameter
double diameter = 2*radius;
//Display all values with precision of 2 decimal places
cout << fixed << setprecision(2) << "Radius Of the circle=" << radius << endl;
cout << fixed << setprecision(2) << "Diameter Of the circle=" << diameter << endl;
cout << fixed << setprecision(2) << "Circumference Of the circle=" <<circumference << endl;
cout << fixed << setprecision(2) << "Area Of the circle=" << area << endl;
return 0;
}
//Distance calculating function implementation
double distance(double x1, double y1, double x2, double y2) {
return sqrt((pow((x2 - x1), 2) + pow((y2 - y1), 2)));
}
//Radius calculating function implementation
double Radius(double x1, double y1, double x2, double y2) {
return distance(x1, y1, x2, y2);
}
//Circumference calculating function implementation
double Circumference(double rad) {
return 2*Pi *rad;
}
//Area calculating function implementation
double Area(double rad) {
return Pi * (pow(rad, 2));
}
-------------------------------------------
Output
Please enter circle's centr point(x1 y1):1 1
Please enter circle's point(x2 y2):5 9
Radius Of the circle=8.94
Diameter Of the circle=17.89
Circumference Of the circle=56.20
Area Of the circle=251.33
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.