The second software engineering work: the use of tools!

The second software engineering work: the use of tools!

Git git
Git user name dracssr
student ID 61427
blog address dragon
Job Link The second personal work: using familiar tools

content

   In fact, the job encounter many difficulties, mainly the use of vs, as well as on Github to download and save the job submission. In this operation also learned a lot.

  Because in the past never used vs, in this download also encountered some difficulties, specific installation tutorial can click here ! Gangster written in great detail.
  Problems encountered, such as my first because the c drive only a dozen G, so I want to install in the e plate, the results of running after the code has been saying can not find the file location, I will be lost, only then can not uninstall re-download, and then find the address location of the installation tool of the column did not change, or e disk, and then only surf the Internet.
1
Get into the code found after the error vs run directly behind made a few changes, such as clicking a new project with an empty file, not running in vs inside, can not find pch.h header files, and later with the console may appear pch.h header files.
1
After the run, or will go wrong, and then I Calculator :: MakeFormula () function in the // srand ((unsigned int) time (NULL)); statement is commented out, would generate a random number is written inside the main function, and Add a for loop before they can run properly;
11
full-Code:
headers: Calculator.h

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

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

Source file ConsoleApplication2.cpp

// 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));
    cout<<"请输入您要生成的题目数:"<<endl;
    int num;
    cin >> num;
    for (int i = 1; i <= num; 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 文件

I do not have specific code change much, I would not be able to change the run, run the following results
1
as the results written topic, I wrote several error codes will I give up.
After github submission, beating trouble, did not even find, submitted the wrong time, to submit jobs to go to comment. Then step back to go forward to find places to submit jobs.

Impressions

  Learning a new tool, the existence of some difficulties, keep Baidu Baidu, ask a roommate to see other people submitted the blog, and slowly learn, write slowly, eventually began running, in general, the difficulties encountered Although many will, but by the time and effort for a long time, or resolved. The last thing a new school, I was quite happy.

Guess you like

Origin www.cnblogs.com/Drac/p/11564320.html
Recommended