软件工程个人作业02

题目要求:

1、题目避免重复;
2、可定制(数量/打印方式);
3、可以控制下列参数:

n是否有乘除法;

n是否有括号(最多可以支持十个数参与计算);
n数值范围;
n加减有无负数;
n除法有无余数!

计划,思路:1.编写随机生成1-100之内的数的代码(取随机数)

                 2.编写生成加减乘除运算符的代码;

                 3.编写生成加减运算符的代码;

                 4.编写生成四则运输的函数;

                 5.编写生成含有负号的随机数函数;

                 6.编写含有括号的带有加减号的函数;

                 7.编写生成最简真分数的函数;

                 8.编写只生成加减号的函数;

                 9.编写只生成乘除号的函数;

                10.编写运行界面;

                11.将上述编写好的函数按要求进行组合;

                12.运行代码;

实验代码:

           四则运算
//邵文正 20142894  2016.3.15
/*
是否有乘除法;
是否有括号(最多可以支持十个数参与计算);
数值范围;
加减有无负数;
除法有无余数!
*/
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
void face()//界面
{
    cout << "[-------------------------------------------------------- ]" << endl;
    cout << "|                     请输入您的选择:                                    |" << endl;
    cout << "|    1.灰常难: 含乘除法,括号,加减法有负数,除法有余数    |" << endl;
    cout << "|    2.有点难:(含乘除法,括号,加减法有负数)                 |" << endl;
    cout << "|    3.还可以:(含乘除法,括号)                                    |" << endl;
    cout << "|    4.一般吧:(只含有乘除法和加减法)                            |" << endl;
    cout << "|    5.简单的:(只有简单的加减运算)                               |" << endl;
    cout << "|    6.不想做:(啥也不生成直接退出程序咯)                        |" << endl;
    cout << "|        ///////作者: 踏  雪  飞  鸿                                     |" << endl;
    cout << "|_________________________________________________________|" << endl;
}
double random()//100以内随机数
{
    return(rand()%100);
}
double random2()//含有负号的随机数
{
    int a;
    a = rand() % 2;
    if (a==1)
    return(random());
    else
    {
        return(-random());
    }
}
string Fuhao1()//加减乘除运算符
{
    int a;
    a = rand() % 4;
    if (a == 1)
    {
        return "+";
    }
    if (a == 2)
    {
        return "-";
    }
    if (a == 3)
    {
        return"×";
    }
    else
    {
        return"÷";
    }
}
char Fuhao2()//只含有加减运算符
{
    int a;
    a = rand() % 2;
    if (a == 1)
    {
        return '+';
    }
    else
    {
        return '-';
    }
}
string Fuhao3()
{
    int a;
    a = rand() % 2;
    if (a == 1)
    {
        return "×";
    }
    else
    {
        return "÷";
    }
}
void zhenfenshu()//生成真分数
{
    int x, y;
m:y = rand() % 100;
    if (y == 0)
    {
        goto m;
    }
    x = rand() % 100;
    for (int i = 2; x >= i; i++)
    if (x%i == 0 && y%i == 0)
    {
        x /= i;
        y/= i;
        i--;
    }
    if (x < y)
    {
        cout << "(" << x << "/" << y << ")";
    }
    else
    {
        goto m;
    }
    
}
void sizeyunsuan()//四则运算;
{
    double a, b;
    a = random();
    b = random();
    cout << a << Fuhao1() << b ;

}
void jiajianyunsuan()//加减运算;
{
    double a, b;
    x:a = random();
    b = random();
    if (a <= b)
    {
        goto x;
    }
    cout << a << Fuhao2() << b;

}
void chengchuyunshuan()//乘除运算;
{
    double a, b;
    z:a = rand()%100;
    b = rand()%100;
    if (a <= b ||a==0||b==0)
    {
        goto z;
    }
    cout << a << Fuhao3() << b;

}
void kuohao()//生成括号
{
    int nm;
    nm = rand()%2;
    double a, b,c,d;
    
    
    if (nm == 1)
    {
        a = random();
        b = random();
        cout << "(" << a << Fuhao2()<< b << ")";
    }
    if (nm == 2)
    {
        a = random();
        b = random();
        c = random2();
        d = random();
        if (c <= 0)
        {
            cout << "(" << a << Fuhao2() << b << Fuhao2() <<"("<< c<<")" << Fuhao2() << d << ")";
        }
        else
        {
            cout << "(" << a << Fuhao2() << b << Fuhao2() << c << Fuhao2() << d << ")";
        }
    }
    if (nm==0)
    {
        a = random();
        b = random();
        d = random();
        cout << "(" << a << Fuhao2()<< b  << Fuhao2() << d << ")";
    }
    
}
void dasuanshi()
{
    double x, y;
    b:x = random2();
    y = random2();
    if (x == 0 || y == 0)
    {
        goto b;
    }
    if (x < 0 && y>0)
        cout << "(" << x << ")" << Fuhao1() << y;
    if (y<0 && x>0)
    {
        cout << x << Fuhao1() << "(" << y << ")";
    }
    if (x < 0 && y < 0)
    {
        cout << "(" << x << ")" << Fuhao1() << "(" << y << ")";
    }
    if (x>0 && y>0)
    {
        cout << x << Fuhao1() << y;
    }
    cout << Fuhao1();
    kuohao();
    cout << Fuhao1();
    kuohao();
    
}
void yushuchufa()
{
    int a, b;
    n:a = rand()%1000;
    b = rand()%100;
    if (b == 0)
    {
        goto n;
    }
    if ((int)a%(int)b == 0 || a <= b)
    {
        goto n;
    }
    cout << a << "÷" << b ;
}
void main()
{
    char choose;//选择用
    int number;//生成算式个数
y:face();
    cin >> choose;
    if (choose <= '0'||choose > '6')
    {
        cout << "您的输入有误,请重新选择!" << endl;
        goto y;
    }
    switch (choose)
    {
    case '1':
       {
                cout << "请问:先生/女士  您想要生成多少这样的算式呢?" << endl;
                cin >> number;
                for (int i = 1; i <= number; i++)
                {
                    int m;
                    m = rand() % 3;
                    cout << "NO" << i << ":  ";
                    if (m == 1)
                    {
                        dasuanshi();
                    }
                    else if (m==2)
                    {
                        zhenfenshu();
                        cout<<Fuhao1();
                        zhenfenshu();
                        cout << Fuhao1();
                        sizeyunsuan();
                    }
                    else if (m==0)
                    {
                        yushuchufa();
                    }
                    cout << "=";
                    cout << endl;
                }
                cout << endl;
                goto y;
       }
    case'2':
       {
               cout << "请问:先生/女士  您想要生成多少这样的算式呢?" << endl;
               cin >> number;
               for (int i = 1; i <= number; i++)
               {
                   int m;
                   m = rand() %2;
                   cout << "NO" << i << ":   ";
                   if (m == 1)
                   {
                       dasuanshi();
                   }
                   else
                   {
                       zhenfenshu();
                       cout << Fuhao1();
                       zhenfenshu();
                       cout << Fuhao1();
                       sizeyunsuan();
                   }
                   cout << "=";
                   cout << endl;
               }
               cout << endl;
                goto y;
       }
    case'3':
       {
               cout << "请问:先生/女士  您想要生成多少这样的算式呢?" << endl;
               cin >> number;
               for (int i = 1; i <= number; i++)
               {
                   int m;
                   m = rand() % 2;
                   cout << "NO" << i << ":   ";
                   if (m == 1)
                   {
                       chengchuyunshuan();
                   }
                   else
                   {
                       kuohao();
                      cout<< Fuhao1();
                       sizeyunsuan();

                   }
                   cout << "=";
                   cout << endl;
               }
               cout << endl;
               goto y;
       }
    case'4':
       {
               cout << "请问:先生/女士  您想要生成多少这样的算式呢?" << endl;
               cin >> number;
               for (int i = 1; i <= number; i++)
               {
                   cout << "NO" << i << ":   ";
                   sizeyunsuan();
                   cout << "=";
                   cout << endl;
                  
               }
              
               cout << endl;
               goto y;
       }
    case'5':
      {
               cout << "请问:先生/女士  您想要生成多少这样的算式呢?" << endl;
               cin >> number;
               for (int i = 1; i <= number; i++)
               {
                   cout << "NO." << i << ":   ";
                   jiajianyunsuan();
                   cout << "=";
                   cout << endl;
               }
               cout << endl;
               goto y;
      }
    case'6':
     {
               return;
     }
   }
    
      
}

运行结果截图:

2.

3.

4.

5.

6.

PSP0:

项目计划总结:

日期

任务

 

听课

编程

阅读

准备考试

 

 

日总计

周日

 

 

 

 

 

 

 

周一

70+50

0

0

0

 

 

100

周二

0

120

0

0

 

 

120

周三

0

50

50

0

 

 

100

周四

0

0

30

0

 

 

30

周五

0

50

30

0

 

 

80

周六

0

0

100

0

 

 

100

周总计

70

220

210

0

 

 

530

 

 

 

总计

120

220

210

0

 

 

530

平均

120

220

210

0

 

 

530

最大

120

220

210

0

 

 

530

最小

120

220

210

0

 

 

530

以前各周的累计时间

总计

120

220

210

0

 

 

530

平均

120

220

210

0

 

 

530

最大

120

220

210

0

 

 

530

最小

120

220

210

0

 

 

530

 

 

 

事件记录日志表:

日期

开始时间

结束时间

中断时间

净时

活动

备注

C

U

3/14

8:00

10:00

0

120

听课

 

 

 

 

2:30

6:00

30

360

自学Web

 

 

 

 

19:00

22:00

30

270

预习复习课本知识

 

 

 

3/15

16:00

18:00

0

120

编程

思考加编程

 

 

 

19:00

22:00

60

120

自学Web

 

 

 

3/16

15:00

16:00

10

50

阅读

《构建之法》

 

 

 

19:00

20:00

10

50

编程

 

 

 

3/17

16:00

17:00

10

50

阅读

《构建之法》

 

 

3/18

15:30

16:30

10

50

编程

 

 

 

 

17:00

17:30

0

30

阅读

《构建之法》

 

 

3/19

10:00

12:00

20

100

阅读

《构建之法》

 

 

 

缺陷记录日志表:

日期

编号

类型

引入阶段

排除阶段

修复时间

修复缺陷

3/16

01

无法生成有余数的除法

编译阶段

重新编译阶段

30

 

3/18

02

生成结果由于未知原因中断

编译阶段

断点检查阶段

60

被除数可能随机生成0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

            

实验心得:觉得本次试验自己并没有完全按照规定做,如果自己还有时间,会重新设计程序,尽量按要求完成。

posted @ 2016-03-17 20:00  码农小正  阅读(140)  评论(0编辑  收藏  举报