1、软件基础课程设计报告C语言计算器设计软件基础课程设计报告 一、需求分析系统目标:设计的计算器至少能够进行简单的四则运算和求倒数求反以及开方运算。主体功能:程序能实现:加,减,乘,除,开方,倒数等运算功能;还要实现数据的输入,输出,计算,显示及程序退出等功能。另外还可以实现多种科学计算的功能,如:三角函数的计算,弧度与角度间的转换,对数指数的计算等。开发环境:操作系统:Windows XP编程环境:MicrosoftVisualC+6.0 二、功能说明(1)包含的功能有:加、减、乘、除运算,开方、求倒数、三角函数、弧度与角度间的转换、对数指数的计算等功能。(2)计算器上数字09为一个控件数组,加
2、、减、乘、除为一个控件数组,其余为单一的控件。(3)给对话框添加菜单。(4)计算功能基本上是用系统内部函数。(5)程序可以能自动判断输入数据的正确性,保证不出现多于一个小数点、以0开头等不正常现象。(6)“CE”按钮可以清除所有已输入的数据从头计算,“Back”按钮可以实现退位功能。(7)能够显示时间、日期。三、详细设计(1)流程图(2)编辑资源(3)效果图四、程序附录计算器Dlg.cpp :#include stdafx.h#include 计算器.h#include 计算器Dlg.h#include math.h#includeFirstDlg.h#include #define PI 3
3、.14;#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic: CAboutDlg();/ Dialog Data /AFX_DATA(CAboutDlg) enum IDD = IDD_ABOUTBOX ; /AFX_DATA / ClassWizard generated virtual function override
4、s /AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support /AFX_VIRTUAL/ Implementationprotected: /AFX_MSG(CAboutDlg) /AFX_MSG DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD) /AFX_DATA_INIT(CAboutDlg) /AFX_DATA_INITvoid CAboutDlg:DoDa
5、taExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CAboutDlg) /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog) /AFX_MSG_MAP(CAboutDlg) / No message handlers /AFX_MSG_MAPEND_MESSAGE_MAP()/ CMyDlg dialogCMyDlg:CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyDlg:IDD, pParent) /AFX
6、_DATA_INIT(CMyDlg) m_result = 0.0; /AFX_DATA_INIT / Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CMyDlg:DoDataExchange(CDataExchange* pDX) CDialog:DoDataExchange(pDX); /AFX_DATA_MAP(CMyDlg) DDX_Control(pDX, IDC_EDIT1, m_EDIT
7、); DDX_Text(pDX, IDC_EDIT1, m_result); /AFX_DATA_MAPBEGIN_MESSAGE_MAP(CMyDlg, CDialog) /AFX_MSG_MAP(CMyDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_NUM0, OnNum0) ON_BN_CLICKED(IDC_NUM1, OnNum1) ON_BN_CLICKED(IDC_NUM2, OnNum2) ON_BN_CLICKED(IDC_NUM3, OnNum3) ON_BN_CLI
8、CKED(IDC_NUM4, OnNum4) ON_BN_CLICKED(IDC_NUM5, OnNum5) ON_BN_CLICKED(IDC_NUM6, OnNum6) ON_BN_CLICKED(IDC_NUM7, OnNum7) ON_BN_CLICKED(IDC_NUM8, OnNum8) ON_BN_CLICKED(IDC_NUM9, OnNum9) ON_BN_CLICKED(IDC_DOT, OnDot) ON_BN_CLICKED(IDC_CE, OnCe) ON_BN_CLICKED(IDC_jia, Onjia) ON_BN_CLICKED(IDC_jian, Onjia
9、n) ON_BN_CLICKED(IDC_cheng, Oncheng) ON_BN_CLICKED(IDC_chu, Onchu) ON_BN_CLICKED(IDC_dengyu, Ondengyu) ON_BN_CLICKED(IDC_daoshu, Ondaoshu) ON_BN_CLICKED(IDC_zhengfu, Onzhengfu) ON_BN_CLICKED(IDC_BACKSPACE, OnBackspace) ON_BN_CLICKED(IDC_Ln, OnLn) ON_BN_CLICKED(IDC_log, Onlog) ON_BN_CLICKED(IDC_RADIO
10、2, OnRadio2) ON_BN_CLICKED(IDC_RADIO1, OnRadio1) ON_BN_CLICKED(IDC_sqrt, Onsqrt) ON_BN_CLICKED(IDC_sin, Onsin) ON_BN_CLICKED(IDC_cos, Oncos) ON_BN_CLICKED(IDC_tan, Ontan) ON_BN_CLICKED(IDC_pingfang, Onpingfang) ON_BN_CLICKED(IDC_lifang, Onlifang) ON_BN_CLICKED(IDC_mi, Onmi) ON_BN_CLICKED(IDC_Exp, On
11、Exp) ON_BN_CLICKED(IDC_10demi, On10demi) ON_BN_CLICKED(IDC_jiecheng, Onjiecheng) ON_COMMAND(ID_TIME, OnTime) ON_COMMAND(ID_DATE, OnDate) ON_COMMAND(ID_EXIT, OnExit) ON_COMMAND(ID_HELP, OnHelp) /AFX_MSG_MAPEND_MESSAGE_MAP()/ CMyDlg message handlersBOOL CMyDlg:OnInitDialog() CDialog:OnInitDialog(); /
12、Add About. menu item to system menu. / IDM_ABOUTBOX must be in the system command range. ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR); pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); / Set the icon for this dialog. The framework does this au
13、tomatically / when the applications main window is not a dialog SetIcon(m_hIcon, TRUE); / Set big icon SetIcon(m_hIcon, FALSE); / Set small icon / TODO: Add extra initialization here CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1); UpdateData(FALSE); quan2=1; dotflag=0; numflag=0; return TRUE; /
14、return TRUE unless you set the focus to a controlvoid CMyDlg:OnSysCommand(UINT nID, LPARAM lParam) if (nID & 0xFFF0) = IDM_ABOUTBOX) CAboutDlg dlgAbout; dlgAbout.DoModal(); else CDialog:OnSysCommand(nID, lParam); / If you add a minimize button to your dialog, you will need the code below/ to draw th
15、e icon. For MFC applications using the document/view model,/ this is automatically done for you by the framework.void CMyDlg:OnPaint() if (IsIconic() CPaintDC dc(this); / device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); / Center icon in client rectangle int cx
16、Icon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; / Draw the icon dc.DrawIcon(x, y, m_hIcon); else CDialog:OnPaint(); / The system calls this to obtain the
17、 cursor to display while the user drags/ the minimized window.HCURSOR CMyDlg:OnQueryDragIcon() return (HCURSOR) m_hIcon;void CMyDlg:OnNum0() UpdateData(); if(dotflag) quan2*=10; m_result+=0/(double)quan2; else if(numflag) m_result=m_result*10+0; else m_result=0; numflag=1; UpdateData(FALSE); void CM
18、yDlg:OnNum1() UpdateData(); if(dotflag) quan2*=10; m_result+=1/(double)quan2; else if(numflag) m_result=m_result*10+1; else m_result=1; numflag=1; UpdateData(FALSE);void CMyDlg:OnNum2() UpdateData(); if(dotflag) quan2*=10; m_result+=2/(double)quan2; else if(numflag) m_result=m_result*10+2; else m_re
19、sult=2; numflag=1; UpdateData(FALSE); void CMyDlg:OnNum3() UpdateData(); if(dotflag) quan2*=10; m_result+=3/(double)quan2; else if(numflag) m_result=m_result*10+3; else m_result=3; numflag=1; UpdateData(FALSE); void CMyDlg:OnNum4() UpdateData(); if(dotflag) quan2*=10; m_result+=4/(double)quan2; else
20、 if(numflag) m_result=m_result*10+4; else m_result=4; numflag=1; UpdateData(FALSE); void CMyDlg:OnNum5() UpdateData(); if(dotflag) quan2*=10; m_result+=5/(double)quan2; else if(numflag) m_result=m_result*10+5; else m_result=5; numflag=1; UpdateData(FALSE); void CMyDlg:OnNum6() UpdateData(); if(dotfl
21、ag) quan2*=10; m_result+=6/(double)quan2; else if(numflag) m_result=m_result*10+6; else m_result=6; numflag=1; UpdateData(FALSE); void CMyDlg:OnNum7() UpdateData(); if(dotflag) quan2*=10; m_result+=7/(double)quan2; else if(numflag) m_result=m_result*10+7; else m_result=7; numflag=1; UpdateData(FALSE
22、); void CMyDlg:OnNum8() UpdateData(); if(dotflag) quan2*=10; m_result+=8/(double)quan2; else if(numflag) m_result=m_result*10+8; else m_result=8; numflag=1; UpdateData(FALSE); void CMyDlg:OnNum9() UpdateData(); if(dotflag) quan2*=10; m_result+=9/(double)quan2; else if(numflag) m_result=m_result*10+9
23、; else m_result=9; numflag=1; UpdateData(FALSE); void CMyDlg:OnDot() UpdateData();dotflag=1;m_result+=0.0;UpdateData(FALSE); void CMyDlg:OnCe() UpdateData();m_EDIT.SetSel(0,-1);m_EDIT.ReplaceSel();m_result=0;num1=0;num2=0;numflag=0;dotflag=0;quan2=1;UpdateData(FALSE); void CMyDlg:Onjia() UpdateData(
24、);num1=m_result;cal=+;numflag=0;dotflag=0;quan2=1; void CMyDlg:Onjian() UpdateData();num1=m_result;cal=-;numflag=0;dotflag=0;quan2=1; void CMyDlg:Oncheng() UpdateData();num1=m_result;cal=*;numflag=0;dotflag=0;quan2=1; void CMyDlg:Onchu() UpdateData();num1=m_result;cal=/;numflag=0;dotflag=0;quan2=1;
25、void CMyDlg:Ondengyu() UpdateData();num2=m_result;switch(cal) case+:m_result=num1+num2;break;case-:m_result=num1-num2;break;case*:m_result=num1*num2;break;case/:m_result=num1/num2;break;casex:m_result=pow(num1,num2);break;numflag=0;dotflag=0;quan2=1;UpdateData(FALSE); void CMyDlg:Ondaoshu() UpdateDa
26、ta();m_result=1/m_result;numflag=0;dotflag=0;quan2=1;UpdateData(FALSE); void CMyDlg:Onzhengfu() UpdateData();m_result=0-m_result;UpdateData(FALSE); void CMyDlg:OnBackspace() UpdateData();static int dotquan=quan2;long temp;if(dotflag&numflag) if(dotquan=10) temp=(long)(m_result*dotquan); m_result=(double)(temp/10); dotquan/=10; m_result=m_result/dotquan; else /UpdateData(); if(numflag&m_result) m_result=(long)m_result/10; UpdateData(FALSE); void CMyDlg:OnLn() UpdateData();m_result=log(m_result);numflag=0
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1