/* Fabrice Toussaint
section N938
Feburary 1, 2011
Purspose of program is to locate centroid and find distance between all three points and centroid
*/
#include <iostream>// for cout and cin
#include <cmath> // for sqrt () and pow (x,y)
using namespace std;
int main ()
{
float distance1; // assign number of distance 1
float distance2; // assign number of distance 2
float distance3; // assign number of distance 3
float centroidX; // x point of centroid
float centroidY; // y point of centroid
float xa; // point xa
float xb; // point xb
float xc; // point xc
float ya; // point ya
float yb; // point yb
float yc; // point yc
cout << " Triangle Centroid Calculator!" << endl; // welcome user
cout << endl;
cout << "Enter point one on your triangle: " << endl; // prompt user to enter two numbers
cin >> xa >> ya; // store numbers into variable xa and ya
cout << "Enter point two on your triangle: " << endl; // prompt user to enter two numbers for second point
cin >> xb >> yb; // store numbers into variable xb and yb
cout << "Enter point three on your triangle: " << endl; // prompt user to enter two numbers for third point
cin >> xc >> yc; // store number into variable xb and yb
cout << endl;
centroidX = (xa + xb + xc)/3; // centroid equation for point X
centroidY = (ya + yb + yc)/3; // centroid equation for point Y
cout << "The centroid is located at (" << centroidX << ',' << centroidY << ") " << endl; // distplay centroid coordinate to user
cout << endl;
distance1 = sqrt((pow((centroidX - xa), 2) + pow((centroidY - ya), 2))); // distance 1 from point 1 to centroid
distance2 = sqrt((pow((centroidX - xb), 2) + pow((centroidY - yb), 2))); // distance 2 from point 2 to centroid
distance3 = sqrt((pow((centroidX - xc), 2) + pow((centroidY - yc), 2))); // distance 3 from point 3 to centroid
cout << "Distance from centroid to point 1: " << distance1 << endl; // prompt user of the distance1
cout << "Distance from centroid to point 2: " << distance2 << endl; // prompt user of the distance2
cout << "Distance from centroid to point 3: " << distance3 << endl; // prompt user of the distance3
cout << endl;
cout<< "Thank you for your business." << endl;
return 0;
}
im fairly new to coding, and i just finished writing up this code for a centroid calculator, and i was just curious to have more advance coders have a look at this and critique me on my style or suggest any better ways to getting to the end.
what could i do to shorten it??
what could i do to maybe make it more readable?( i had to leave comments on everysingle line for teacher)
im open so just let me know your opinions on one of my first programs.
thank you
-fabrice toussaint