work- 2022-05-22 12:08 采纳率: 50%
浏览 72
已结题

c++ mfc 口算小程序

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

  • 写回答

1条回答 默认 最新

  • 歇歇 2022-05-28 22:42
    关注
    
    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);
    }
    
    评论

报告相同问题?

问题事件

  • 系统已结题 5月30日
  • 创建了问题 5月22日

悬赏问题

  • ¥15 用js遍历数据并对非空元素添加css样式
  • ¥15 使用autodl云训练,希望有直接运行的代码(关键词-数据集)
  • ¥50 python写segy数据出错
  • ¥20 关于线性结构的问题:希望能从头到尾完整地帮我改一下,困扰我很久了
  • ¥30 3D多模态医疗数据集-视觉问答
  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵
  • ¥15 如何输入双曲线的参数a然后画出双曲线?我输入处理函数加上后就没有用了,不知道怎么回事去掉后双曲线可以画出来
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术