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

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

    一 需求分析:

    • 运行界面用户按任意键开始运行,根据提示选择所要实现的计算(加、减、乘、除)
    • 选择相应计算后,程序对应算法随机产生两个数,用户给出答案
    • 用户给出答案,程序进行判断答案是否正确
    • 运行退出时,程序给出计算结果,统计答题正确与错误的个数

    二 设计:

      • rand()%100用来产生0~100以内的随机数,cystem("pause")用于暂停
      • 四个子函数对应相应的加减乘除运算,并判断结果对错
      • switch选择调用运算种类
      • 代码如下
      • #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("回答错误
        ");wrong++;}
         else {printf("回答正确
        ");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("回答错误
        ");wrong++;}
         else {printf("回答正确
        ");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("回答错误
        ");wrong++;}
         else {printf("回答正确
        ");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("回答错误
        ");wrong++;}
         else {printf("回答正确
        ");right++;} 
        }
        void main()
        {
           int choise,con=0;
           
           printf("
        
        		四则运算程序
        "); 
           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");
           
        }
  • 相关阅读:
    背水一战 Windows 10 (61)
    背水一战 Windows 10 (60)
    背水一战 Windows 10 (59)
    背水一战 Windows 10 (58)
    背水一战 Windows 10 (57)
    背水一战 Windows 10 (56)
    背水一战 Windows 10 (55)
    背水一战 Windows 10 (54)
    背水一战 Windows 10 (53)
    背水一战 Windows 10 (52)
  • 原文地址:https://www.cnblogs.com/rjgc123/p/4420184.html
Copyright © 2011-2022 走看看