| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 547 人关注过本帖
标题:帮我看看!
只看楼主 加入收藏
ll564992764
Rank: 1
等 级:新手上路
帖 子:31
专家分:6
注 册:2011-9-16
结帖率:85.71%
收藏
已结贴  问题点数:0 回复次数:7 
帮我看看!
#include <iostream.h>
void main()
{
    double fristnum;
    char sop;
    double secondnum;
    int frist;
    int second;
    cout<<"请输入表达式:"<<endl;
    cin>>fristnun>>sop>>secondnum;
    cout<<"结果:"<<calc(fristnum,sop,secondnum)<<endl;
}
double calc(double fristnum,char sop,double secondnum)
{
    calculator *pcalc=NULL;
    pcalc=judge(fristnum,sop,secondnum);
    double frusult=pclac->result();
    delete pcalc;
    return fresult;
}
class calcultor
{
public:
    double data1();
    {
        return m_fdata1;
    }
    void setdata1(double fristnum)
    {
        m_fdata1=fristnum;
    }
    double data2();
    {
        return m_fdata2;
    }
    void setdata2(double secondnum)
    {
        m_fdata2=secondnum;
    }
    double result() const=0;
private:
    double m_fdata1,m_fdata2;
};
calcultor *judge(double fristnum,char sop,double secondnum)
{
    calcultor *pcalc=NULL;
    if(sop='+')
        pcalc=new add();
    else if(sop='-')
        pcalc=new sub();
    else if(sop='^')
        pcalc=new power();
    else if(sop='%')
   


        pcalc=new compement();
    else
        throw string("不可识别的运算符!");
    pcalc->setdata1(fristnum);
    pcalc->setdata2(secondnum);
    return pcalc;
}
class add:public calcultor
{
public:
    add(double fristnum=0.,double secondnum=0.)
    {
        calcultor(fristnum,secondnum);
    }
    double result() const
    {
        return data1()+data2();
    }
};
class sub:public calcultor
{
public:
    sub(double fristnum=0.,double secondnum=0.)
    {
        calcultor(fristnum,secondnum);
    }
    double result() const
    {
        return data1()-data2();
    }
};
class power:public calcultor
{
public:
    power(double fristnum=0.,double secondnum=0.)
    {
        calcultor(fristnum,secondnum);
    }
    double result() const
    {
        return data1()^data2();
    }
};
class complement:public calcultor
{
public:
    complement(double fristnum=0.,double secondnum=0.)
    {
        calcultor(fristnum,secondnum);
    }
    double result() const
    {
        return data1()%data2();
    }
};
报的错是calnew.cpp(63) : error C2143: syntax error : missing ';' before '}'
不知为啥?求指导~

[ 本帖最后由 ll564992764 于 2011-10-15 20:24 编辑 ]
搜索更多相关主题的帖子: calculator include public double return 
2011-10-15 20:22
nomify
Rank: 5Rank: 5
等 级:职业侠客
帖 子:79
专家分:366
注 册:2011-10-13
收藏
得分:0 
貌似错误好多呀。
2011-10-15 22:14
mengcan555
Rank: 4
等 级:业余侠客
帖 子:104
专家分:253
注 册:2011-9-17
收藏
得分:0 
错误太多,有些单词的前后拼写都不一致,我彻底放弃帮你修改了,你还是练练基本功吧
2011-10-15 22:40
ll564992764
Rank: 1
等 级:新手上路
帖 子:31
专家分:6
注 册:2011-9-16
收藏
得分:0 
回复 2楼 nomify
求指导!有高分哦!
2011-10-15 23:24
ll564992764
Rank: 1
等 级:新手上路
帖 子:31
专家分:6
注 册:2011-9-16
收藏
得分:0 
回复 3楼 mengcan555
别啊~我才学的C++啊~
2011-10-15 23:25
ll564992764
Rank: 1
等 级:新手上路
帖 子:31
专家分:6
注 册:2011-9-16
收藏
得分:0 
#include <iostream.h>
void main()
{
    double fristnum;
    char sop;
    double secondnum;
    int frist;
    int second;
    cout<<"请输入表达式:"<<endl;
    cin>>fristnum>>sop>>secondnum;
    cout<<"结果:"<<calc(fristnum,sop,secondnum)<<endl;
}
double calc(double fristnum,char sop,double secondnum)
{
    calculator *pcalc=NULL;
    pcalc=judge(fristnum,sop,secondnum);
    double frusult=pclac->result();
    delete pcalc;
    return fresult;
}
class calculator
{
public:
    double data1();
    {
        return m_fdata1;
    }
    void setdata1(double fristnum)
    {
        m_fdata1=fristnum;
    }
    double data2();
    {
        return m_fdata2;
    }
    void setdata2(double secondnum)
    {
        m_fdata2=secondnum;
    }
    double result() const=0;
private:
    double m_fdata1,m_fdata2;
};
calculator *judge(double fristnum,char sop,double secondnum)
{
    calculator *pcalc=NULL;
    if(sop='+')
        pcalc=new add();
    else if(sop='-')
        pcalc=new sub();
    else if(sop='^')
        pcalc=new power();
    else if(sop='%')
   


        pcalc=new compement();
    else
        throw string("不可识别的运算符!");
    pcalc->setdata1(fristnum);
    pcalc->setdata2(secondnum);
    return pcalc;
}
class add:public calculator
{
public:
    add(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result() const
    {
        return data1()+data2();
    }
};
class sub:public calculator
{
public:
    sub(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result() const
    {
        return data1()-data2();
    }
};
class power:public calculator
{
public:
    power(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result() const
    {
        return data1()^data2();
    }
};
class complement:public calculator
{
public:
    complement(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result() const
    {
        return data1()%data2();
    }
};
这是改过拼写错误的~
2011-10-15 23:40
nomify
Rank: 5Rank: 5
等 级:职业侠客
帖 子:79
专家分:366
注 册:2011-10-13
收藏
得分:10 
程序代码:
#include <iostream.h>
#include <cmath>
#include <stdexcept>

class calculator
{
public:
    calculator(double fristnum=0.,double secondnum=0.) :
      m_fdata1(fristnum),m_fdata2(secondnum) {}
       
    double data1()
    {
        return m_fdata1;
    }
    void setdata1(double fristnum)
    {
        m_fdata1=fristnum;
    }
    double data2()
    {
        return m_fdata2;
    }
    void setdata2(double secondnum)
    {
        m_fdata2=secondnum;
    }
    virtual double result()
    {
        return 0;
    }
private:
    double m_fdata1,m_fdata2;
};

class add:public calculator
{
public:
    add(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result()
    {
        return data1()+data2();
    }
};
class sub:public calculator
{
public:
    sub(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result()
    {
        return data1()-data2();
    }
};
class power:public calculator
{
public:
    power(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result()
    {
        return pow(data1(),data2());
    }
};
class complement:public calculator
{
public:
    complement(double fristnum=0.,double secondnum=0.)
    {
        calculator(fristnum,secondnum);
    }
    double result()
    {
        return (int)data1()%(int)data2();
    }
};

calculator *judge(double fristnum,char sop,double secondnum)
{
    calculator *pcalc=NULL;
    if(sop=='+')
        pcalc=new add();
    else if(sop=='-')
        pcalc=new sub();
    else if(sop=='^')
        pcalc=new power();
    else if(sop=='%')  
        pcalc=new complement();
    else
        throw  std::runtime_error("不可识别的运算符!");
    pcalc->setdata1(fristnum);
    pcalc->setdata2(secondnum);
    return pcalc;
}

double calc(double fristnum,char sop,double secondnum)
{
    calculator *pcalc=NULL;
    pcalc=judge(fristnum,sop,secondnum);
    double fresult=pcalc->result();
    delete pcalc;
    return fresult;
}

void main()
{
    double fristnum;
    char sop;
    double secondnum;
//    int frist;
//    int second;
    cout<<"请输入表达式:"<<endl;
    cin>>fristnum>>sop>>secondnum;
    cout<<"结果:"<<calc(fristnum,sop,secondnum)<<endl;
}


[ 本帖最后由 nomify 于 2011-10-16 00:32 编辑 ]
2011-10-16 00:29
ll564992764
Rank: 1
等 级:新手上路
帖 子:31
专家分:6
注 册:2011-9-16
收藏
得分:0 
回复 7楼 nomify
谢谢~给分了~
2011-10-16 09:03
快速回复:帮我看看!
数据加载中...
 
   



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

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