不明白的错误,帮解决下,谢谢
是一个求三角形面积的大家看下:
//point.h
#include <iostream.h>
#include <math.h>
class point
{
public:
point()
{
X=Y=0;
}
point(double x,double y)
{
X=x;
Y=y;
cout<<"Cpoint::Cpoint is called"<<"\n";
}
double X;
double Y;
};
//tria.h
#include<iostream.h>
#include<math.h>
#include"point.h"
class Tria
{
private:
point A;
point B;
point C;
double a;double b;double c;double s;
public:
Tria()
{
A(1,0); B(0,1); C(0,0);
Distance();
cout<<"Tria::Tria() is called"<<endl;
}
Tria(double a,double b,double c,double d,double e,double f)
{
A(a,b); B(c,d);C(d,f);
if(ifTria(A,B,C)==0)
{
cout<<"the value is not availeble"<<endl;
A(1,0); B(0,1)l; C(0,0);
}
Distance();
cout<<"Tria::Tria(double) is called"<<endl;
}
double distance(const point &a, const point &b) //求两点间的距离
{
return sqrt( (a.X-b.X)*(a.X-b.X)+(a.Y-b.Y)*(a.Y-b.Y) );
}
void Distance() //求出边长和周长
{
c=distance(A,B);
b=distance(A,C);
a=distance(B,C);
}
int ifTria(const point &a, const point &b,const point &c) //判断三点是否构成三角形,并返回判断结果
{
if( (a.Y-b.Y)*(b.X-c.X)==(a.X-b.X)*(b.Y-c.Y) )
return 0;
else return 1;
}
int setA(double x,double y) // 给点赋值
{
point t;
t.X=x; t.Y=y;
if( ifTria(t,B,C)==1)
{ A=t;
Distance();
return 1;
}
else return 0;
}
int setB(double x,double y) // 给点赋值
{
point t;
t.X=x; t.Y=y;
if( ifTria(A,t,C)==1)
{ B=t;
Distance();
return 1;
}
else return 0;
}
int setC(double x,double y) // 给点赋值
{
point t;
t.X=x; t.Y=y;
if( ifTria(A,B,t)==1)
{ C=t;
Distance();
return 1;
}
else return 0;
}
double Area() //求此三角形的面积
{
double temp,p;
p=s/2;
temp=p*(p-a)*(p-b)*(p-c);
return ( sqrt(temp));
}
void show() const
{
cout<<"A("<<A.x<<"."<<A.Y<<")"<<endl;
cout<<"B("<<B.x<<"."<<B.Y<<")"<<endl;
cout<<"C("<<C.x<<"."<<C.Y<<")"<<endl;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
cout<<"the area is "<<Area<<endl;
};
// Triamian
#include <iostream.h>
#include "tria.h"
int main()
{
Tria ob1;
Tria ob2(1,3,5,7,9,10);
ob1.show();
ob2.show();
return 0;
}
编译出现一下错误:
[color=Lime]error C2059: syntax error : 'PCH creation point'
triamain0.cpp(8) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
triamain0.cpp(17) : fatal error C1004: unexpected end of file found[/color]执行 cl.exe 时出错.