| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 798 人关注过本帖
标题:我刚做的计算器....有小数点的..但运行的时候出现溢出错误....下面是代码
只看楼主 加入收藏
bozl
Rank: 2
等 级:论坛游民
帖 子:49
专家分:53
注 册:2007-10-23
收藏
 问题点数:0 回复次数:1 
我刚做的计算器....有小数点的..但运行的时候出现溢出错误....下面是代码
// YADlg.cpp : implementation file
//
#include <stdlib.h>
#include "stdafx.h"
#include "YA.h"
#include "YADlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
    CAboutDlg();

// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA

    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    //{{AFX_MSG(CAboutDlg)
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
    //{{AFX_DATA_INIT(CAboutDlg)
    //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CAboutDlg)
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
        // No message handlers
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CYADlg dialog

CYADlg::CYADlg(CWnd* pParent /*=NULL*/)
    : CDialog(CYADlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CYADlg)
    m_xianshi = 0.0;
    m_m1=" ";
    m_m2=" ";
    m_flag=' ';
    m_pt=' ';
    m_m11=0;
    m_m22=0;
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CYADlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CYADlg)
    DDX_Text(pDX, IDC_EDIT1, m_xianshi);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CYADlg, CDialog)
    //{{AFX_MSG_MAP(CYADlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_B0, OnB0)
    ON_BN_CLICKED(IDC_B1, OnB1)
    ON_BN_CLICKED(IDC_B2, OnB2)
    ON_BN_CLICKED(IDC_B3, OnB3)
    ON_BN_CLICKED(IDC_B4, OnB4)
    ON_BN_CLICKED(IDC_B5, OnB5)
    ON_BN_CLICKED(IDC_B6, OnB6)
    ON_BN_CLICKED(IDC_B7, OnB7)
    ON_BN_CLICKED(IDC_B8, OnB8)
    ON_BN_CLICKED(IDC_B9, OnB9)
    ON_BN_CLICKED(IDC_BCHENG, OnBcheng)
    ON_BN_CLICKED(IDC_BCHU, OnBchu)
    ON_BN_CLICKED(IDC_BDENG, OnBdeng)
    ON_BN_CLICKED(IDC_BJIA, OnBjia)
    ON_BN_CLICKED(IDC_BJIAN, OnBjian)
    ON_BN_CLICKED(IDC_BPT, OnBpt)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CYADlg message handlers

BOOL CYADlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    // TODO: Add extra initialization here
    
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CYADlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialog::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CYADlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CYADlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CYADlg::OnB0()
{
    // TODO: Add your control notification handler code here
    if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"0");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"0");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"0");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"0");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);

}

void CYADlg::OnB1()
{
    // TODO: Add your control notification handler code here
        if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"1");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"1");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"1");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"1");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);

}

void CYADlg::OnB2()
{
    // TODO: Add your control notification handler code here
    if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"2");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"2");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"2");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"2");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);

}

void CYADlg::OnB3()
{
    // TODO: Add your control notification handler code here
    if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"3");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"3");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"3");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"3");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);


}

void CYADlg::OnB4()
{
    // TODO: Add your control notification handler code here
        if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"4");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"4");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"4");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"4");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);

}

void CYADlg::OnB5()
{
    // TODO: Add your control notification handler code here
    if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"5");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"5");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"5");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"5");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);


}

void CYADlg::OnB6()
{
    // TODO: Add your control notification handler code here
        if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"6");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"6");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"6");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"6");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);

}

void CYADlg::OnB7()
{
    // TODO: Add your control notification handler code here
        if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"7");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"7");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"7");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"7");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);

}

void CYADlg::OnB8()
{
    // TODO: Add your control notification handler code here
        if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"8");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"8");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"8");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"8");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);

}

void CYADlg::OnB9()
{
    // TODO: Add your control notification handler code here
        if(m_flag==' ')
    {
        if(m_pt=='.')
        {
            m_m1=strcat(m_m1,".");
            m_m1=strcat(m_m1,"9");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
            m_pt=' ';
        }
        else
        {
            m_m1=strcat(m_m1,"9");
            m_m11=atoi(m_m1);
            m_xianshi=m_m11;
        }
    }
    else
            {
        if(m_pt=='.')
        {
            m_m2=strcat(m_m2,".");
            m_m2=strcat(m_m2,"9");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
            m_pt=' ';
        }
        else
        {
            m_m2=strcat(m_m2,"9");
            m_m22=atoi(m_m2);
            m_xianshi=m_m22;
        }
    }
    UpdateData(false);


}

void CYADlg::OnBcheng()
{
    // TODO: Add your control notification handler code here
    m_flag='*';
}

void CYADlg::OnBchu()
{
    // TODO: Add your control notification handler code here
    m_flag='/';
}

void CYADlg::OnBdeng()
{
    // TODO: Add your control notification handler code here
    switch(m_flag)
    {
    case '*':m_xianshi=m_m11*m_m22;break;
    case '/':m_xianshi=m_m11/m_m22;break;
    case '+':m_xianshi=m_m11+m_m22;break;
    case '-':m_xianshi=m_m11-m_m22;break;
    }
}

void CYADlg::OnBjia()
{
    // TODO: Add your control notification handler code here
    m_flag='+';
}

void CYADlg::OnBjian()
{
    // TODO: Add your control notification handler code here
    m_flag='-';
}

void CYADlg::OnBpt()
{
    // TODO: Add your control notification handler code here
    m_pt='.';
}
搜索更多相关主题的帖子: 计算器 include CAboutDlg IDD 
2008-03-06 19:57
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
收藏
得分:0 
上传压缩包好吗?你这样这么长的代码谁帮你看呀?

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
2008-03-09 21:35
快速回复:我刚做的计算器....有小数点的..但运行的时候出现溢出错误....下面是代 ...
数据加载中...
 
   



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

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