




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、軟件基礎(chǔ)課程設(shè)計(jì)報(bào)告 一、需求分析系統(tǒng)目標(biāo):設(shè)計(jì)的計(jì)算器至少能夠進(jìn)行簡(jiǎn)單的四則運(yùn)算和求倒數(shù)求反以及開(kāi)方運(yùn)算。主體功能:程序能實(shí)現(xiàn):加,減,乘,除,開(kāi)方,倒數(shù)等運(yùn)算功能;還要實(shí)現(xiàn)數(shù)據(jù)的輸入,輸出,計(jì)算,顯示及程序退出等功能。另外還可以實(shí)現(xiàn)多種科學(xué)計(jì)算的功能,如:三角函數(shù)的計(jì)算,弧度與角度間的轉(zhuǎn)換,對(duì)數(shù)指數(shù)的計(jì)算等。開(kāi)發(fā)環(huán)境:操作系統(tǒng):windows xp編程環(huán)境:microsoftvisualc+6.0 二、功能說(shuō)明(1)包含的功能有:加、減、乘、除運(yùn)算,開(kāi)方、求倒數(shù)、三角函數(shù)、弧度與角度間的轉(zhuǎn)換、對(duì)數(shù)指數(shù)的計(jì)算等功能。(2)計(jì)算器上數(shù)字09為一個(gè)控件數(shù)組,加、減、乘、除為一個(gè)控件數(shù)組,其余為單
2、一的控件。(3)給對(duì)話(huà)框添加菜單。(4)計(jì)算功能基本上是用系統(tǒng)內(nèi)部函數(shù)。(5)程序可以能自動(dòng)判斷輸入數(shù)據(jù)的正確性,保證不出現(xiàn)多于一個(gè)小數(shù)點(diǎn)、以0開(kāi)頭等不正?,F(xiàn)象。(6)“ce”按鈕可以清除所有已輸入的數(shù)據(jù)從頭計(jì)算,“back”按鈕可以實(shí)現(xiàn)退位功能。(7)能夠顯示時(shí)間、日期。三、詳細(xì)設(shè)計(jì)(1)流程圖創(chuàng)建工程(創(chuàng)建一個(gè)對(duì)話(huà)框應(yīng)用程序)設(shè)計(jì)對(duì)話(huà)框界面設(shè)置各控件屬性為編輯框連接成員變量為類(lèi)添加數(shù)據(jù)成員,初始化構(gòu)造函數(shù)。為所有按鈕添加事件對(duì)類(lèi)添加成員函數(shù)(更新編輯框)并進(jìn)行實(shí)現(xiàn)實(shí)現(xiàn)對(duì)各按鈕事件的實(shí)現(xiàn)(2)編輯資源(3)效果圖四、程序附錄計(jì)算器dlg.cpp :#include stdafx.h#incl
3、ude 計(jì)算器.h#include 計(jì)算器dlg.h#include math.h#includefirstdlg.h#include #define pi 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
4、 = idd_aboutbox ;/afx_data/ classwizard generated virtual function overrides/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(cabout
5、dlg:idd)/afx_data_init(caboutdlg)/afx_data_initvoid caboutdlg:dodataexchange(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(
6、cwnd* pparent /*=null*/): cdialog(cmydlg:idd, pparent)/afx_data_init(cmydlg)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
7、_data_map(cmydlg)ddx_control(pdx, idc_edit1, m_edit);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)
8、on_bn_clicked(idc_num3, onnum3)on_bn_clicked(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, onji
9、a)on_bn_clicked(idc_jian, onjian)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)o
10、n_bn_clicked(idc_radio2, 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_clicke
11、d(idc_exp, onexp)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 aut
13、omatically/ when the applications main window is not a dialogseticon(m_hicon, true);/ set big iconseticon(m_hicon, false);/ set small icon/ todo: add extra initialization herecheckradiobutton(idc_radio1,idc_radio2,idc_radio1);updatedata(false); quan2=1; dotflag=0; numflag=0; return true; / return tr
14、ue unless you set the focus to a controlvoid 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
15、 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 paintingsendmessage(wm_iconerasebkgnd, (wparam) dc.getsafehdc(), 0);/ center icon in client rectangleint cxicon = getsystemmet
16、rics(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 icondc.drawicon(x, y, m_hicon);elsecdialog:onpaint();/ the system calls this to obtain the cursor to display while the
17、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;elseif(numflag)m_result=m_result*10+0;else m_result=0; numflag=1;updatedata(false);void cmydlg:onnum1() updatedata();if(dotflag)q
18、uan2*=10;m_result+=1/(double)quan2;elseif(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;elseif(numflag)m_result=m_result*10+2;else m_result=2; numflag=1;updatedata(false);void cmydlg:onnum3
19、() updatedata();if(dotflag)quan2*=10;m_result+=3/(double)quan2;elseif(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;elseif(numflag)m_result=m_result*10+4;else m_result=4; numflag=1;updateda
20、ta(false);void cmydlg:onnum5() updatedata();if(dotflag)quan2*=10;m_result+=5/(double)quan2;elseif(numflag)m_result=m_result*10+5;else m_result=5; numflag=1;updatedata(false);void cmydlg:onnum6() updatedata();if(dotflag)quan2*=10;m_result+=6/(double)quan2;elseif(numflag)m_result=m_result*10+6;else m_
21、result=6; numflag=1;updatedata(false);void cmydlg:onnum7() updatedata();if(dotflag)quan2*=10;m_result+=7/(double)quan2;elseif(numflag)m_result=m_result*10+7;else m_result=7; numflag=1;updatedata(false);void cmydlg:onnum8() updatedata();if(dotflag)quan2*=10;m_result+=8/(double)quan2;elseif(numflag)m_
22、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;elseif(numflag)m_result=m_result*10+9;else m_result=9; numflag=1;updatedata(false);void cmydlg:ondot() updatedata();dotflag=1;m_result+=0.0;updatedata(fa
23、lse);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();num1=m_result;cal=+;numflag=0;dotflag=0;quan2=1;void cmydlg:onjian() updatedata();num1=m_result;cal=-;numflag=0;dotflag
24、=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;void cmydlg:ondengyu() updatedata();num2=m_result;switch(cal)case+:m_result=num1+num2;break;case-:m_result=num1-num2;break;ca
25、se*: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() updatedata();m_result=1/m_result;numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:onzhengfu() updatedata();m_result=0-m_result
26、;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(fal
27、se);void cmydlg:onln() updatedata();m_result=log(m_result);numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:onlog() updatedata();m_result=log(m_result)/log(10);numflag=0;dotflag=0;quan2=1;updatedata(false);void cmydlg:onradio2() m_isdegree=1;i=1;updatedata(true);void cmydlg:onradio1() m_isd
28、egree=0;i=(2*3.1415926)/360;updatedata(false);void cmydlg:onsqrt()updatedata(); if(m_result0)messagebox(輸入無(wú)效!);return;m_result = sqrt(m_result);updatedata(false);void cmydlg:onsin() m_result=sin(m_result*i);updatedata(false);void cmydlg:oncos() m_result=cos(m_result*i);updatedata(false);void cmydlg:ontan() m_
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 ISO/TR 41019:2024 EN Facility managements role in sustainability,resilience and adaptability
- 2025年度校園基礎(chǔ)設(shè)施裝修改造工程合同
- 2025年度房產(chǎn)居間合同:旅游地產(chǎn)項(xiàng)目開(kāi)發(fā)合作協(xié)議
- 2025年度標(biāo)前協(xié)議模板:XX基礎(chǔ)設(shè)施建設(shè)合作前期協(xié)議
- 2025年度酒店客房預(yù)訂客戶(hù)投訴處理合同
- 2025年度博物館安防監(jiān)控設(shè)備采購(gòu)與安裝合同
- 學(xué)期班級(jí)教學(xué)活動(dòng)工作任務(wù)計(jì)劃
- 學(xué)期閱讀推廣活動(dòng)計(jì)劃
- 社區(qū)文藝活動(dòng)計(jì)劃
- 生物教育在新時(shí)代的挑戰(zhàn)與機(jī)遇計(jì)劃
- 2024全國(guó)各省高考詩(shī)歌鑒賞真題及解析
- 高考日語(yǔ)閱讀理解練習(xí)2篇-高考日語(yǔ)復(fù)習(xí)
- 印刷基礎(chǔ)知識(shí)培訓(xùn)資料
- NB/T 11536-2024煤礦帶壓開(kāi)采底板井下注漿加固改造技術(shù)規(guī)范
- 2024-2025學(xué)年人教版五年級(jí)(上)英語(yǔ)寒假作業(yè)(一)
- 【課件】九年級(jí)化學(xué)下冊(cè)(人教版2024)-【新教材解讀】義務(wù)教育教材內(nèi)容解讀課件
- 醫(yī)院臨床科研大數(shù)據(jù)平臺(tái)方案
- 2024年北京市中考生物真題卷及答案解析
- GA/T 761-2024停車(chē)庫(kù)(場(chǎng))安全管理系統(tǒng)技術(shù)要求
- (2024)湖南省公務(wù)員考試《行測(cè)》真題卷及答案解析
- 2025年部編教材的網(wǎng)絡(luò)培訓(xùn)心得體會(huì)
評(píng)論
0/150
提交評(píng)論