軟體工程第二次作業

來源:互聯網
上載者:User

標籤:

 題目:
請編寫一個能自動產生小學四則運算題目的 “軟體”。
讓程式能接受使用者輸入答案,並判定對錯。
最後給出總共 對/錯 的數量。

  • 需求分析
  1. 能自動產生加、減、乘、除四則運算式子,並顯示在控制台中。
  2. 能在控制台中顯示給出的答案顯示出來,並判斷正確還是錯誤。
  3. 能統計出一共做對和做錯多少道題目。
  • 設計思路
  1. 按任意鍵之後,輸入“1”代表做加法運算,輸入“2”代表做減法運算,輸入“3”代表做乘法運算,輸入“4”代表做除法運算;
  2. 當任意選擇一個運算時便會出現一道相對應的題目,如果答案不正確,會顯示“No,you are wrong!”,如果答案正確,會顯示“Yes,good job!”;
  3. 做完了一道題目後,輸入“1”表示繼續做所選擇的運算,輸入“2”表示重新選擇運算,輸入“3”便退出運算;
  4. 如果第2步中輸入“2”,則又開始第一步操作,如果不做題目了就輸入3退出系統,同時統計出總共對/錯的數量。
  • 代碼實現

 

#include "stdio.h"#include"windows.h"int right=0,wrong=0;void add(){    int a,b,c;    a=rand()%100;    b=rand()%100;    printf("請回答:%d+%d=",a,b);    scanf("%d",&c);    if(a+b!=c)    {        printf("No,you are wrong!\n");        wrong++;    }    else    {        printf("Yes,good job!\n");        right++;}    }void minu(){    int a,b,c;    a=rand()%100;    b=rand()%100;    printf("請回答:%d-%d=",a,b);    scanf("%d",&c);    if(a-b!=c)    {        printf("No,you are wrong!\n");        wrong++;    }    else    {        printf("Yes,good job!\n");        right++;    }}void mul(){    int a,b,c;    a=rand()%100;    b=rand()%100;    printf("請回答:%d*%d=",a,b);    scanf("%d",&c);    if(a*b!=c)    {        printf("No,you are wrong!\n");        wrong++;    }    else    {        printf("Yes,good job!\n");        right++;    } }void di(){    int a,b,c;    a=rand()%100;    b=rand()%100;    printf("請回答:%d/%d=",a,b);    scanf("%d",&c);    if(a/b!=c)    {        printf("No,you are wrong!\n");        wrong++;    }    else    {        printf("Yes,good job!\n");        right++;    } }void main(){    int choise,con=0;    printf("\n\n\t\t歡迎光臨我的C語言四則運算程式\n");    system("pause");    system("cls");    while(1)    {        printf("\n\n\t\t請選擇:\n加(輸入1)\n減(輸入2)\n乘(輸入3)\n除(輸入4)\n");        if(con==0)scanf("%d",&choise);        switch(choise)        {            case 1:add();break;        case 2:minu();break;        case 3:mul();break;        case 4:di();break;        }        printf("請問您想繼續進行這個運算還是重新選擇其他運算還是退出程式?\n繼續(輸入1),重新選擇運算(輸入2),退出(輸入3)");        scanf("%d",&con);        if(con==1)con=1;        if(con==2)con=0;         if(con==3)break;    }        printf("您總做了%d個題,正確%d的道,錯誤%d道!\n",right+wrong,right,wrong);    system("pause");} 

 

  • 效果

  • 分析與總結
  1. PSP耗時計算

  1.  總結

首先,由於力量有限,所以這個軟體有很大的問題,在做除法運算的時候做不出來。

其次,我認為對於每一件事情,不管你喜不喜歡,在你去做的時候態度必須要端正,就算結果不會十全十美,但是至少會有個結果,如果你不去做,就連結果也不會有。

 

軟體工程第二次作業

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.