holy error messages batman
well everyone heres the code and I gotta tell yah this one has got me stumped
Code:
#include <iostream>
#include <string>
using namespace std;
class two
{
private: float x, y;
public:
void read()
{
cout<<"Enter the x cooridnate: "; cin>>x; //enter the value for the x coord
cout<<"Enter the y coordinate: "; cin>>y; //enter the value for the y coord
}
void show()
{
cout<<"the x and y of point a are("<<x<<" , "<<y<<")"<<endl; //shows the value of the x and y coord
}
friend void show(two p)
{
cout<<"the x and y of point b are("<<p.x<<" , "<<p.y<<")"<<endl;
}
friend float distance(two p)
{
float d=((0-p.x)(0-p.x)) + (0-p.y)(0-p.y));
cout<<sqrt(d);
}
};
void main()
{
two a, b;//declares two objects a and b
a.read();//read in x and y values for object a
b.read();//read in x and y values for object b
a.show();//show x and y values for object a
show(b);//show x and y values for object b
cout<<"The distance from point(0,0) to point a is" <<distance(b);
}
well according to the info I got on friend functions this stuff should work man but I keep getting this crazy error message that says internal compiler error. Now the one question that I have what exactly am I missing here
Here is something that will actually compile.
Code:
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
class two
{
private: float x, y;
public:
void read()
{
cout<<"Enter the x cooridnate: "; cin>>x;
cout<<"Enter the y coordinate: "; cin>>y;
}
void show()
{
cout<<"the x and y of point a are("<<x<<" , "<<y<<")"<<endl;
}
void show(two p)
{
cout<<"the x and y of point b are("<<p.x<<" , "<<p.y<<")"<<endl;
}
float distance(two p)
{
float d=((0-p.x)*(0-p.x) + (0-p.y)*(0-p.y)); //add * between )(
return sqrt(d); //chang cout to return
}
};
int main()
{
two a, b; //why define two objects but output one ?
a.read();
b.read();
a.show();
b.show(b);
cout<<"The distance from point(0,0) to point a is " ;
cout<<a.distance(a);
cin.ignore();
cin.get();
return 0;
}