熟悉使用工具

Git地址 地址
Git用户名 lilyShuangszyzhk
学号后五位 74121
博客地址 博客地址
作业链接 作业链接

一.环境搭载

Visual Studio 2017

因为Visual Studio 2017文件比较庞大而且下载缓慢,我的edu也不知道遇到什么问题,即使在图书馆下载速度依旧是大约9kb/s,无奈之下本次只能选用Visual Studio 2010完成作业

git

git的下载安装与使用都较为顺畅,没有遇到什么问题

二.克隆项目

1.在github上将代码拷贝到自己的仓库中

2.使用git克隆阿超的四则运算

3.新建文件夹并创建项目

4.代码

这里因为我不会使生成的算式中除法计算全部保证整除,只能默认阿超的孩子算除法会只取整除部分了...

#include "stdafx.h"
#include<iostream>
using namespace std;

char s[4]={'+','-','*','/'};

void make(int n)//题目个数 
{
    int ans=0,ch=1,m=0,x,y,z;
    for(int i=1;i<n;i++)
    {
      x=rand()%100+1,y=rand()%4;
      if(s[y]=='*'||s[y]=='/')
      {
        if(m==0)
            ch*=x; 
        else if(m==1)
            ch*=-x;
        else if(m==2)
            ch*=x;
        else
            ch/=x;
      }
      else 
      {
        if(m==0)
            ans+=x;
        else if(m==1)
            ans-=x;
        else if(m==2)
        {
            ch*=x;
            ans+=ch;
            ch=1;
        }
        else
        {
           ch/=x;
           ans+=ch;
           ch=1;    
        }
      }
      cout<<x<<s[y];
      m=y; //前一步的符号 
    }

    z=rand()%100+1;
        if(m==0)
            ans+=z;
        else if(m==1)
            ans-=z;
        else if(m==2)
        {
            ch*=z;
            ans+=ch;
            ch=1;
        }
        else
        {
           ch/=z;
           ans+=ch;
           ch=1;    
        }
    cout<<z<<"= "<<ans<<endl;
    
}
int main()
{
    int seed;
    cout<<"Enter a seed:";
        cin>>seed;//输入随机数种子,防止每次题目相同
        srand(seed);
    for(int i=1;i<=10;++i)
        make(rand()%4+2);//将题目长度控制在四步计算之内 
    return 0;
} 

运行结果

测试成功

猜你喜欢

转载自www.cnblogs.com/szy211/p/11564146.html