Software Engineering Second job: Familiar tools

Second job: Familiar tools

GIT address https://github.com/
GIT Username Sisyphus121
Student ID after five 61313
blog address my blog
Job Link https://www.cnblogs.com/harry240/p/11515697.html

1. Environment Configuration

I am using VS2019 version, before doing C ++ course work has been used VS, environment configuration No screenshot.

Installation of the Git and GitHub.

2. Issues and Code

On A super family of children in first grade, and this summer the teachers to the parents arranged a job: Parents give their children every day some reasonable, but the four operations subject some difficulty, and parents to the child's job scoring record .

A super programmer as I thought, since the topic is required every day, why not do a primary school can automatically generate the title four operations to solve the problem with the command line "software" it. He then translate what the teacher, on the formation of the demand of this software:

程序接收一个命令行参数 n,然后随机产生 n 道加减乘除(分别使用符号+-*/来表示)练习题,每个数字在 0 和 100 之间,运算符在 2 个 到 3 个之间。
由于阿超的孩子才上一年级,并不知道分数。所以软件所出的练习题在运算过程中不得出现非整数,比如不能出现 3÷5+2=2.6 这样的算式。
练习题生成好后,将生成的 n 道练习题及其对应的正确答案输出到一个文件 subject.txt 中。

当程序接收的参数为4时,以下为一个输出文件示例。

13+17-1=29
11*15-5=160
3+10+4-16=1
15÷5+3-2=4

Code

#include <iostream>
#include <ctime>
#include <fstream>

using namespace std;

int getrandnum();//获取1-100的随机数字
char getrandsignal();//随机获取四个运算符
bool judgeint(int ,int[] ,char[] );//判断结果是否为整数
void filein(int , int[] , char[] );//将算式写入到文本文档中
void display(int , int[] , char[] );//屏幕输出算式
int main()
{
    int n;
    int m,i,j;
    int num[5];
    char sign[5];
    fstream file("subject.txt", ios::out);//清空subject文档
    cout << "请输入要产生的题目数量: ";
    cin >> n;
    cout << "题目:" << endl;
    srand(time(0));//获取随机数

    while (n != 0) {//算式生成
        m = rand() % 4 + 2;
        for (i = 0; i < m; i++) {
            num[i] = getrandnum();
        }
        for (i = 0; i < m - 1; i++) {
            sign[i] = getrandsignal();
        }
        if(judgeint(m,num,sign))
        {
            n--;
            display(m, num, sign);
            filein(m, num, sign);
        }
    }
}

//获取1-100的随机数字
int getrandnum() {
    return rand() % 100 + 1;
}

//随机获取四个运算符
char getrandsignal() {
    char signal[4] = { '+','-','*','/' };
    int q;
    q = rand() % 4;
    return signal[q];
}

//判断结果是否为整数
bool judgeint(int k, int num[5], char sign[5]) {
    int c1=0;
        for (int j = 0; j < k - 1; j++) {
            if (sign[j] == '/')
                c1 = num[j] % num[j + 1];
        }
    if (c1 != 0)
        return false;
    else
        return true;
}

//将算式写入到文本文档中
void filein(int k, int num[5], char sign[5]){
    ofstream questions("subject.txt", ios::app);
    if (questions.is_open()) {
        for (int i = 0; i < k-1; i++) {
            questions << num[i] << sign[i];
    }
    questions << num[k - 1];
        questions << " =\n";
        questions.close();
    }
}

//屏幕输出算式
void display(int k, int num[5], char sign[5]) {
    
    for (int i = 0; i < k-1; i++) {
        cout << num[i] << sign[i];
    }
    cout << num[k - 1];
    cout << '=' << endl;
}

operation result

3. Cloning and upload

Cloning part very well, follow the tutorial once cloned over, then start writing code, but the problem has been uploaded, it is not clear upload no problem as shown:

4. impressions

In fact, this assignment to write code is not in trouble, debugging several times came out the results you want, but on how to use vs GitHub and is still very dizzy, especially GitHub, that a bunch of English too unfriendly, tutorials also appeared the problem, debug, there is a obj file simply do not, and on tutorials discrepancy, at the same time with the git command is not very well, in short, this assignment I only completed part of the code, and use on GitHub vs there studies continue research.

Guess you like

Origin www.cnblogs.com/sisyphus1121/p/11564458.html