标题:这是什么错误
只看楼主
weina
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-3-7
 问题点数:0 回复次数:6 
这是什么错误
fatal error C1004: unexpected end of file found

这错误怎么改啊
搜索更多相关主题的帖子: found fatal unexpected end 
2008-04-06 00:12
weina
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-3-7
得分:0 
各位大侠,帮忙改下,我是初学
#include <math.h>
#include<iostream>
using namespace std;
class Data1{
double  length,width ;
public:
    void PrintMenu();
    void setdata_1(double l,double w);
    double Girth_1();
    double  Area_1();
    void  ErrMsg_1(double nCode);
};


void Data1::PrintMenu()
{
    cout<<"          MENU\n"<<endl;
    cout<<"========================"<<endl;

    cout<<"1.矩形的面积\n"<<endl;
    cout<<"2.三角形的面积\n"<<endl;
    cout<<"3.梯形的面积\n"<<endl;

    cout<<"========================"<<endl;
    cout<<"choice(1,2,3):"<<endl;
}

void  Data1::setdata_1(double l,double w){
length=l;width=w;
}
double Data1::Girth_1(){
double g;
g=(length+width)*2;

return g;

}

double Data1::Area_1()
{
double s;
s=length*width;
if (length<=0||width<=0)
return -1000;
else
return s;
}
void  Data1::ErrMsg_1(int nCode) // 错误处理函数
{
    switch(nCode)
    {
        //根据错误码输出错误信息
    
    case -1000:cout<<"矩形任意一边不能小于或等于0!Error Code="<<nCode<<endl;break;
    
    }


class Data2{
double   a,b,c;
public:
    void setdata_2(double a1,double a2,double a3);
    double Girth_2();
    double Area_2();
    void  ErrMsg_2(double nCode);
};
void  Data2::setdata_2(double a1,double a2,double a3){
a=a1,b=a2,c=a3;
}
double Data2::Girth_2(){
double h;
h=a+b+c;
return h;
}
double Data2::Area_2(){
double s,l;
l=(a+b+c)/2;
if (a<=0||b<=0||c<=0||a+b<c)
           return -1001;
else
           return sqrt(l*(l-a)*(l-b)*(l-c));
}
void  Data2::ErrMsg_2(int nCode) // 错误处理函数
{
    switch(nCode)
    {
        //根据错误码输出错误信息
    
    case -1001:cout<<"三角形任意一边不能小于或等于0,或输入数据不能构成三角形!Error Code="<<nCode<<endl;break;
    
    }



class Data3{
    double   a,b,c;
public:
    void setdata_3(double a1,double a2,double h);
    double Girth_3();
    double Area_3();
    void  ErrMsg_3(int nCode);
};

void  Data3::setdata_3(double a1,double a2,double h){
    a=a1,b=a2,c=h;
}
double Data3::Girth_3(){
    double g,m;
    m=sqrt(((b-a)/2)*((b-a)/2)+c*c);
    g=a+b+2*m;
    if(a<=0||b<=0||c<=0||a==b)
        return -1002;
    else
        return g;
}
double Data3::Area_3(){
    double s;
    s=(a+b)*c/2;
    
    if(a<=0||b<=0||c<=0||a==b)
        return -1002;
    else
        return s;
}
void  Data3::ErrMsg_3(int nCode) // 错误处理函数
{
    switch(nCode)
    {
        //根据错误码输出错误信息
    
    case -1002:cout<<"梯形底或高不能小于0!或上底和下底相等!Error Code="<<nCode<<endl;break;
    
    }
}






int main()  // 主函数
{  Data1 Rect;
   Data2 Triangle;
   Data3 Trapezia;
    int  i;
    double a1, a2,a3, s, l, w, h;
Rect.PrintMenu();
    cin>>i;
    switch(i)
    {
    case 1:
    
        while(1)
        {
            cout<<"请输入矩形的长和宽:";
            cin>>l>>w;
            Rect.setdata_1(l,w);
         s=Rect.Area_1(); // 通过r求面积
            if(s > 0) //    有效输入,输出面积    
            {
                cout<<"矩形的面积为:"<<s<<endl;
                cout<<"周长为:"<<Rect.Girth_1()<<endl;
                break; // 跳出循环
            }
            else  // 无效的输入,返回错误码
            {
                Rect.ErrMsg_1(s);
            }
        }
        break;
    
    case 2:
        while(1)
        {
            cout<<"请输入三边;";
            cin>>a1>>a2>>a3;
        Triangle.setdata_2(a1,a2,a3);
            s=Triangle.Area_2(a1, a2, a3); // 通过r求面积
            if(s>0) //    有效输入,输出面积    
            {
                cout<<"三角形的面积为:"<<s<<endl;
                cout<<"周长为:"<<Triangle.Girth_2()<<endl;
                break; // 跳出循环
            }
            else  // 无效的输入,返回错误码
            {
                Triangle.ErrMsg_2(s);
            }
        }
        break;
        case 3:
        
        while(1)
        {
            cout<<"请输入梯形的上底下底和高:";
            cin>>a1>>a2>>h;
            Trapezia.setdata_3(a1,a2,h);
            s=Trapezia.Area_3(a1, a2, h); // 通过r求面积
            if(s > 0) //    有效输入,输出面积    
            {
                cout<<"梯形的面积为:"<<s<<endl;
                cout<<"周长为:"<<Trapezia.Girth_3()<<endl;
                break; // 跳出循环
            }
            else  // 无效的输入,返回错误码
            {
                Trapezia.ErrMsg_3(s);
            }
        }
        break;
    default:
        break;
    }
    return 0;
}
2008-04-06 00:15
bjtusq
Rank: 2
来 自:BJTU
等 级:论坛游民
帖 子:141
专家分:20
注 册:2006-8-5
得分:0 
好多错啊

[url][/url]
2008-04-06 08:59
bjtusq
Rank: 2
来 自:BJTU
等 级:论坛游民
帖 子:141
专家分:20
注 册:2006-8-5
得分:0 
#include <math.h>
#include<iostream>
using namespace std;
class Data1{
double  length,width ;
public:
    void PrintMenu();
    void setdata_1(double l,double w);
    double Girth_1();
    double  Area_1();
    void  ErrMsg_1(double nCode);这里和下面函数里传的参数类型不一样
};


void Data1::PrintMenu()
{
    cout<<"          MENU\n"<<endl;
    cout<<"========================"<<endl;

    cout<<"1.矩形的面积\n"<<endl;
    cout<<"2.三角形的面积\n"<<endl;
    cout<<"3.梯形的面积\n"<<endl;

    cout<<"========================"<<endl;
    cout<<"choice(1,2,3):"<<endl;
}

void  Data1::setdata_1(double l,double w){
length=l;width=w;
}
double Data1::Girth_1(){
double g;
g=(length+width)*2;

return g;

}

double Data1::Area_1()  怎么没有参数,怎么算{
double s;
s=length*width;
if (length<=0||width<=0)
return -1000;
else
return s;
}
void  Data1::ErrMsg_1(int nCode) // 错误处理函数   上面是double吧,换成double就不能用switch了
{
    switch(nCode)
    {
        //根据错误码输出错误信息
   
    case -1000:cout<<"矩形任意一边不能小于或等于0!Error Code="<<nCode<<endl;break;
   
    }


class Data2{
double   a,b,c;
public:
    void setdata_2(double a1,double a2,double a3);
    double Girth_2();
    double Area_2();
    void  ErrMsg_2(double nCode);
};
void  Data2::setdata_2(double a1,double a2,double a3){
a=a1,b=a2,c=a3;  //this.a更好}
double Data2::Girth_2(){
double h;
h=a+b+c;
return h;
}
double Data2::Area_2(){ double s,l;
l=(a+b+c)/2;
if (a<=0||b<=0||c<=0||a+b<c)
           return -1001;
else
           return sqrt(l*(l-a)*(l-b)*(l-c));
}
void  Data2::ErrMsg_2(int nCode) // 错误处理函数
{
    switch(nCode)    {
        //根据错误码输出错误信息
   
    case -1001:cout<<"三角形任意一边不能小于或等于0,或输入数据不能构成三角形!Error Code="<<nCode<<endl;break;
   
    }
}//函数结束应该有个“}”吧


class Data3{
    double   a,b,c;
public:
    void setdata_3(double a1,double a2,double h);
    double Girth_3();
    double Area_3();
    void  ErrMsg_3(int nCode);
};

void  Data3::setdata_3(double a1,double a2,double h){
    a=a1,b=a2,c=h;
}
double Data3::Girth_3(){
    double g,m;
    m=sqrt(((b-a)/2)*((b-a)/2)+c*c);
    g=a+b+2*m;
    if(a<=0||b<=0||c<=0||a==b)
        return -1002;
    else
        return g;
}
double Data3::Area_3(){
    double s;
    s=(a+b)*c/2;
   
    if(a<=0||b<=0||c<=0||a==b)
        return -1002;
    else
        return s;
}
void  Data3::ErrMsg_3(int nCode) // 错误处理函数
{
    switch(nCode)    {
        //根据错误码输出错误信息
   
    case -1002:cout<<"梯形底或高不能小于0!或上底和下底相等!Error Code="<<nCode<<endl;break;
   
    }
}






int main()  // 主函数
{  Data1 Rect;
   Data2 Triangle;
   Data3 Trapezia;
    int  i;
    double a1, a2,a3, s, l, w, h;
Rect.PrintMenu();
    cin>>i;
    switch(i)
    {
    case 1:
   
        while(1)
        {
            cout<<"请输入矩形的长和宽:";
            cin>>l>>w;
            Rect.setdata_1(l,w);
         s=Rect.Area_1(); // 通过r求面积
            if(s > 0) //    有效输入,输出面积   
            {
                cout<<"矩形的面积为:"<<s<<endl;
                cout<<"周长为:"<<Rect.Girth_1()<<endl;
                break; // 跳出循环
            }
            else  // 无效的输入,返回错误码
            {
                Rect.ErrMsg_1(s);
            }
        }
        break;
   
    case 2:
        while(1)
        {
            cout<<"请输入三边;";
            cin>>a1>>a2>>a3;
        Triangle.setdata_2(a1,a2,a3);
            s=Triangle.Area_2(a1, a2, a3); // 通过r求面积
            if(s>0) //    有效输入,输出面积   
            {
                cout<<"三角形的面积为:"<<s<<endl;
                cout<<"周长为:"<<Triangle.Girth_2()<<endl;
                break; // 跳出循环
            }
            else  // 无效的输入,返回错误码
            {
                Triangle.ErrMsg_2(s);
            }
        }
        break;
        case 3:
        
        while(1)
        {
            cout<<"请输入梯形的上底下底和高:";
            cin>>a1>>a2>>h;
            Trapezia.setdata_3(a1,a2,h);
            s=Trapezia.Area_3(a1, a2, h); // 通过r求面积
            if(s > 0) //    有效输入,输出面积   
            {
                cout<<"梯形的面积为:"<<s<<endl;
                cout<<"周长为:"<<Trapezia.Girth_3()<<endl;
                break; // 跳出循环
            }
            else  // 无效的输入,返回错误码
            {
                Trapezia.ErrMsg_3(s);
            }
        }
        break;
    default:
        break;
    }
    return 0;
}

[url][/url]
2008-04-06 09:07
bjtusq
Rank: 2
来 自:BJTU
等 级:论坛游民
帖 子:141
专家分:20
注 册:2006-8-5
得分:0 
还有一些错
我没自习看

[url][/url]
2008-04-06 09:07
weina
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-3-7
得分:0 
在类中求面积的函数没有参数也可以算的,直接用类里面的值就可以了。
double nCode应该是int的,
2008-04-06 10:34
weina
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-3-7
得分:0 
回复 5# 的帖子
谢谢你了
2008-04-06 10:51



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




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

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