It compiles fine using g++ one a True Unix 64 machine and on Visual C++. Any help you can give me would be appreciated, thanks
Code: Select all
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
using namespace std;
int main()
{
cout << showpoint << setprecision(4);
pair<double,double> point[3],midpoint[2],center;
double slope[2];
double radius;
double a,b,c;
int index = 0, index2 = 0;
string input;
getline( cin, input, '\n' );
do
{
index = 0; index2 = 0;
for( int i = 0; i < 3; i++ )
{
while( input[index2] != ' ' )
index2++;
point[i].first = atof((input.substr(index,index2)).c_str());
index = index2 + 1;
index2++;
while( input[index2] != ' ' && input.length() != index2 )
index2++;
point[i].second = atof((input.substr(index,index2)).c_str());
index = index2 + 1;
index2++;
}
if( (point[0].second - point[1].second) == 0 )
{
slope[0] = ((point[0].first - point[2].first)/(point[2].second - point[0].second));
midpoint[0].first = (point[0].first + point[2].first)/2;
midpoint[0].first = (point[0].second + point[2].second)/2;
slope[1] = ((point[1].first - point[2].first)/(point[2].second - point[1].second));
midpoint[1].first = (point[1].first + point[2].first)/2;
midpoint[1].second = (point[1].second + point[2].second)/2;
}
else
{
slope[0] = ((point[0].first - point[1].first)/(point[1].second - point[0].second));
midpoint[0].first = (point[0].first + point[1].first)/2;
midpoint[0].second = (point[0].second + point[1].second)/2;
if( (point[0].second - point[2].second) == 0 )
{
slope[1] = ((point[1].first - point[2].first)/(point[2].second - point[1].second));
midpoint[1].first = (point[1].first + point[2].first)/2;
midpoint[1].second = (point[1].second + point[2].second)/2;
}
else
{
slope[1] = ((point[0].first - point[2].first)/(point[2].second - point[0].second));
midpoint[1].first = (point[0].first + point[2].first)/2;
midpoint[1].second = (point[0].second + point[2].second)/2;
}
}
center.first = (slope[0]*midpoint[0].first - midpoint[0].second - slope[1]*midpoint[1].first + midpoint[1].second)/(slope[0] - slope[1]);
center.second = slope[0]*(center.first - midpoint[0].first) + midpoint[0].second;
radius = sqrt( pow(center.first - point[0].first, 2 ) + pow(center.second - point[0].second, 2 ) );
if( center.first < 0 )
{
if( center.second < 0 )
{
cout << "(x + " << -1 * center.first << ")^2 + (y + " << -1 * center.second << ")^2 = " << radius << "^2" << endl;
}
else
{
cout << "(x + " << -1 * center.first << ")^2 + (y - " << center.second << ")^2 = " << radius << "^2" << endl;
}
}
else
{
if( center.second < 0 )
{
cout << "(x - " << center.first << ")^2 + (y + " << -1 * center.second << ")^2 = " << radius << "^2" << endl;
}
else
{
cout << "(x - " << center.first << ")^2 + (y - " << center.second << ")^2 = " << radius << "^2" << endl;
}
}
a = 2*center.first;
b = 2*center.second;
c = pow(center.first, 2) + pow(center.second, 2) - pow( radius, 2 );
cout << "x^2 + y^2 ";
if( a < 0 )
{
if( b < 0 )
{
if( c < 0 )
cout << "+ " << -1 * a << "x + " << -1 * b << "y - " << -1 * c << " = 0";
else
cout << "+ " << -1 * a << "x + " << -1 * b << "y + " << c << " = 0";
}
else
{
if( c < 0 )
cout << "+ " << -1 * a << "x - " << b << "y - " << -1 * c << " = 0";
else
cout << "+ " << -1 * a << "x - " << b << "y + " << c << " = 0";
}
}
else
{
if( b < 0 )
{
if( c < 0 )
cout << "- " << a << "x + " << -1 * b << "y - " << -1 * c << " = 0";
else
cout << "- " << a << "x + " << -1 * b << "y + " << c << " = 0";
}
else
{
if( c < 0 )
cout << "- " << a << "x - " << b << "y - " << -1 * c << " = 0";
else
cout << "- " << a << "x - " << b << "y + " << c << " = 0";
}
}
cout << endl << endl;
}while(getline(cin, input, '\n' ));
return 0;
}