zoukankan      html  css  js  c++  java
  • 软件工程个人作业02

    设计思路:

    在第一次实验的基础上(第一次并没有建类),建立Arithmetic类,然后依次添加新的功能模块(添加新的函数体或者在原有函数体上做改动)

    通过switch语句实现功能的选择不同的case语句调用不同的函数体实现功能

    通过对随机数对4求余数来随机产生不同的运算符

    通过随机数对10求余来确定括号的个数

    通过减去余数(a=(a-a%b))来确保没有余数

    通过加一个数来确保没有余数是产生有余数的运算式

    通过随机函数确定负号位置

    Arithmetic.h

    #pragma once
    #include<iostream>
    using namespace std;

    class Arithmetic
    {
      protected:
      int a,b,c,d,y,m;
      public:
      Arithmetic(void);
      ~Arithmetic(void);
      void Intnumber(int N,int m,int F,int O,int P);
      void Mixnumber(int N,int m,int F,int O);
      void show1(int y,int a,int b,int o,int P);
      void show2(int y,int a,int b,int c,int d);
      void Havespace(int F,int N);
    };

    Arithmetic.cpp

    #include "Arithmetic.h"


    Arithmetic::Arithmetic(void)
    {
    }

    Arithmetic::~Arithmetic(void)
    {
    }
    void Arithmetic::Intnumber(int N,int m,int F,int O,int P)
    {
      for(int i=0;i<N;i++)
      {
        a=rand()%F;
        b=rand()%F;
        if(m==1)
          { y=rand()%2;}
        else if(m==2)
          { y=rand()%4;} //判断是否有乘除
        if(b==0||(a==b&&b==c)) //避免重复且除数不为0
        {
          i--;
        }
        else
        {
          show1(y,a,b,O,P);
        }
      }
    }
    void Arithmetic::Mixnumber(int N,int m,int F,int O)
    {
        for(int i=0;i<N;i++)
        {
          a=rand()%F;
          b=rand()%F;
          if(m==1)
            { y=rand()%2;}
          else if(m==2)
            { y=rand()%4;} //判断是否有乘除
          c=rand()%100;
          d=rand()%100;
          if(b==0||b>=a||d>=c||(a==b&&b==c)) //确保假分数避免重复且除数不为0
          {
            i--;
          }
          else
          {
            show2(y,a,b,c,d);
          }
        }
    }
    void Arithmetic::show1(int y,int a,int b,int o,int p)
    {
        if(y==0)
        {
          if(o==1)//判断有无负数
            {cout<<a<<"+"<<b<<"="<<endl;}
          else
            {
              if(rand()%3==0)//随机确定负号位置
                {cout<<"(-"<<a<<")+"<<b<<"="<<endl;}
              if(rand()%3==1)
                {cout<<a<<"+(-"<<b<<")="<<endl;}
              else
                {cout<<"(-"<<a<<")+(-"<<b<<")="<<endl;}
             }
        }
        else if(y==1)//判断有无负数
        {
        if(o==1)//随机确定负号位置
          {cout<<a<<"-"<<b<<"="<<endl;}
        else
        {
            if(rand()%3==0)
              {cout<<"(-"<<a<<")-"<<b<<"="<<endl;}
            if(rand()%3==1)
              {cout<<a<<"-(-"<<b<<")="<<endl;}
            else
              {cout<<"(-"<<a<<")-(-"<<b<<")="<<endl;}
        }
      }
      else if(y==2)
      { cout<<a<<"*"<<b<<"="<<endl;}
      else
      if(p==1)//判断是否要求有余数
      {
        if(a%b!=0)
        {a=(a-a%b);}//确保没有余数
        cout<<a<<"/"<<b<<"="<<endl;
      }
      else
      {
        if(b==1)
          {b=b+1;}
        if(a%b==0)
          {a=(a+rand()%b);}//确保有余数
        cout<<a<<"/"<<b<<"="<<endl;
      }
    }
    void Arithmetic::show2(int y,int a,int b,int c,int d)
    {
      if(y==0)
        {cout<<"("<<a<<"/"<<b<<")+("<<c<<"/"<<d<<")="<<endl;}
      else if(y==1)
        { cout<<"("<<a<<"/"<<b<<")-("<<c<<"/"<<d<<")="<<endl;}
      else if(y==2)
        { cout<<"("<<a<<"/"<<b<<")*("<<c<<"/"<<d<<")="<<endl; }
      else
        {cout<<"("<<a<<"/"<<b<<")/("<<c<<"/"<<d<<")="<<endl; }
    }
    void Arithmetic::Havespace(int F,int N)
    {

        for(int i=0;i<N;i++)
         {
            char s;
            int n=rand()%4;
            if(n==0)
            {s='+';}
            else if(n==1)
            {s='-';}
            else if(n==2)
            {s='*';}
            else
            {s='/';}
            cout<<"("<<rand()%F<<s<<rand()%F<<")"<<s<<"("<<rand()%F<<s<<rand()%F<<")="<<endl;
         }
    }

    main.cpp

    #include "Arithmetic.h"


    void main()
    {
      P:
      Arithmetic A;
      int N;
      cout<<"请输入要打印的题目数量:"<<endl;
      cin>>N;
      int n,m,f,o,p;
      cout<<"请输入四则运算数的种类(1为整数,2为假分数,3有括号运算):"<<endl;
      cin>>n;
      cout<<"生成f值以内的运算题目(输入f值):"<<endl;
      cin>>f;
      if(n==1||n==2)
      {
        cout<<"有无乘除运算?(1没有,2有):"<<endl;
        cin>>m;
        cout<<"加减运算有无负数?(1没有,2有):"<<endl;
        cin>>o;
        cout<<"除法有无余数?(1没有,2有)"<<endl;
        cin>>p;
    }
    switch(n)
    {
      case 1:
      {A.Intnumber(N,m,f,o,p);break;}
      case 2:
      {A.Mixnumber(N,m,f,o);break;}
      case 3:
      {A.Havespace(f,N);}
      }
      goto P;
    }

                                              周活动总结表

                                    姓名:李营                                                日期:2016/3/19

    日期

    任务

    听课(min

    编写程序(min

    阅读课本

    准备考试

    日总计(min

    周日

    周一

    100

    120

    220

    周二

    周三

    150

    150

    周四

    周五

    周六

    120

    120

    周总计

    100

    270

    390

                                阶段时间和效率:

    总计

    100

    270

    120

    390

    平均

    100

    270

    120

    390

    最大

    100

    270

    120

    390

    最小

    100

    270

    120

    390

                               (注:第一次记录)

                                               时间记录日志

                                学生:李营                      日程:20016/3/19

                               教师:王建民                                           课程;软件工程概论

    日期

    开始时间

    结束时间

    中断时间

    净时间

    活动

    备注

    3/14

    8:00

    9:50

    10

    100

    听课

    王老师讲课

    1430

    16:50

    20

    120

    编写程序(二柱子)

    ,打水,聊天

    作业

    3/16

    14:00

    16:40

    10

    150

    编写程序(解决了连续分数加括号问题),打水

    作业

    3/19

    14:00

    16:00

    120

    编写程序(对程序稍加完善),整理提交作业

    作业

                                                缺陷记录日志

                              学生:李营

                              日期:2016/3/26

                              教员:王建民

                              程序号:2

    日期

    编号

    类型

    引入阶段

    排除阶段

    修复时间

    修复缺陷

    3/14

    1

    a

    编译运行

    编译运行

    1min

    忽略了被除数不能为0

    2

    b

    编码

    编码

    1min

    忘记了加“;”

    3/16

    3

    c

    编码

    编码

    1min

    忘记了关闭上一次的运行窗口造成程序报错为找不到保存路径

  • 相关阅读:
    软件工程(2018)结对编程第二次作业
    软件工程(2019)结对编程第一次作业
    软件工程(2019)第三次个人作业
    软件工程(2019)第二次作业
    软件工程(2019)第一次作业
    实用的小工具
    php中需要注意的函数(持续更新)
    sql 防注入(更新问题)
    laravel 中将一对多关联查询的结果去重处理
    调试location指令时,直接让location输出文本
  • 原文地址:https://www.cnblogs.com/liying123/p/5291644.html
Copyright © 2011-2022 走看看