【正文】
試1 測(cè)試能否把一個(gè)中綴表達(dá)式轉(zhuǎn)換為后綴表達(dá)式2 能否正確計(jì)算后綴表達(dá)式的值3 進(jìn)制轉(zhuǎn)換能否正常工作測(cè)試結(jié)果:1 子程序能正確轉(zhuǎn)換得到后綴表達(dá)式2 子程序可以進(jìn)行計(jì)算,但當(dāng)遇到非法輸入時(shí)程序自動(dòng)終止3 進(jìn)制轉(zhuǎn)換可以進(jìn)行,但遇到負(fù)數(shù)時(shí)轉(zhuǎn)換的結(jié)果每個(gè)數(shù)字前都有負(fù)號(hào)軟件調(diào)試和修改記錄:針對(duì)上述問(wèn)題對(duì)軟件進(jìn)行一些局部改動(dòng)。計(jì)算器可以處理表達(dá)式運(yùn)算,可以進(jìn)行數(shù)制轉(zhuǎn)換,和一些常見(jiàn)的數(shù)學(xué)計(jì)算如開(kāi)方,取平方求對(duì)數(shù),正弦,余弦等。但從整體上已經(jīng)達(dá)到了要求可以進(jìn)行更高級(jí)的計(jì)算。3 如果要進(jìn)行開(kāi)方、平方、取對(duì)數(shù)、正余弦、進(jìn)制轉(zhuǎn)換等操作時(shí),先輸入表達(dá)式再按相應(yīng)的按鍵即可得出結(jié)果。實(shí)驗(yàn)討論:該計(jì)算器的核心部分在于表達(dá)式的解析與計(jì)算上。如二叉樹(shù)也可以實(shí)現(xiàn)表達(dá)式的解析與計(jì)算。程序功能是否還可以繼續(xù)增加?比如階乘運(yùn)算,進(jìn)制轉(zhuǎn)換可以處理浮點(diǎn)數(shù),可以進(jìn)行矩陣的加減乘除運(yùn)算,求函數(shù)的導(dǎo)數(shù)等一系列操作,這樣該計(jì)算器的級(jí)別將會(huì)更高。雖然這算不上項(xiàng)目但它還是提供了一個(gè)實(shí)戰(zhàn)的機(jī)會(huì)。以前總會(huì)用一個(gè)工程,現(xiàn)在可以用三個(gè)。基本上掌握了MFC程序開(kāi)發(fā)的環(huán)節(jié)過(guò)程這對(duì)以后視窗編程有很大的幫助,在此基礎(chǔ)上可以自己開(kāi)方一些小程序,找到了自我提高的方法。此外這次編程給我了許多啟示,自己到底該怎么樣去學(xué)習(xí)。如計(jì)算器開(kāi)始是學(xué)到一點(diǎn)動(dòng)態(tài)鏈接庫(kù),想辦法去運(yùn)用它。由此學(xué)到的知識(shí)自己想辦法去運(yùn)用,用在你當(dāng)前思考的問(wèn)題上。此次實(shí)驗(yàn),應(yīng)用了堆棧這一存儲(chǔ)結(jié)構(gòu)來(lái)解析表達(dá)式,并用動(dòng)態(tài)鏈接庫(kù)技術(shù)進(jìn)行導(dǎo)出。參考文獻(xiàn):[1] :清華大學(xué)出版社,1999[2] . 西安:交通大學(xué)出版社,2004[3] 羅斌 Visual C++編程技巧 北京:中國(guó)水利水電出版社,2005附錄:源程序代碼// : implementation fileinclude include include includeifdef _DEBUGdefine new DEBUG_NEWundef THIS_FILEstatic char THIS_FILE[] = __FILE__。///////判斷優(yōu)先級(jí)的函數(shù) extern int Precedence(char op)。///////計(jì)算后綴表達(dá)式的值///////////////////////extern double pute(char *str)。// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog{public: CAboutDlg()。 //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX)。CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){ //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT}void CAboutDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX)。 //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()LoadIcon(IDR_MAINFRAME)。 //{{AFX_DATA_MAP(CCalcDlg) DDX_Text(pDX, IDC_EDIT1, m_edit1)。 // Add About... menu item to system menu. // IDM_ABOUTBOX must be in the system mand range. ASSERT((IDM_ABOUTBOX amp。 ASSERT(IDM_ABOUTBOX 0xF000)。 if (pSysMenu != NULL) { CString strAboutMenu。 if (!()) { pSysMenuAppendMenu(MF_SEPARATOR)。 } } // Set the icon for this dialog. The framework does this automatically // when the application39。 // Set big icon SetIcon(m_hIcon, FALSE)。 // return TRUE unless you set the focus to a control}void CCalcDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID amp。 ()。 }}// If you add a minimize button to your dialog, you will need the code below// to draw the icon. For MFC applications using the document/view model,// this is automatically done for you by the framework.void CCalcDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this)。 // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON)。 CRect rect。rect)。 int y = (() cyIcon + 1) / 2。 } else { CDialog::OnPaint()。}void CCalcDlg::OnNO1() { // TODO: Add your control notification handler code here m_edit1+=1。}void CCalcDlg::OnNO2() { // TODO: Add your control notification handler code here m_edit1+=2。}void CCalcDlg::OnNO3() { // TODO: Add your control notification handler code here m_edit1+=3。}void CCalcDlg::OnNO4() { // TODO: Add your control notification handler code here m_edit1+=4。}void CCalcDlg::OnNO5() { // TODO: Add your control notification handler code here m_edit1+=5。}void CCalcDlg::OnNO6() { // TODO: Add your control notification handler code here m_edit1+=6。}void CCalcDlg::OnNO7() { // TODO: Add your control notification handler code here m_edit1+=7。}void CCalcDlg::OnNO8() { // TODO: Add your control notification handler code here m_edit1+=8。}void CCalcDlg::OnN0() { // TODO: Add your control notification handler code here m_edit1+=0。}void CCalcDlg::OnNO9() { m_edit1+=9。 }void CCalcDlg::OnDOT() { // TODO: Add your control notification handler code here m_edit1+=.。}void CCalcDlg::OnADD() { // TODO: Add your control notification handler code here m_edit1+=+。}void CCalcDlg::OnDENG() { // TODO: Add your control notification handler code here char s[70],s2[70],buffer1[20]。CString str1,str2,str3。 str1=m_edit1。 s[sizeof(s)1]=39。 if((1)==+||s[0]==39。||s[0]==39。||s[0]==39。||s[0]==39。) {( \n抱 歉!\n不 能 處 理 輸 入 的 表 達(dá) 式! \n請(qǐng) 重 新 輸 入)。 m_edit1=_T( )。 } for(i=0。\039。+39。39。*39。/39。amp。+39。39。*39。/39。 MessageBox(str2,馮凱溫馨提示)。 goto label。 if(change(s,s2)==0) { ( \n輸 入 的 表 達(dá) 式 錯(cuò) 誤 ! \n請(qǐng) 重 新 輸 入)。 m_edit1=_T( )。} r=pute(s2)。 MessageBox(str2,馮凱溫馨提示)。 goto label。 for(i=1。\039。.39。amp。\039。\039。 label: UpdateData(false)。UpdateData(false)。 UpdateData(false)。 UpdateData(false)。 UpdateData(false)。CString str1,str2,str3。 str1=m_edit1。 str3=str1。 MessageBox(str2,馮凱溫馨提示)。 goto label。 //調(diào)用等號(hào)子過(guò)程 x=strtod(m_edit1,amp。 if(x0) { ( \n負(fù) 數(shù) 不 能 開(kāi) 方 ...... )。 m_edit1=_T( )。 } y=sqrt(x)。 for(i=0。\039。.39。amp。\039。\039。label: UpdateData(false)。CString str1,str2,str3。 str1=m_edit1。 str3=str1。 MessageBox(str2,馮凱溫馨提示)。 goto label。 //調(diào)用等號(hào)子過(guò)程 x=strtod(m_edit1,amp。 y=pow(x,2)。 for(i=0。\039。.39。amp。\039。\039。label: UpdateData(false)。CString str1,str2,str3。 str1=m_edit1。 str3=str1。 MessageBox(str2,馮凱溫馨提示)。 str2=_T( )。} } OnDENG()。s1)。 MessageBox(str2,馮凱溫馨提示)。 goto label。 _gcvt(y,6,buffer1)。buffer1[i]!=39。i++) { if(buffer1[i]==39。amp。buffer1[i+1]==39。) buffer1[i]=39。} m_edit1=(CString)buffer1。}void CCalcDlg::Ondelete() { // TODO: Add your control notification handler code here CString str1,str2,str3。 str1=(()1)。 UpdateData(false)。 UpdateData(false)。 UpdateData(false)。int i=0,j=0,k=0。 char *s1,buffer1[35]。 str2=str1。 if((1)==B||(1)==o||(1)==H||(1)==B||(1)==o||(1)==H) { { ( \n! 不 能 將 進(jìn) 制 數(shù) 轉(zhuǎn) 換 為 二 進(jìn) 制 )。