1. 程式人生 > >2016012069小學四則運算練習軟件項目報告

2016012069小學四則運算練習軟件項目報告

== array 運算 har 估計 odin string 技術 evel

代碼鏈接:https://git.coding.net/yueshendaren/personal_project.git

目錄:

1:需求分析

2:功能設計

3:設計實現

4:算法詳解

5:測試運行

6:部分代碼

7:作業總結


1:需求分析:題目要求我們設計一個四則運算的程序,在輸入隨機數n後產生n道題涉及3到5個運算符,且不能有負數和小數。練習題生成好後,輸出學號與生成的n道練習題及其對應的正確答案輸出到文件“result.txt”中,不要輸出額外信息,文件目錄與程序目錄一致。

輸出實例如下:

2018010203
13+17-1=29
11*15-5=160
3+10+4-16=1
15÷5+3-2=4

2:功能設計:設計一個四則運算程序,能將運算式和答案一起輸出。運算符在3—5個之間。並附帶自己的學號

3:設計實現:通過隨機數函數生成運算符和運算的數字,使用調度場算法來解決運算問題

4:算法詳解:使用Random函數生成隨機數和隨機運算符

調度場算法: 由於後綴表達式求值比較容易,一個下推棧即可,所以在編譯過程中,中綴表達式會轉成後綴表達式。而調場度算法就是將中綴表達式轉換成後綴表達式的算法。

5:測試運行:

技術分享圖片技術分享圖片

6:部分代碼:(1)生成中綴表達式



public static
String zhongxu(){ int[] shuzi = new int[7]; char[] zifu = new char[7]; String wenti = ""; shuzi[0] = (int)(Math.random()*10); wenti = wenti + shuzi[0]; for(int i=0; i<5; i++) { zifu[i] = caozuo[(int
)(Math.random()*3)]; if(zifu[i]==‘+‘) shuzi[i+1] = (int)(Math.random()*10); if(zifu[i]==‘-‘) shuzi[i+1] = (int)(Math.random()*shuzi[i]); if(zifu[i]==‘*‘) shuzi[i+1] = (int)(Math.random()*10); if(zifu[i]==‘÷‘) shuzi[i+1] = yueshu(shuzi[i+1]); wenti = wenti+zifu[i]+shuzi[i]; } return wenti; }

 

(2)生成並計算後綴表達式



public static int youxianji(char x){
            if(x==‘+‘ || x==‘-‘) return 1;
            else return 2;
        }
        
        public static int yunsuan(int x, int y, char z)
        {
            if(z==‘+‘) return x+y;
            if(z==‘-‘) return x-y;
            if(z==‘*‘) return x*y;
            if(z==‘÷‘) return x/y;
            return -1;
        }
        
        public static  int houxujisuan(String wenti){
            char[] zifu = new char[20];
            char[] caozuo = new char[20]; 
            int[] shuzi = new int[20];
            int temp = 0, pn = -1, pc = -1; 
            
            zifu = wenti.toCharArray();
            
            for(int i=0; i<zifu.length; i++){
                
                if(Character.isDigit(zifu[i])) {
                    temp = temp*10 + zifu[i]-‘0‘;
                    if(i == zifu.length-1){
                        shuzi[++pn] = temp;
                    }
                }
                else {
                    shuzi[++pn] = temp; 
                    temp = 0;
                    
                    while(pc!=-1 && youxianji(caozuo[pc]) >= youxianji(caozuo[i]) ) {
                        int num1 = shuzi[pn--];
                        int num2 = shuzi[pn--];
                        char ch1 = caozuo[pc--];
                        shuzi[++pn] = yunsuan(num2, num1, ch1);
                    }
                    
                    if(pc == -1) caozuo[++pc] = zifu[i];
                }
            }
            
            while(pc != -1) {
                int num1 = shuzi[pn--];
                int num2 = shuzi[pn--];
                char ch1 = caozuo[pc--];
                shuzi[++pn] = yunsuan(num2, num1, ch1);
            }
            
            return shuzi[0];
        }
        

 

7:作業總結:說實話,從剛看到作業開始就知道自己的編程能力實在是差。甚至都不知道怎麽去寫這個作業,最終在同學和百度的幫助下,勉強完成了這次作業。不得不說自己用的調場度算法大量借鑒了別人的博客,因為自己的能力真的有限。可能這次作業不盡人意,但它卻讓我意識到自己到底有多差。這學期重新學java,並不是說說而已,畢竟自己的時間真的不多了。不想也不能再這樣下去了。不管這次作業的結果如何,我都會接受,我只能說,下一次的自己一定能有進步。

PSP2.1

任務內容

計劃共完成需要的時間(min) 實際完成需要的時間(min)
Planning 計劃 8 10
Estimate 估計這個任務需要多少時間,並規劃大致工作步驟 10   15
Development 開發 10 10
· Analysis 需求分析 (包括學習新技術) 60 100
Design Spec 生成設計文檔 10 10
Design Review 設計復審 (和同事審核設計文檔) 6 4
Coding Standard 代碼規範 (為目前的開發制定合適的規範) 10 10
Design 具體設計 6 6
Coding 具體編碼 400 600
Code Review 代碼復審 7 9
Test 測試(自我測試,修改代碼,提交修改) 11 12
Reporting 報告 10 10
Test Report 測試報告 10 11
Size Measurement 計算工作量 5 6
Postmortem & Process Improvement Plan 事後總結, 並提出過程改進計劃 10 20


2016012069小學四則運算練習軟件項目報告