C++課程設(shè)計(jì)檢測版 2_第1頁
C++課程設(shè)計(jì)檢測版 2_第2頁
C++課程設(shè)計(jì)檢測版 2_第3頁
C++課程設(shè)計(jì)檢測版 2_第4頁
C++課程設(shè)計(jì)檢測版 2_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、C+課程設(shè)計(jì)報(bào)告(2013)面向?qū)ο蟪绦蛟O(shè)計(jì)(VC+)課程設(shè)計(jì)報(bào)告題目:基于MFC的科學(xué)計(jì)算器設(shè)計(jì)與實(shí)現(xiàn)班級:軟件工程12-02 姓名:于佳輝 組長:常明鑫 成員:常明鑫 于雷鳴 于佳輝 郭大銘 時(shí)間:2013-6-27 地點(diǎn):實(shí)驗(yàn)1#101 1計(jì)算器的設(shè)計(jì)與實(shí)現(xiàn)1課程設(shè)計(jì)內(nèi)容課題名稱:計(jì)算器的實(shí)現(xiàn)說明:實(shí)現(xiàn)一個(gè)計(jì)算器。要求: 1)用“計(jì)算器”的標(biāo)準(zhǔn)視圖執(zhí)行簡單的計(jì)算。2)用其科學(xué)型視圖執(zhí)行簡易的科學(xué)計(jì)算。2 系統(tǒng)需求分析2.1 系統(tǒng)目標(biāo)我們在學(xué)習(xí)生活中,常會(huì)遇到一些繁雜的數(shù)值運(yùn)算,這時(shí)候我們就必須用到科學(xué)計(jì)算器,所以便著手開發(fā)了這個(gè)計(jì)算器程序,以便用于自己的學(xué)習(xí)工作。要計(jì)算功能有以下幾個(gè)方面

2、:加法,減法,乘法,除法。2.2 主體功能1. 十進(jìn)制數(shù)的加、減、乘、除等簡單計(jì)算。2. 界面設(shè)有清空按鈕,方便使用。2.3 開發(fā)環(huán)境VC+ 6.03 系統(tǒng)概要設(shè)計(jì)3.1 系統(tǒng)功能劃分表3-1 系統(tǒng)功能表序號文件名主要功能備注1+加法求和兩個(gè)操作數(shù)2-減法求差兩個(gè)操作數(shù)3*乘法求積兩個(gè)操作數(shù)4/除法求商兩個(gè)操作數(shù) 假設(shè)執(zhí)行操作“+”,先輸入一個(gè)數(shù),再輸入“+”,再輸入另一個(gè)數(shù),最后輸入“+”。整個(gè)功能“+”就執(zhí)行完畢。附錄1 源程序清單/ 計(jì)算器Dlg.cpp : implementation file/#include stdafx.h#include 計(jì)算器.h#include 計(jì)算器Dl

3、g.h#include#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 overri

4、des/AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:/AFX_MSG(CAboutDlg)/AFX_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)/AFX_DATA_INIT(CAboutDlg)/AFX_DATA_INITvoid CAboutDlg:DoDataExcha

5、nge(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_DATA_INIT(CMyD

6、lg)m_number1 = 0.0;m_number2 = 0.0;m_result = 0.0;/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CMyDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CMyDlg)DDX_Control(pDX, IDC_EDI

7、T3, m_CResult);DDX_Text(pDX, IDC_EDIT1, m_number1);DDX_Text(pDX, IDC_EDIT2, m_number2);DDX_Text(pDX, IDC_EDIT3, m_result);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CMyDlg, CDialog)/AFX_MSG_MAP(CMyDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)ON_EN_CHANGE(IDC_EDIT

8、2, OnChangeEdit2)ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)ON_BN_CLICKED(IDC_BUTTON9, OnButton9)ON_BN_CLICKED(IDC_BUTTON8, OnButton8)ON_BN_CLICKED(IDC_BUTTON7, OnButton7)ON_BN_CLICKED(IDC_BUTTON6, OnButton6)ON_BN_CLICKED(IDC_BUTTON5, OnButton5)ON_BN_CLICKED(IDC_BUTTON4, OnButton4)ON_BN_CLICKED(IDC_BUTTO

9、N3, OnButton3)ON_BN_CLICKED(IDC_BUTTON2, OnButton2)ON_BN_CLICKED(IDC_BUTTON1, OnButton1)ON_BN_CLICKED(IDC_BUTTON0, OnButton0)ON_BN_CLICKED(IDC_BUTTONjia, OnBUTTONjia)ON_BN_CLICKED(IDC_BUTTONjian, OnBUTTONjian)ON_BN_CLICKED(IDC_BUTTONcheng, OnBUTTONcheng)ON_BN_CLICKED(IDC_BUTTONchu, OnBUTTONchu)ON_EN

10、_SETFOCUS(IDC_EDIT1, OnSetfocusEdit1)ON_EN_SETFOCUS(IDC_EDIT2, OnSetfocusEdit2)ON_BN_CLICKED(IDC_BUTTONresult, OnBUTTONresult)ON_BN_CLICKED(IDC_BUTTON10, OnButton10)/AFX_MSG_MAPEND_MESSAGE_MAP()BOOL CMyDlg:OnInitDialog()CDialog:OnInitDialog();/ Add About. menu item to system menu./ IDM_ABOUTBOX must

11、 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 automatically/ when the applications main window is not a dial

12、ogSetIcon(m_hIcon, true);/ Set big iconSetIcon(m_hIcon, false);/ Set small icon/ TODO: Add extra initialization herereturn true; / return true unless you set the focus to a controlint nEditFlag=0;void CMyDlg:OnLButtonDown(UINT nFlags, CPoint point)this-SetFocus();nEditFlag=0;CDialog:OnLButtonDown(nF

13、lags,point);void CMyDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam);/ If you add a minimize button to your dialog, you will need the code below/ to draw the icon. For MFC applications using the docu

14、ment/view model,/ this is automatically done for you by the framework.void CMyDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon =

15、 GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icondc.DrawIcon(x, y, m_hIcon);elseCRect rc;GetClientRect( &rc );CPaintDC dc(this);dc.FillSolidRect(&rc, RGB(255,235,205); CDialog:OnPaint(); / The

16、 system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CMyDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;void CMyDlg:OnChangeEdit1() /nEditFlag=1;/ TODO: If this is a RICHEDIT control, the control will not/ send this notification unless you override the

17、CDialog:OnInitDialog()/ function and call CRichEditCtrl().SetEventMask()/ with the ENM_CHANGE flag ORed into the mask./ TODO: Add your control notification handler code herevoid CMyDlg:OnChangeEdit2() / TODO: If this is a RICHEDIT control, the control will not/ send this notification unless you over

18、ride the CDialog:OnInitDialog()/ function and call CRichEditCtrl().SetEventMask()/ with the ENM_CHANGE flag ORed into the mask./ TODO: Add your control notification handler code here/nEditFlag=2;void CMyDlg:OnChangeEdit3() / TODO: If this is a RICHEDIT control, the control will not/ send this notifi

19、cation unless you override the CDialog:OnInitDialog()/ function and call CRichEditCtrl().SetEventMask()/ with the ENM_CHANGE flag ORed into the mask./ TODO: Add your control notification handler code here數(shù)字按鈕:void CMyDlg:OnButton1() UpdateData(true);/將關(guān)聯(lián)變量的值更新到控件顯示if (nEditFlag=1)if (point_num=1) te

20、mp1=m_number1;m_number1=(1/pow(float)10,pointnum); m_number1=temp1+m_number1; pointnum=pointnum+1;elsem_number1=m_number1*10+1;else if(nEditFlag=2)if (point_num=1) temp1=m_number2;m_number2=(1/pow(float)10,p_pointnum); m_number2=temp1+m_number2; p_pointnum=p_pointnum+1;else m_number2=m_number2*10+1;

21、UpdateData(false);/ TODO: Add your control notification handler code here加法:void CMyDlg:OnBUTTONjia() UpdateData();double n_result;n_result=m_number1+m_number2;m_result=n_result;char sz20;sprintf(sz,%f,n_result);m_CResult.SetWindowText(sz);/SetWindowText是一個(gè)Windows API函數(shù)。該函數(shù)改變指定窗口的標(biāo)題欄的文本內(nèi)容/ TODO: Add

22、 your control notification handler code here減法:void CMyDlg:OnBUTTONjian() UpdateData();double n_result;n_result=m_number1-m_number2;m_result=n_result;char sz20;sprintf(sz,%f,n_result);m_CResult.SetWindowText(sz);/ TODO: Add your control notification handler code here乘法:void CMyDlg:OnBUTTONcheng() Up

23、dateData();double n_result;n_result=m_number1*m_number2;m_result=n_result;char sz20;sprintf(sz,%f,n_result);m_CResult.SetWindowText(sz);/ TODO: Add your control notification handler code here除法:void CMyDlg:OnBUTTONchu() UpdateData();double n_result;n_result=m_number1/m_number2;m_result=n_result;char sz20;sprintf(sz,%f,n_result);m_CResult.SetWindowText(sz);/ TODO: Add your control notification handler code here第一個(gè)輸入框:void CMyDlg:OnSetfocusEdit1() nEditFla

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論