实验五编写一个小型计算器Word文档格式.docx

上传人:b****3 文档编号:16458034 上传时间:2022-11-23 格式:DOCX 页数:13 大小:23.69KB
下载 相关 举报
实验五编写一个小型计算器Word文档格式.docx_第1页
第1页 / 共13页
实验五编写一个小型计算器Word文档格式.docx_第2页
第2页 / 共13页
实验五编写一个小型计算器Word文档格式.docx_第3页
第3页 / 共13页
实验五编写一个小型计算器Word文档格式.docx_第4页
第4页 / 共13页
实验五编写一个小型计算器Word文档格式.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

实验五编写一个小型计算器Word文档格式.docx

《实验五编写一个小型计算器Word文档格式.docx》由会员分享,可在线阅读,更多相关《实验五编写一个小型计算器Word文档格式.docx(13页珍藏版)》请在冰豆网上搜索。

实验五编写一个小型计算器Word文档格式.docx

VisualC++6.0或Dev-cpp

1.利用MFC的向导创建基于对话框的应用程序,添加按钮、编辑框等控件。

2.实现算术“加、减、乘、除”的运算。

3.选做添加计算三角函数运算、对数运算、指数运算、进制转换等功能。

 

1.利用MFCAppWizard向导建立程序框架,建立一个基于对话框的程序,项目名为MyCal。

2.利用资源编辑器,建立对话框。

添加一个编辑框,设置ID属性。

3.在控件工具栏中选择“Button”,添加一个按钮,鼠标右键单击该编辑框,在弹出快捷菜单中选择“Properties”,设置ID值和Caption属性。

4.依次添加若干编辑框和按钮,分别用于加减乘除操作及相应的操作数据。

编辑界面。

5.给编辑框连接变量。

在编辑框处点击右键选择“ClassWizard”,在弹出的对话框中选择“MemberVariables”选项卡,找到编辑框ID,选择“AddVariable”按钮,添加变量m_dispiay。

6.给按钮连接代码。

将程序代码在VisualC++6.0中进行程序调试,更改代码错误后编译通过,并输出调试后的最终结果。

输出结果如下:

实验五主要考察了使用VisualC++的MFC开发程序的方法。

通过实验五的再学习现作如下总结:

1.通过本次实验,初步掌握了MFC的基本使用操作,学会了掌握添加按钮、编辑框等控件。

2.对MFC的理解无非就是对按钮和编辑框链接相应的函数操作即可。

3.程序中出现了关于VisualC++版本的要求,在编译时提示缺少MFC42D.DLL、MFCO42D.DLL、MSVCRTD.dll等提示。

实验五程序代码如下:

//MyCalDlg.cpp:

implementationfile

//

#include"

stdafx.h"

MyCal.h"

MyCalDlg.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

//CAboutDlgdialogusedforAppAbout

classCAboutDlg:

publicCDialog

{

public:

CAboutDlg();

//DialogData

//{{AFX_DATA(CAboutDlg)

enum{IDD=IDD_ABOUTBOX};

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);

//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg:

:

CAboutDlg():

CDialog(CAboutDlg:

IDD)

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

voidCAboutDlg:

DoDataExchange(CDataExchange*pDX)

CDialog:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

//Nomessagehandlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//CMyCalDlgdialog

CMyCalDlg:

CMyCalDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CMyCalDlg:

IDD,pParent)

//{{AFX_DATA_INIT(CMyCalDlg)

m_display=_T("

"

);

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32

m_hIcon=AfxGetApp()->

LoadIcon(IDR_MAINFRAME);

voidCMyCalDlg:

//{{AFX_DATA_MAP(CMyCalDlg)

DDX_Text(pDX,IDC_EDIT1,m_display);

BEGIN_MESSAGE_MAP(CMyCalDlg,CDialog)

//{{AFX_MSG_MAP(CMyCalDlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BUTTON20,On_add)

ON_BN_CLICKED(IDC_BUTTON17,On_divide)

ON_BN_CLICKED(IDC_BUTTON9,On_equal)

ON_BN_CLICKED(IDC_BUTTON1,On_one)

ON_BN_CLICKED(IDC_BUTTON2,On_two)

ON_BN_CLICKED(IDC_BUTTON5,On_three)

ON_BN_CLICKED(IDC_BUTTON11,On_four)

ON_BN_CLICKED(IDC_BUTTON3,On_five)

ON_BN_CLICKED(IDC_BUTTON6,On_six)

ON_BN_CLICKED(IDC_BUTTON10,On_seven)

ON_BN_CLICKED(IDC_BUTTON12,On_eight)

ON_BN_CLICKED(IDC_BUTTON4,On_nine)

ON_BN_CLICKED(IDC_BUTTON8,On_zero)

ON_BN_CLICKED(IDC_BUTTON7,On_plus_minus)

ON_BN_CLICKED(IDC_BUTTON19,On_cut)

ON_BN_CLICKED(IDC_BUTTON18,On_multiply)

ON_BN_CLICKED(IDC_BUTTON16,On_CE)

//CMyCalDlgmessagehandlers

BOOLCMyCalDlg:

OnInitDialog()

OnInitDialog();

//Add"

About..."

menuitemtosystemmenu.

//IDM_ABOUTBOXmustbeinthesystemcommandrange.

ASSERT((IDM_ABOUTBOX&

0xFFF0)==IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX<

0xF000);

CMenu*pSysMenu=GetSystemMenu(FALSE);

if(pSysMenu!

=NULL)

{

CStringstrAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if(!

strAboutMenu.IsEmpty())

{

pSysMenu->

AppendMenu(MF_SEPARATOR);

AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}

}

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'

smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);

//Setbigicon

SetIcon(m_hIcon,FALSE);

//Setsmallicon

//TODO:

Addextrainitializationhere

returnTRUE;

//returnTRUEunlessyousetthefocustoacontrol

OnSysCommand(UINTnID,LPARAMlParam)

if((nID&

0xFFF0)==IDM_ABOUTBOX)

CAboutDlgdlgAbout;

dlgAbout.DoModal();

else

CDialog:

OnSysCommand(nID,lParam);

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow

//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,

//thisisautomaticallydoneforyoubytheframework.

OnPaint()

if(IsIconic())

CPaintDCdc(this);

//devicecontextforpainting

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

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(&

rect);

intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

OnPaint();

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCMyCalDlg:

OnQueryDragIcon()

return(HCURSOR)m_hIcon;

On_add()

Addyourcontrolnotificationhandlercodehere

op='

+'

;

//m_preNum=GetNum();

sscanf(m_display,"

%lf"

&

m_preNum);

m_display="

\0"

UpdateData(false);

On_cut()

Addyourcontrolnotificationhandlercodehere

-'

On_multiply()

*'

On_divide()

/'

On_equal()

doubleresult=0;

m_curNum);

switch(op)

case'

result=m_preNum+m_curNum;

break;

result=m_preNum-m_curNum;

case'

result=m_preNum*m_curNum;

result=m_preNum/m_curNum;

m_preNum=result;

chars[256]={0};

sprintf(s,"

result);

m_display=s;

On_one()

m_display+="

1"

On_two()

2"

On_three()

3"

On_four()

4"

On_five()

5"

On_six()

6"

On_seven()

7"

On_eight()

8"

On_nine()

9"

On_zero()

0"

On_plus_minus()

s);

-"

m_display+=s;

On_CE()

m_preNum=0;

m_curNum=0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1