跪求一个MFC制作的简单计算器带报告 T T

 我来答
揭美男的真相
推荐于2017-07-02
知道答主
回答量:3
采纳率:0%
帮助的人:0
展开全部
计算机系统设计报告
一、 计算器系统开发设计思想
1、 试验目的
运用所学知识,通过实践加强对所学知识的理解和巩固,增强对相关知识的认识,提高应用所学知识在世界中发现问题、分析问题和解决问题的能力。
2、 试验内容
设计一个多功能计算软件实现功能:
1)具备整型数据、浮点型数据的算术(加、减、乘、除)运算功能。依次输入第一个运算数、运算符(+,-,*,/)、第二个运算数,然后输出结果。结果可以作为下一个运算的第一运算数。按‘C’清屏,按‘R’返回 菜单。
例如:输入:2
+
5
输出:7
2)实现单运算符表达式计算的功能。输入的操作数可以包含整数或浮点数。输入表达式如下:
例如:输入:2+5在
输出:7
二、 计算器系统功能及系统设计介绍
1、 界面设计

创建一个基本对话框的MFC应用程序,在对话框窗体上创建一个计算器所需的按钮。并修改按钮的属性,将个按钮的ID改为向对应的符号,如将 的ID改为IDC_zhengfu。并对编辑添加成员变量m_result用以显示结果。
2、对主要成员函数编写代码
(1) 对头文件jsDlg.h编写代码
在头文件中手动添加成员函数与成员函数变量,代码如下:
//定义两个euum枚举类型Operator, CalcError结构
enum Operator { OpNone, OpAdd, OpSubtract, OpMultiply, OpDivide };
enum CalcError { ErrNone, ErrDivideByZero };

double m_operand; //存储当前输入的操作数
double m_accum; //存储当前的计算处理结束
BOOL m_bCoff; //标识当前输入是否是小数
double m_coff; //小数输入时的系数
Operator m_operator; //定义 枚举变量 m_operator 用以标识当前运算符
CalcError m_errorState; // 定义 枚举 变量m_errorState 用以标识当前运算状态
BOOL m_bOperandAvail; //标识当前输入是否是新输入数字
void UpdateDisplay(); //成员函数处理显示
void Calculate(); //成员函数处理计算
void OnOperandInput(int a); //成员函数处理数字输入
(2)对原文件jsDlg.cpp编写代码
因为该系统运算过程中需要使用平方跟函数,所以在头文件中要添加头文件#include “math.h”。然后对声明变量进行初始化:
jsDlg::jsDlg(CWnd* pParent /*=NULL*/)
: CDialog(jsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCaaDlg)
m_result = _T(“”); //默认为m_result变量初始化
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_coff=0.1; //为变量进行初始化
m_bCoff=0; 为变量进行初始化
m_errorState = ErrNone; //为变量进行初始化
m_bOperandAvail=FALSE; //为变量进行初始化
m_operator=OpNone; //为变量进行初始化
}
(3)对各控件编写代码
void jsDlg ::On0() //处理“ 0”按钮
{
// TODO: Add your control notification handler code here
OnOperandInput(0);
}

void jsDlg::On1() //处理“ 1”按钮
// TODO: Add your control notification handler code here
OnOperandInput(1);
}
数字“0-9”控件的代码同上类似
void CJsDlg::Onjia()
{
// TODO: Add your control notification handler code here
Calculate();
m_operator = OpAdd;
}

void CJsDlg::Onjian()
{
// TODO: Add your control notification handler code here
Calculate();
m_operator = OpSubtract;
}

void CJsDlg::Oncheng()
{
// TODO: Add your control notification handler code here
Calculate();
m_operator = OpMultiply;
}

void CJsDlg::Onchu()
{
// TODO: Add your control notification handler code here
Calculate();
m_operator = OpDivide;
}

void CJsDlg::Onzhengfu()
{
// TODO: Add your control notification handler code here
m_operand*=-1;
UpdateDisplay();
}

void CJsDlg::Ondian()
{
// TODO: Add your control notification handler code here
m_bCoff=1;
UpdateDisplay();
}

void CJsDlg::Ondengyu()
{
// TODO: Add your control notification handler code here
Calculate();
m_operator = OpNone;
}

void CJsDlg::Onpingfang()
{
// TODO: Add your control notification handler code here
m_operand*=m_operand;
UpdateDisplay();
}

void CJsDlg::Onsqrt()
{
// TODO: Add your control notification handler code here
m_operand=sqrt(m_operand);
UpdateDisplay();
}

void CJsDlg::Onqinglin()
{
// TODO: Add your control notification handler code here
m_operator = OpNone;
m_operand = 0;
m_accum = 0;
m_bOperandAvail = FALSE;
m_errorState = ErrNone;
m_coff=0.1;
m_bCoff=0;
UpdateDisplay();
}

void CJsDlg::OnR()
{
// TODO: Add your control notification handler code here
OnOK(); // 退出对话框程序
}
(4)编写用于实现计算的自定义函数
在jsDlg.cpp中编写:
void jsDlg ::OnOperandInput(int a) //处理0-9 数字的输入函数
{
if (m_errorState != ErrNone) //判断当前运算是否有误,若有则返回
return;
if (!m_bOperandAvail) //判断是否输入新的数字,1-是 0-否
m_operand = 0;
if(!m_bCoff) //判断是否是小数输入,1-是 0-否
m_operand=m_operand*10+(a);
else
{
m_operand=m_operand+(a)*m_coff;
m_coff*=0.1;
}
m_bOperandAvail=TRUE;
UpdateDisplay(); //更新显示
}
(5)编写处理计算函数
在jsDlg.cpp中编写:
void jsDlg ::Calculate()
{
if (m_errorState != ErrNone)
return;
if (m_bOperandAvail)
{ //如果没有计算符就将m_operand值赋予m_accum
if (m_operator == OpNone)
m_accum = m_operand;
else if (m_operator == OpMultiply)
//否则按计算符进行计算
m_accum *= m_operand;
else if (m_operator == OpDivide)
{
if (m_operand == 0)
m_errorState = ErrDivideByZero;
else
m_accum /= m_operand;
}
else if (m_operator == OpAdd)
m_accum += m_operand;
else if (m_operator == OpSubtract)
m_accum -= m_operand;
}
m_bOperandAvail = FALSE;
m_bCoff=0;
m_coff=0.1;
UpdateDisplay();
}
(6)编写处理显示函数
在jsDlg.cpp中编写:
Void CjsDlg::UpdateDisplay() //处理显示函数
{
if (GetSafeHwnd() == NULL)
return;
if (m_errorState != ErrNone)
m_result="除数不能为零";
else //如果当前计算无错误那么进行显示
{
//如果是输入计算数,那么显示输入情况,如果按下计算符,则显示结果
float lVal = (m_bOperandAvail) ? m_operand : m_accum;
m_result.Format(_T("%f"), lVal); //将float型转化为CString型
int i=m_result.GetLength();
while(m_result.GetAt(i-1)=='0')
{
m_result.Delete(i-1,1);
i-=1;
}
}
//用编辑控件变量m_result改变编辑控件的值,更新显示
UpdateData(FALSE);
}
3、 检查创建工程并运行
三、 计算器系统开发的体会
本次MFC计算器的制作,学到了MFC基本的编程方法,增加了编写程序的能力,对VC++可视化用户界面的理解进一步加深。对类的类的封装和设计也有了一种新的认识,为以后的学习积累了经验。不过,通过这次设计实践,也发现了自己的不足之处。在编写过程中也遇到了困难,请教了许多同学,反复检查之后也终于不问题解决了,做出了自己想要的成果。总之,这次实践然我学到了许多东西,有很大的进步。

这个...嫌长了就自己简略一下...
AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
匿名用户
2011-07-05
展开全部
已发送到你的邮箱,VC-MFC课程设计还带实验报告的哦。
另外,站长团上有产品团购,便宜有保证
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式