The second software engineering foundation work

Familiar tools

git address  https://github.com/npcccc1/achaodnm.git
git user name  npcccc1
Blog link  https://www.cnblogs.com/npc1158947015/
After school number 5  92324
Job Link  https://edu.cnblogs.com/campus/xnsy/Autumn2019SoftwareEngineeringFoundation/homework/7590

 

 

 

 

 

 

 

 

 

First, the environment configuration process

Before it is used github registered very easily, before also just great visual stdio2017, selected the c ++ components but did not stay shots, git installation did not encounter much of a problem.

Cloning Project: On attempting to file type conversion also spent a lot of time with nothing

Because for reasons git understand too little, found on the Internet a few days did not understand the branch of knowledge to solve a misuse git a directive came out, so the project always translate over cloning is not a c ++ project, has been parked in default the master branch to open its files are also of Java.

 

 

Second, the idea of ​​code

Claim:

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:

Receiving a program command line parameter n, then n channel arithmetic randomly generated (respectively use the symbol + - * represented) exercises, each number between 0 and 100, the operator between 2-3.

A super child was due last year, did not know the score. Therefore, the software exercises not appear in the non-integer arithmetic process, such as 3 ÷ 5 + 2 = 2.6 This formula can not occur.

After the exercises generate good will generated n Road exercises the right answer and the corresponding output to a file subject.txt in.

When the received program parameters to 4, the following is a sample output file.

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

 

思路:

#include "pch.h"                    //头文件
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <time.h>   
using namespace std;

  

 


char Operator() { int i; srand(time(NULL)); //需要生成随机的运算符与随机数 i = rand() % 4 + 1; //就先设出这两个函数 switch (i) { case 1: return '+'; case 2: return '-'; case 3: return '*'; case 4: return '/'; } } int Random() { int x; srand(time(NULL)); //看看是否为伪随机数 x = rand() % 100 + 1; return x; }

  

  先把主函数列上,方便之后的函数解说

int main()
{
	int a,b,c,d,judge,n,x;
	char op1,op2,op3;
	cout << "enter the number of calculations that you want to produce:"<<endl;
	cin >> n;                    //问要几个四则运算
	for (x = 1; x <= n; x++)
	{
		judge = rand() % 3 + 1;
		if (judge = 1)            //judge为运算符个数,1时再加1或2
		{
			judge = judge + rand() % 2 + 1;
		}
		if (judge == 2)           
		{
			a = Random();
			b = Random();
			c = Random();
			op1 = Operator();
			op2 = Operator();
			Calculation(op1, a, b);     //把两随机数与符号输出
			Calculation(op2, c);       //用到函数重载
			cout << endl;
		}
		if (judge == 3)
		{                                   //三个运算符需要四个随机数构成式子
			a = Random();
			b = Random();
			c = Random();
			d = Random();
			op1 = Operator();
			op2 = Operator();
			op3 = Operator();
			Calculation(op1, a, b);
			Calculation(op2, c);
			Calculation(op3, d);
			cout << endl;
		}
	}
}

  函数Calculation与Realmark(判断除法运算结果是否为小数)与全局变量int temporary:

  一开始想的是只写一个Calculation(op1, a, b)函数,在txt文件中把相邻的两个相同的数删去一个,后来发现还是重载加全局变量传递相同的数更为简单,便于实现

 

bool Realmark(int x,int y)             //两数相除余数为零则符合条件
{
	if (x%y || y % x != 0)
	{
		return 0;
	}
	else return 1;
} 
void Calculation(char a, int x, int y)
{
	if (a == '*'&&a == '+'&&a == '-')
	{                                          //加减乘直接输出
		cout << x << a << y;
	}
	if (a == '/')
	{
		do
		{
			if (Realmark(x, y))
			{
				cout << x << a << y;
				break;
			}
			else
			{
				x = Random();
				y = Random();
			}
		} while (Realmark(x, y));
	}
	temporary = y;              //每个式子开始的数+符+数可以调用次函数,并且把y赋值给全局变量
}                                   //方便下一个函数只输出符+数,与判断y与新的x若是除法会不会有余数

int temporary; //全局变量,写主函数之前即可


void Calculation(char a, int x) { if(a == '*'&&a=='+'&&a=='-') { cout << a << x; //加减乘即可直接输出 } if (a == '/') { do { if (Realmark(x, temporary)) { cout << a << x ; break; } else { x = Random(); //Realmark为0则要重新生成x,再比较新的x与tempoary } } while (Realmark(x, temporary)); } }

 

一个跑代码时特别坑的就是用了它步骤中的控制台项目,不知道是不是我没转化成c++项目,没拷贝src文件的原因,总是在第一行就开始报错:

符号符号已多次定义。The symbol symbol was defined more than once.

 

此错误后跟错误LNK1169

一个或多个多重定义的符号找到one or more multiply defined symbols found

生成失败,因为多个定义的一个或多个符号。The build failed due to multiple definitions of one or more symbols. 此错误之前错误LNK2005

实验多次,重新开一个空项目才不再报错。

 

三、 使用github克隆项目、提交代码

github真是慢的要死还全是英文看不懂

还是git简直日了 还是依旧不知道哪里出错

为啥照着教程做会给我出来warning出来找不到文件  解决了这个(自己没仔细看)又出来其他的,人都傻了。手动传的代码最后

 

 

四、感想

无聊好无聊一直找错误找到心态爆炸,完全没有什么成就感信了教程的邪一直在一些点打圈圈,啥都不会的感觉太不爽了。

Guess you like

Origin www.cnblogs.com/npc1158947015/p/11563408.html