zoukankan      html  css  js  c++  java
  • 软件工程第二次作业

     题目:
    请编写一个能自动生成小学四则运算题目的 “软件”。
    让程序能接受用户输入答案,并判定对错。
    最后给出总共 对/错 的数量。

    • 需求分析
    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!
    ");
            wrong++;
        }
        else
        {
            printf("Yes,good job!
    ");
            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!
    ");
            wrong++;
        }
        else
        {
            printf("Yes,good job!
    ");
            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!
    ");
            wrong++;
        }
        else
        {
            printf("Yes,good job!
    ");
            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!
    ");
            wrong++;
        }
        else
        {
            printf("Yes,good job!
    ");
            right++;
        }
     }
    void main()
    {
        int choise,con=0;
        printf("
    
    		欢迎光临我的C语言四则运算程序
    ");
        system("pause");
        system("cls");
        while(1)
        {
            printf("
    
    		请选择:
    加(输入1)
    减(输入2)
    乘(输入3)
    除(输入4)
    ");
            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("请问您想继续进行这个运算还是重新选择其他运算还是退出程序?
    继续(输入1),重新选择运算(输入2),退出(输入3)");
            scanf("%d",&con);
            if(con==1)con=1;
            if(con==2)con=0; 
            if(con==3)break;
        }    
        printf("您总做了%d个题,正确%d的道,错误%d道!
    ",right+wrong,right,wrong);
        system("pause");
    } 
    • 效果截图

    • 分析与总结
    1. PSP耗时计算

    1.  总结

    首先,由于力量有限,所以这个软件有很大的问题,在做除法运算的时候做不出来。

    其次,我认为对于每一件事情,不管你喜不喜欢,在你去做的时候态度必须要端正,就算结果不会十全十美,但是至少会有个结果,如果你不去做,就连结果也不会有。

  • 相关阅读:
    Serveral effective linux commands
    Amber learning note A8: Loop Dynamics of the HIV-1 Integrase Core Domain
    amber初学……
    anaconda使用
    python中的一些语法
    python中的OOP
    python中的模块
    将python程序打包成exe
    python-执行过程
    python基础
  • 原文地址:https://www.cnblogs.com/denghonghong/p/4415576.html
Copyright © 2011-2022 走看看