zoukankan      html  css  js  c++  java
  • 四则运算2程序

    1、代码

    #include<iostream>

    #include<stdlib.h>

    #include<time.h>

    #include<conio.h>

    using namespace std;

     

    int x1[100],x2[100],j,i;

    void yunsuan1()//空行输出

    {

        if (j==0)

            cout<<x1[i]<< "+"<<x2[i]<<"="<<endl;

        if (j==1)

            cout<<x1[i]<< "-"<<x2[i]<<"="<<endl;

        if (j==2)

            cout<<x1[i]<< "*"<<x2[i]<<"="<<endl;

        if (j==3)

            cout<<x1[i]<< "/"<<x2[i]<<"="<<endl;

    }

    void yunsuan2()//空格输出

    {

        if (j==0)

            cout<<x1[i]<<"+"<<x2[i]<<"="<<" ";

        if (j==1)

            cout<<x1[i]<<"-"<<x2[i]<<"="<<" ";

        if (j==2)

            cout<<x1[i]<<"*"<<x2[i]<<"="<<" ";

        if (j==3)

            cout<<x1[i]<<"/"<<x2[i]<<"="<<" ";

    }

     

     

    int main()

    {

        srand(time(NULL));//题目避免重复

        int N, n, M;//题目数量,数字范围

        int out, div, fushu, jixu;//输出方式,是否有乘除运算,加减法是否有负数,是否继续

        cout<<"请输入题目的数量:"<<endl;

        cin>>N;

        cout<<"请选择数值范围(0--M)"<<endl;

        cin>>M;

        cout<<"请选择打印方式(0、空行打印; 1、空格打印)"<<endl;

        cin>>out;

        cout<<"请选择有无乘除运算(0、没有乘除运算; 1、有乘除运算)"<<endl;

        cin>>div;

        cout<<"请选择加减运算有无负数(0、没有负数; 1、有负数)"<<endl;

        cin>>fushu;

        cout << "题目如下:" << endl;

        for (i=1;i<=N;i++)

        {

            x1[i]=rand()%M;//随机输出用户制定范围内的数

            x2[i]=rand()%M;

            j=rand()%4;

            if (out==0)

            {

                if (div==0&&fushu==0)

                {

                    if (j>=2)

                    {

                        j=j-2;

                        yunsuan1();

                    }

                    else

                    {

                        yunsuan1();

                    }

                }

                if (div==1&&fushu==1)

                {

                    if (x1[i]>x2[i])

                    {

                        n=x1[i];

                        x1[i]=x2[i];

                        x2[i]=n;

                    }

     

                    yunsuan1();

                }

                if (div==0&&fushu==1)

                {

     

                    if (j>=2)

                    {

                        j=j-2;

                        yunsuan1();

                    }

                    else

                    {

                        yunsuan1();

                    }

                }

                if (div==1&&fushu==0)

                {

                    yunsuan1();

                }

            }

            else if (out==1)

            {

                if (div==0&&fushu==0)

                {

                    if (j>=2)

                    {

                        j=j-2;

                        yunsuan2();

                    }

                    else

                    {

                        yunsuan2();

                    }

                }

                if (div==1&&fushu==1)

                {

                    if (x1[i]>x2[i])

                    {

                        n=x1[i];

                        x1[i]=x2[i];

                        x2[i]=n;

                    }

     

     

                    yunsuan2();

                }

                if (div==0&&fushu==1)

                {

                    if (j>=2)

                    {

                        j=j-2;

                        yunsuan2();

                    }

                    else

                    {

                        yunsuan2();

                    }

     

                }

                if (div==1&&fushu==0)

                {

                    yunsuan2();

                }

            }

     

        }

        cout<<"是否继续?  1、是;2、否"<<endl;

        cin>>jixu;

        if (jixu==1)

        {

            cout<<endl;

            main();

        }

        else

        {

            return 0;

        }

        return 0;

    }

    2、运行结果

    3、总结

    总结:程序编写之初使用类然后调用函数,因为对函数的调用和类的使用有些忘记,而且查找资料最后也没找到,所以最后直接定义了两个函数yuansuan1(),yunsuan2(); 然后为了使题目不重复使用了srand(time(NULL))函数 ;还有就是分数的实现没有思路。主要的时间都浪费在类的使用上了,最后也没用上。

  • 相关阅读:
    Powershell 音乐播放
    Powershell指令集_2
    Powershell指令集_2
    Powershell 邮件发送
    Powershell 邮件发送
    Oracle 11g 关闭内存自动管理
    Oracle 11g 内存手动管理
    Oracle 内存参数调整
    RESTful三理解
    RESTful三理解
  • 原文地址:https://www.cnblogs.com/weishengzuimo/p/4367755.html
Copyright © 2011-2022 走看看