Soft Second familiar tools work

Soft work second jobs

Familiar tools

GIT address https://github.com/Corvvus
GIT Username Corvvus
Student ID after five 61426
blog address https://www.cnblogs.com/zhangzhuoxin/
Job Link https://www.cnblogs.com/harry240/p/11515697.html

Configuration process

1. Download vs2017

nz8i8O.png

Download a c ++ configuration environment
2. Download git
nz8mVI.png

3. A super save the library to your library

4. In a file directory git bush, save the library file to your local

nz8rM4.png

5. The original Java files into cpp file

nz8fJK.png
6. copy the source code and header files into the vs

nzGCes.png

Code

head File

#pragma once
#include "stdlib.h"
#include <stack>
#include <vector>
#include <iostream>
#include "stdlib.h"
#include <ctime>
#include <string>  
#include "../Calculator/calculator.h"
using namespace std;

class Calculator {
private:
    string op[4] = { "+", "-", "*", "/" };
public:
    Calculator();
    string MakeFormula();
    string Solve(string formula);
};

Source

// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "pch.h"
#include <iostream>

#include <stdlib.h>
#include <stack>
#include <vector>
#include <iostream>
#include "stdlib.h"
#include <ctime>
#include <string>
#include "Calculator.h"

#define random(a,b) (rand()%(b-a+1)+a)

using namespace std;

Calculator::Calculator() {}

string Calculator::MakeFormula() {
    string formula = "";
    //srand((unsigned int)time(NULL));
    int count = random(1, 3);
    int start = 0;
    int number1 = random(1, 100);
    formula += to_string(number1);
    while (start <= count) {
        int operation = random(0, 3);
        int number2 = random(1, 100);
        formula += op[operation] + to_string(number2);
        start++;
    }
    return formula;
};

string Calculator::Solve(string formula) {
    vector<string>* tempStack = new vector<string>();
    stack<char>* operatorStack = new stack<char>();
    int len = formula.length();
    int k = 0;
    for (int j = -1; j < len - 1; j++) {
        char formulaChar = formula[j + 1];
        if (j == len - 2 || formulaChar == '+' || formulaChar == '-' ||
            formulaChar == '*' || formulaChar == '/') {
            if (j == len - 2) {
                tempStack->push_back(formula.substr(k));
            }
            else {
                if (k < j) {
                    tempStack->push_back(formula.substr(k, j + 1));
                }
                if (operatorStack->empty()) {
                    operatorStack->push(formulaChar);
                }
                else {
                    char stackChar = operatorStack->top();
                    if ((stackChar == '+' || stackChar == '-')
                        && (formulaChar == '*' || formulaChar == '/')) {
                        operatorStack->push(formulaChar);
                    }
                    else {
                        tempStack->push_back(to_string(operatorStack->top()));
                        operatorStack->pop();
                        operatorStack->push(formulaChar);
                    }
                }
            }
            k = j + 2;
        }
    }
    while (!operatorStack->empty()) {
        tempStack->push_back(string(1, operatorStack->top()));
        operatorStack->pop();
    }
    stack<string>* calcStack = new stack<string>();
    for (int i = 0; i < tempStack->size(); i++) {
        string peekChar = tempStack->at(i);
        if (peekChar != "+" && peekChar != "-"
            && peekChar != "/" && peekChar != "*") {
            calcStack->push(peekChar);
        }
        else {
            int a1 = 0;
            int b1 = 0;
            if (!calcStack->empty()) {
                b1 = stoi(calcStack->top());
                calcStack->pop();
            }
            if (!calcStack->empty()) {
                a1 = stoi(calcStack->top());
                calcStack->pop();
            }
            if (peekChar == "+") {
                calcStack->push(to_string(a1 + b1));
            }
            else if (peekChar == "-") {
                calcStack->push(to_string(a1 - b1));
            }
            else if (peekChar == "*") {
                calcStack->push(to_string(a1 * b1));
            }
            else if (peekChar == "/") {
                calcStack->push(to_string(a1 / b1));
            }
        }
    }
    return formula + "=" + calcStack->top();
}

int main()
{
    srand((unsigned int)time(NULL));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        Calculator* calc = new Calculator();
        string question = calc->MakeFormula();
        cout << question <<" = "<< endl;
        //string ret = calc->Solve(question);
        //cout << ret << endl;
    }
    getchar();
}



// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门提示: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

Screenshot after running
nzJY40.png

In the document, I will issue MakeFormula string Calculator :: random () function is generated in the main function, so that when called repeatedly will not appear on the same formula

Use github clone projects and submit code
Open git, git push input file in the local
nzJdvF.png

2. Upload complete
nzJDb9.png
picture

Feelings and sharing

The head of the blog is really great, because we are not familiar with git and vs2017, this time work experience, to git a certain understanding, to know how to download files and upload files above, I would like to work in the future will also need their own to learn new tools, so you need to acquire knowledge in the ever growing and learning, it will not be eliminated by the times.

Guess you like

Origin www.cnblogs.com/zhangzhuoxin/p/11564262.html