简易计算器实验报告
实 验 题 目 简易计算器 学 生 姓 名 吴云 学 号 2013051205 所 在 学 院 计算机学院 年 级 班 级 计科5班
成都信息工程学院 计算机学院
一、 题目:简易计算器 题目概述:
? 学习MFC的应用,做出相对精美的界面;学习面向对象的思想,即用C++,考虑到
类。
? 模仿Windows的计算器,用图形界面实现加减乘除开根号求倒数等等基本操作。 ? 实现括号运算。
二、 开发环境
Win7操作系统的电脑一台 + VC6.0编程软件
三、 设计步骤
(一)界面设计:
首先打开VC++6.0 建立一个MFC的基本对话框,添加所需的按钮的编辑框如下图:
(二)添加变量:
点击菜单栏的:查看->建立类向导->添加成员变量: 给编辑框添加一个CString类型的变量m_result。
(三)为按钮添加事件:
为按钮和编辑框改了名字和ID后点击每一个按钮,为每一个按钮添加一个对应的事件,即:为每一个按钮添加算法代码。 (四)个性化程序:
即修改程序一些细节的地方,如程序的图标,程序的界面颜色、图案等等。。 (五)调试并运行程序:
将写好的程序调试好了后运行。
四、 程序的主要函数及其释义:
void CCalculatorDlg::OnButton1() //按下数字键1时出现的事件 { }
void CCalculatorDlg::OnButton2() //按下数字键2时出现的事件,同上 {
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result = _T(\fff = 0;
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result += _T(\
UpdateData(FALSE); //将数据送到编辑窗口
//当fff == 0时,此时刚算完上次的数据,再按数字键时自动清
空上次的数据
m_result = _T(\ //对字符串处理需要_T()函数实现 fff = 0;
}
m_result += _T(\UpdateData(FALSE);
void CCalculatorDlg::OnButton3() // 3 { }
void CCalculatorDlg::OnButton4() // 4 { }
void CCalculatorDlg::OnButton5() // 5 { }
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result += _T(\UpdateData(FALSE);
m_result = _T(\fff = 0;
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result += _T(\UpdateData(FALSE);
m_result = _T(\fff = 0;
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result += _T(\UpdateData(FALSE);
m_result = _T(\fff = 0;
void CCalculatorDlg::OnButton6() // 6 { }
void CCalculatorDlg::OnButton7() // 7 { }
void CCalculatorDlg::OnButton8() // 8 { }
void CCalculatorDlg::OnButton9() // 9 {
// TODO: Add your control notification handler code here if(fff == 1){
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result += _T(\UpdateData(FALSE);
m_result = _T(\fff = 0;
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result += _T(\UpdateData(FALSE);
m_result = _T(\fff = 0;
// TODO: Add your control notification handler code here if(fff == 1){ }
m_result += _T(\UpdateData(FALSE);
m_result = _T(\fff = 0;