Git address | https://github.com/mengcc1/mengcc |
---|---|
GIT Username | mengcc1 |
Student ID after five | 24242 |
blog address | https://www.cnblogs.com/mengcc/ |
Job Link | https://www.cnblogs.com/ChildishChange/p/10398212.html |
1. Environment Configuration
(1) vs the environment configuration
in learning c # already installed the vs2017, so what is the problem is not present in the environment configuration
(2) Configuration of Git
registered GitHub more smoothly without encountering problems.
2. cloning project
3. Design Process
Code design
a. Generating first calculation formula, the four random values and arithmetic symbols.
public static char[] Operator = { '+', '-', '*', '/' };
//产生运算式
public static string MakeFormula()
{
string result = null;
Random random = new Random();
int Number = (int)random.Next(0, 101);
int op_count = (int)random.Next(2, 4);
result += Number;
for (int i = 0; i < random.Next(2, 4); i++)
{
Thread.Sleep(200);
Number = (int)random.Next(0, 101);
op_count = (int)random.Next(0, 4);
result = result + Operator[op_count] + Number;
}
return result;
}
B. the random values and operators may be performed after the operation.
//计算运算式
public static string Solve(string formula)
{
DataTable dt = new DataTable();
object ob = null;
ob = dt.Compute(formula, "");
while (ob.ToString().Contains(".") || formula.Contains("/0")) //判断是否存在小数和除0操作
{
formula = MakeFormula();
ob = dt.Compute(formula, "");
}
while (Convert.ToInt32(ob) < 0 || ob.ToString().Contains(".")) //结果出现负数或小数,则重新生成
{
formula = MakeFormula();
ob = dt.Compute(formula, "");
}
return formula + "=" + ob.ToString();
}
c. output to the document.
public static void Write(string formula)
{
try
{
StreamWriter sw = new StreamWriter(@"C:\Users\Administrator\Desktop\软件工程\AchaoCalculator\结果.txt",true);
sw.WriteLine(formula);
sw.Close();
}
catch
{
Console.WriteLine("保存错误!");
}
}
D. The main function.
static void Main(string[] args)
{
int n = 0;
Console.WriteLine("请输入练习题数量:");
n = int.Parse(Console.ReadLine());
for(int i=1;i<=n;i++)
{
Program.Write(Solve(MakeFormula()));
Console.WriteLine(Solve(MakeFormula()));
}
}
The results show:
In the process of writing code does encountered many difficulties, but through access to information, and then the students discuss many of the issues have been resolved, gain a lot of knowledge.
4. Test Unit
5. Submit Code
According to job tips, links to their git accounts, upload their own code.
result.
Summary:
This job for me difficult challenges can be very large, long time do not write code, already feeling rusty, but finally completed on-line access code following information, as well as to discuss the students, the feeling of a job harvest a lot, I learned to use GitHub, and some Git operations, know a good project does not knock out the proper code, but also to maintain its simplicity, efficiency. In short a great harvest this assignment, also thanks to the support of other students.