VC++课程设计简单计算器的设计Word文件下载.docx
- 文档编号:17184084
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:35
- 大小:120.62KB
VC++课程设计简单计算器的设计Word文件下载.docx
《VC++课程设计简单计算器的设计Word文件下载.docx》由会员分享,可在线阅读,更多相关《VC++课程设计简单计算器的设计Word文件下载.docx(35页珍藏版)》请在冰豆网上搜索。
(5)、删除功能:
可以在输入错误时删除已输入的数值。
(6)、归零功能:
可以在计算完成后清空编辑框中的已有数值。
二、程序设计与实现
1.程序结构
本计算器首先是通过在计算器的界面上按下相应的按钮,来进行基本的加,减,乘,除等基本运算,计算器还能够进行平方运算,求平方根运算,乘方运算,三角函数运算(包括正弦函数(sin)、余弦函数(cos)、正切函数(tan)、余切函数(cot)),对数函数(ln、log),指数函数(exp),幂函数(x~)和进制转换(包括二进制转十进制、十进制转二进制和八进制转二进制)等运算。
以下是本计算器的运算流程图:
二进制转十进制N-S流程图:
intlen;
doublesum=0.0,num;
len=strlen(m_xs);
inti=0;
i<
len;
num=(m_xs[i]-48);
num=num*pow(2,len-i-1);
sum+=num;
i++;
m_xs.Format("
%f"
sum);
UpdateData(false);
十进制转二进制N-S流程图:
intn,i,t;
doubleY,p=0.0;
Y=strtod(m_xs,NULL);
t=(int)(Y);
t!
=1
是
否
i=1;
当t>
1;
n=t%2;
t=t/2;
p+=n*pow(10,(i-1));
p+=1*pow(10,(i-1));
p);
2.设计步骤:
(1)创建一个基于对话框的应用程序。
(2)利用资源编辑器编辑对话框资源,及设计计算器界面并修改对话框各按钮的ID属性和Caption属性。
(3)利用ClassWizard为各按钮添加消息映射(代码在下面详细介绍)。
(4)设置对话框文本背景颜色。
(5)编辑图标。
3.详细介绍:
(1)计算器界面:
(2)主要代码:
//2435Dlg.cpp:
implementationfile
//
#include"
stdafx.h"
2435.h"
2435Dlg.h"
math.h"
#include<
stdlib.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()
//CMy2435Dlgdialog
CMy2435Dlg:
CMy2435Dlg(CWnd*pParent/*=NULL*/)
:
CDialog(CMy2435Dlg:
IDD,pParent)
//{{AFX_DATA_INIT(CMy2435Dlg)
m_11=_T("
"
);
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->
LoadIcon(IDR_MAINFRAME);
m_11="
;
ii="
0"
jj=0;
pi=(float)3.1415926;
aaa=0;
bbb=0;
intCMy2435Dlg:
pd=1;
voidCMy2435Dlg:
//{{AFX_DATA_MAP(CMy2435Dlg)
DDX_Control(pDX,IDC_BUTTON1,m_0);
DDX_Control(pDX,IDC_BUTTON10,m_1);
DDX_Control(pDX,IDC_BUTTON8,m_9);
DDX_Control(pDX,IDC_BUTTON5,m_8);
DDX_Control(pDX,IDC_BUTTON4,m_7);
DDX_Control(pDX,IDC_BUTTON9,m_6);
DDX_Control(pDX,IDC_BUTTON7,m_5);
DDX_Control(pDX,IDC_BUTTON6,m_4);
DDX_Control(pDX,IDC_BUTTON12,m_3);
DDX_Control(pDX,IDC_BUTTON11,m_2);
DDX_Text(pDX,IDC_EDIT1,m_11);
BEGIN_MESSAGE_MAP(CMy2435Dlg,CDialog)
//{{AFX_MSG_MAP(CMy2435Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_EDIT1,OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON11,OnButton11)
ON_BN_CLICKED(IDC_BUTTON10,OnButton10)
ON_BN_CLICKED(IDC_BUTTON3,OnButton3)
ON_BN_CLICKED(IDC_BUTTON18,OnButton18)
ON_BN_CLICKED(IDC_BUTTON12,OnButton12)
ON_BN_CLICKED(IDC_BUTTON6,OnButton6)
ON_BN_CLICKED(IDC_BUTTON7,OnButton7)
ON_BN_CLICKED(IDC_BUTTON9,OnButton9)
ON_BN_CLICKED(IDC_BUTTON4,OnButton4)
ON_BN_CLICKED(IDC_BUTTON5,OnButton5)
ON_BN_CLICKED(IDC_BUTTON8,OnButton8)
ON_BN_CLICKED(IDC_BUTTON1,OnButton1)
ON_BN_CLICKED(IDC_BUTTON13,OnButton13)
ON_BN_CLICKED(IDC_BUTTON14,OnButton14)
ON_BN_CLICKED(IDC_BUTTON15,OnButton15)
ON_BN_CLICKED(IDC_BUTTON16,OnButton16)
ON_BN_CLICKED(IDC_BUTTON17,OnButton17)
ON_BN_CLICKED(IDC_BUTTON2,OnButton2)
ON_BN_CLICKED(IDC_BUTTON19,OnButton19)
ON_BN_CLICKED(IDC_BUTTON20,OnButton20)
ON_BN_CLICKED(IDC_BUTTON25,OnButton25)
ON_BN_CLICKED(IDC_BUTTON21,OnButton21)
ON_BN_CLICKED(IDC_RADIO1,OnRadio1)
ON_BN_CLICKED(IDC_BUTTON28,OnButton28)
ON_BN_CLICKED(IDC_BUTTON27,OnButton27)
ON_BN_CLICKED(IDC_BUTTON26,OnButton26)
ON_BN_CLICKED(IDC_BUTTON24,OnButton24)
ON_BN_CLICKED(IDC_BUTTON23,OnButton23)
ON_BN_CLICKED(IDC_BUTTON22,OnButton22)
ON_BN_CLICKED(IDC_RADIO2,OnRadio2)
ON_BN_CLICKED(IDC_RADIO4,OnRadio4)
ON_BN_CLICKED(IDC_RADIO3,OnRadio3)
ON_BN_CLICKED(IDC_BUTTON29,OnButton29)
ON_BN_CLICKED(IDC_BUTTON30,OnButton30)
ON_BN_CLICKED(IDC_BUTTON31,OnButton31)
ON_BN_CLICKED(IDC_BUTTON32,OnButton32)
ON_BN_CLICKED(IDC_BUTTON33,OnButton33)
ON_BN_CLICKED(IDC_BUTTON34,OnButton34)
ON_COMMAND(ID_MENUITEM32771,OnMenuitem32771)
ON_COMMAND(ID_MENUITEM32772,OnMenuitem32772)
//CMy2435Dlgmessagehandlers
BOOLCMy2435Dlg:
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
m_menu.LoadMenu(IDR_MENU1);
SetMenu(&
m_menu);
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.
HCURSORCMy2435Dlg:
OnQueryDragIcon()
return(HCURSOR)m_hIcon;
OnChangeEdit1()
IfthisisaRICHEDITcontrol,thecontrolwillnot
//sendthisnotificationunlessyouoverridetheCDialog:
//functionandcallCRichEditCtrl().SetEventMask()
//withtheENM_CHANGEflagORedintothemask.
Addyourcontrolnotificationhandlercodehere
OnButton11()
Addyourcontrolnotificationhandlercode
CStringstr;
GetDlgItem(IDC_BUTTON11)->
GetWindowText(str);
m_11=m_11+str;
UpdateData(FALSE);
OnButton10()
CStringstr;
GetDlgItem(IDC_BUTTON10)->
OnButton3()
{
if(jj==2)
OnButton13();
if(pd==1)
ii="
jj=1;
doublea,b,c;
a=atof(m_11);
b=atof(ii);
c=b+a;
ii.Format("
c);
m_11.Format("
UpdateData(FALSE);
pd++;
OnButton18()
a=atof(m_11);
a=a*pi/180;
c=sin(a);
m_11.Format("
OnButton12()
GetDlgItem(IDC_BUTTON12)->
OnButton6()
GetDlgItem(IDC_BUTTON6)->
OnButton7()
GetDlgItem(IDC_BUTTON7)->
OnButton9()
GetDlgItem(IDC_BUTTON9)->
OnButton4()
GetDlgItem(IDC_BUTTON4)->
m_11=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VC 课程设计 简单 计算器 设计