VC++課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第1頁
VC++課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第2頁
VC++課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第3頁
VC++課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第4頁
VC++課程設(shè)計(jì)實(shí)驗(yàn)報(bào)告_第5頁
已閱讀5頁,還剩24頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

《VC++課程設(shè)計(jì)》題目一:計(jì)算器學(xué)院:XXXXXXX班級(jí):XXXXXXX學(xué)號(hào):XXXXXXX姓名:XXXXXXX設(shè)計(jì)時(shí)間:XXXXXXX目錄:需求分析---------------------------------------------1課題設(shè)計(jì)內(nèi)容---------------------------------------1(1)課程設(shè)計(jì)基本流程------------------------------------------1(2)詳細(xì)設(shè)計(jì)說明------------------------------------------------2(3)設(shè)計(jì)流程圖---------------------------------------------------13(4)主要程序------------------------------------------------------14(5)運(yùn)行結(jié)果截圖-----------------------------------------------3.得意之處---------------------------------------------144.設(shè)計(jì)實(shí)踐過程中的收獲與體會(huì)------------------145.設(shè)計(jì)目前存在的問題--------------------------156.主要參考文獻(xiàn)--------------------------------------需求分析本課程主要是完成一個(gè)簡(jiǎn)單計(jì)算器的設(shè)計(jì),要求用戶在使用時(shí)可以準(zhǔn)確顯示整數(shù)及小數(shù),并準(zhǔn)確進(jìn)行加、減、乘、除、冪運(yùn)算,最后實(shí)現(xiàn)清零和退出。課程設(shè)計(jì)內(nèi)容課程設(shè)計(jì)基本流程:首先是進(jìn)行MFC基本對(duì)話框的創(chuàng)建,然后設(shè)計(jì)界面,界面上包括數(shù)字按鈕、等號(hào)按鈕、小數(shù)點(diǎn)按鈕、運(yùn)算按鈕、退出按鈕、清零按鈕和編輯框。并對(duì)各個(gè)按鈕和編輯框的地址、標(biāo)題進(jìn)行更改,綁定變量。最后,建立函數(shù),完成代碼的編寫,實(shí)現(xiàn)程序。詳細(xì)設(shè)計(jì)說明:完成MFC基本對(duì)話框的創(chuàng)建后,進(jìn)行界面設(shè)計(jì)。在界面的左上方設(shè)置編輯框,在其屬性里將地址改為result,綁定變量名稱為m_result,類型為String型。界面左面為數(shù)字鍵盤,右面為運(yùn)算符號(hào)。然后對(duì)兩部分分別進(jìn)行組框。對(duì)各個(gè)按鈕地址進(jìn)行名稱、地址更改。再建立類向?qū)?,在MessageMaps的Messages中選中BN_CLICKED,點(diǎn)擊確定,完成綁定變量。雙擊各個(gè)按鈕,建立函數(shù),添加代碼,實(shí)現(xiàn)數(shù)字按鈕的執(zhí)行與運(yùn)算符按鈕的執(zhí)行。以下是對(duì)應(yīng)控件:ID對(duì)應(yīng)控件IDC_11IDC_22IDC_33IDC_44IDC_55IDC_66IDC_77IDC_88IDC_99IDC_00IDC_dengyudengyuIDC_diandianIDC_jiajiaIDC_jianjianIDC_chengchengIDC_chuchuIDC_mifangmifangIDC_qinglingqinglingIDC_tuichutuichuIDC_resultresult設(shè)計(jì)流程圖:變量變量編輯框按鈕編輯框按鈕運(yùn)算數(shù)字運(yùn)算數(shù)字綁定變量綁定變量主要程序://計(jì)算器Dlg.cpp:implementationfile//#include"stdafx.h"#include"計(jì)算器.h"#include"計(jì)算器Dlg.h"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endifdoublei;//代表不同于m_result的變量,主要用于運(yùn)算intj;//定義整型變量j,并在輸入運(yùn)算符時(shí)賦值///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg: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//Implementationprotected: //{{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_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgdialogCMyDlg::CMyDlg(CWnd*pParent/*=NULL*/) :CDialog(CMyDlg::IDD,pParent){ //{{AFX_DATA_INIT(CMyDlg) m_result=_T(""); //}}AFX_DATA_INIT //NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32 m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);}voidCMyDlg::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDlg) DDX_Text(pDX,IDC_result,m_result); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CMyDlg,CDialog) //{{AFX_MSG_MAP(CMyDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_1,On1) ON_BN_CLICKED(IDC_2,On2) ON_BN_CLICKED(IDC_3,On3) ON_BN_CLICKED(IDC_4,On4) ON_BN_CLICKED(IDC_5,On5) ON_BN_CLICKED(IDC_6,On6) ON_BN_CLICKED(IDC_7,On7) ON_BN_CLICKED(IDC_8,On8) ON_BN_CLICKED(IDC_9,On9) ON_BN_CLICKED(IDC_0,On0) ON_BN_CLICKED(IDC_dengyu,Ondengyu) ON_BN_CLICKED(IDC_dian,Ondian) ON_BN_CLICKED(IDC_jia,Onjia) ON_BN_CLICKED(IDC_jian,Onjian) ON_BN_CLICKED(IDC_cheng,Oncheng) ON_BN_CLICKED(IDC_chu,Onchu) ON_BN_CLICKED(IDC_mifang,Onmifang) ON_BN_CLICKED(IDC_qingling,Onqingling) ON_BN_CLICKED(IDC_tuichu,Ontuichu) ON_EN_CHANGE(IDC_result,Onresult) //}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgmessagehandlersBOOLCMyDlg::OnInitDialog(){ CDialog::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); pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu); } } //Settheiconforthisdialog.Theframeworkdoesthisautomatically //whentheapplication'smainwindowisnotadialog SetIcon(m_hIcon,TRUE); //Setbigicon SetIcon(m_hIcon,FALSE); //Setsmallicon //TODO:Addextrainitializationhere returnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCMyDlg::OnSysCommand(UINTnID,LPARAMlParam){ if((nID&0xFFF0)==IDM_ABOUTBOX) { CAboutDlgdlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID,lParam); }}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCMyDlg::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); } else { CDialog::OnPaint(); }}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCMyDlg::OnQueryDragIcon(){ return(HCURSOR)m_hIcon;}voidCMyDlg::On1(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="1"; UpdateData(false);//數(shù)據(jù)的更新}voidCMyDlg::On2(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="2"; UpdateData(false);}voidCMyDlg::On3(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="3"; UpdateData(false);}voidCMyDlg::On4(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="4"; UpdateData(false);}voidCMyDlg::On5(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="5"; UpdateData(false);}voidCMyDlg::On6(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="6"; UpdateData(false);}voidCMyDlg::On7(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="7"; UpdateData(false);}voidCMyDlg::On8(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="8"; UpdateData(false);}voidCMyDlg::On9(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="9"; UpdateData(false);}voidCMyDlg::On0(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="0"; UpdateData(false);}voidCMyDlg::Ondengyu(){ //TODO:Addyourcontrolnotificationhandlercodehere doublek=0;switch(j) {case1:k=i+atof(m_result);break;case2:k=i-atof(m_result);break;case3:k=i*atof(m_result);break;case4:if(atof(m_result)!=0) {k=i/atof(m_result);break; }else {MessageBox("can'tusezero!"); } case7: { doublem=atof(m_result); k=1; for(m;m>=1;m--) { k=k*i; } break; } }charcRet[50];memset(cRet,0,50);sprintf(cRet,"%f",k);m_result=cRet;UpdateData(FALSE);//所有iQian與iType清0i=0;j=0;m_result="";return;}//等于號(hào)中定義了一個(gè)整形變量j,并在輸入運(yùn)算符的時(shí)候賦值,用switch語句選擇運(yùn)行的運(yùn)算,編程序進(jìn)行運(yùn)算并在編輯框顯示出來運(yùn)算結(jié)果。函數(shù)則不用點(diǎn)等于號(hào)直接顯示結(jié)果。voidCMyDlg::Ondian(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="."; UpdateData(false);}voidCMyDlg::Onjia(){ //TODO:Addyourcontrolnotificationhandlercodehere i=atof(m_result);//實(shí)現(xiàn)字符串到double的轉(zhuǎn)換 j=1; m_result+="+"; m_result=""; UpdateData(false);}voidCMyDlg::Onjian(){ //TODO:Addyourcontrolnotificationhandlercodehere i=atof(m_result); j=2; m_result+="-"; m_result=""; UpdateData(false);}voidCMyDlg::Oncheng(){ //TODO:Addyourcontrolnotificationhandlercodehere i=atof(m_result); j=3; m_result+="*"; m_result=""; UpdateData(false);}voidCMyDlg::Onchu(){ //TODO:Addyourcontrolnotificationhandlercodehere i=atof(m_result); j=4; m_result+="/"; m_result=""; UpdateData(false);}voidCMyDlg::Onmifang(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result+="^"; i=atof(m_result); m_result=""; j=7; UpdateData(false);}voidCMyDlg::Onqingling(){ //TODO:Addyourcontrolnotificationhandlercodehere m_result=""; UpdateData(false);//編輯框的清空}voidCMyDlg::Ontuichu(){ //TODO:AddyourcontrolnotificationhandlercodehereCDialog::OnCancel();//程序的退出}voidCMyDlg::Onresult(){ //TODO:IfthisisaRICHEDITcontrol,thecontrolwillnot //sendthisnotificationunlessyouoverridetheCDialog::OnInitDialog() //functionandcallCRichEditCtrl().SetEvent

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論