c++ mfc 口算小程序

• 完成一个口算训练程序
– 该程序能逐一生成口算题, 并以对话框的形式呈现给用户, 用户 输入当前题目答案后, 生成下一道题目
– 用户答题数量达到预先设置的数目时, 练习结束, 以消息框的形 式给出用户成绩以及错误题目


void CMyDlg::OnZero() 
{
    // TODO: Add your control notification handler code here
    m_showend+="0";
    UpdateData(false);
}
 
 
void CMyDlg::OnOne() 
{
    // TODO: Add your control notification handler code here
        m_showend+="1";
    UpdateData(false);
}
 
 
void CMyDlg::OnTwo() 
{
    // TODO: Add your control notification handler code here
        m_showend+="2";
    UpdateData(false);
}
 
 
void CMyDlg::OnThree() 
{
    // TODO: Add your control notification handler code here
        m_showend+="3";
    UpdateData(false);
}
 
 
void CMyDlg::OnFour() 
{
    // TODO: Add your control notification handler code here
        m_showend+="4";
    UpdateData(false);
}
 
 
void CMyDlg::OnFive() 
{
    // TODO: Add your control notification handler code here
        m_showend+="5";
    UpdateData(false);
}
 
 
void CMyDlg::OnSix() 
{
    // TODO: Add your control notification handler code here
        m_showend+="6";
    UpdateData(false);
}
 
 
void CMyDlg::OnSeven() 
{
    // TODO: Add your control notification handler code here
        m_showend+="7";
    UpdateData(false);
}
 
 
void CMyDlg::OnEight() 
{
    // TODO: Add your control notification handler code here
        m_showend+="8";
    UpdateData(false);
}
 
 
void CMyDlg::OnNine() 
{
    // TODO: Add your control notification handler code here
        m_showend+="9";
    UpdateData(false);
}
 
 
void CMyDlg::OnClearEditBox() //此函数用于清空编辑框信息
{
    // TODO: Add your control notification handler code here
    m_showend="";
    operand_one=0.0;
    operand_two=0.0;
    UpdateData(false);    //更新编辑框信息
}
 
 
void CMyDlg::OnRun() 
{
    // TODO: Add your control notification handler code here
    operand_two=atof(m_showend);
    double end=0.0;
 
 
    //此处为判断操作的类型;
    if(operate==add)
    {
        end=operand_one+operand_two;
        m_showend.Format("%g",end);
    }
    else if(operate==subtraction)
    {
        end=operand_one-operand_two;
        m_showend.Format("%g",end);
    }
    else if(operate==multiplication)
    {
        end=operand_one*operand_two;
        m_showend.Format("%g",end);
    }
    else if(operate==division)
    {
        end=operand_one/operand_two;
        m_showend.Format("%g",end);
    }
    UpdateData(false);
}
 
 
void CMyDlg::OnDivision() //除法运算
{
    // TODO: Add your control notification handler code here
    operand_one=atof(m_showend);
    m_showend="";
    UpdateData(false);
 
 
    operate=division;//操作类型为“除”;
}
 
 
void CMyDlg::OnMultiplication() //乘法运算
{
    // TODO: Add your control notification handler code here
    operand_one=atof(m_showend);
    m_showend="";
    UpdateData(false);
 
 
    operate=multiplication;//操作类型为“乘”;
}
 
 
void CMyDlg::OnSubtraction() //减法运算
{
    // TODO: Add your control notification handler code here
    operand_one=atof(m_showend);
    m_showend="";
    UpdateData(false);
 
 
    operate=subtraction;//操作类型为“减”;
}
 
 
void CMyDlg::OnAdd() //加法运算
{
    // TODO: Add your control notification handler code here
    operand_one=atof(m_showend);
    m_showend="";
    UpdateData(false);
 
 
    operate=add;//操作类型为“加”;
 
 
}
 
 
void CMyDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
    // TODO: Add your message handler code here and/or call default
    AfxMessageBox("345234");
    switch(nChar)
    {
        case 48:CMyDlg::OnZero();break;    
        case 49:CMyDlg::OnOne();break;
        case 50:CMyDlg::OnTwo();break;
        case 51:CMyDlg::OnThree();break;
        case 52:CMyDlg::OnFour();break;
        case 53:CMyDlg::OnFive();break;
        case 54:CMyDlg::OnSix();break;
        case 55:CMyDlg::OnSeven();break;
        case 56:CMyDlg::OnEight();break;
        case 57:CMyDlg::OnNine();break;
        default:break;
    }
    CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
 
 
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) 
{
    // TODO: Add your specialized code here and/or call the base class
    if(pMsg->message == WM_KEYDOWN)
    {
        if(pMsg->wParam==VK_ESCAPE)    //忽略掉键盘上的esc按键消息
        {
            return true;
        }
        //CMyDlg::OnKeyDown(nChar, nRepCnt, nFlags) ;
        switch(pMsg->wParam)    
        {
            case 48:CMyDlg::OnZero();break;    
            case 49:CMyDlg::OnOne();break;
            case 50:CMyDlg::OnTwo();break;
            case 51:CMyDlg::OnThree();break;
            case 52:CMyDlg::OnFour();break;
            case 53:CMyDlg::OnFive();break;
            case 54:CMyDlg::OnSix();break;
            case 55:CMyDlg::OnSeven();break;
            case 56:CMyDlg::OnEight();break;
            case 57:CMyDlg::OnNine();break;
            default:break;
        
        }
    }
    return CDialog::PreTranslateMessage(pMsg);
}