标题:不明白的错误,帮解决下,谢谢
只看楼主
winnerflyer
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-3-14
 问题点数:0 回复次数:2 
不明白的错误,帮解决下,谢谢
是一个求三角形面积的

大家看下:

//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 时出错.
搜索更多相关主题的帖子: private include public double called 
2008-05-09 13:19
winnerflyer
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-3-14
得分:0 
没人回复 摸索的路好难啊.....我又把东西改了下 能运行了
//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;
            //setA(1,0); setB(0,1); setC(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()
   {
       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);
    cout<<endl<<endl;
    cout<<"ob1::show:"<<endl;
    ob1.show();
    cout<<endl<<endl;
    cout<<"ob2::show:"<<endl;
    ob2.show();
    
return 0;
}
2008-05-09 17:59
忘记喧嚣
Rank: 1
等 级:新手上路
帖 子:146
专家分:0
注 册:2007-10-7
得分:0 
}

   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;

};


其实就是这里少了一个  }
好象你已经改过来了
2008-05-10 00:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-213335-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036562 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved