GIT地址 | https://github.com/fengshikun123/Calculator |
---|---|
GIT用户名 | fengshikun123 |
学号后五位 | 24113 |
博客地址 | https://www.cnblogs.com/q1281037172/ |
作业链接 | https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/homework/7582 |
一、配置环境
1.VS2017安装与配置 2.GIT安装与配置、克隆项目
二、设计随机数四则运算项目
大致上用到switch,也用到了random生成随机数和多个循环语句。然后感觉方法是比较笨的那种,看起来就很长。
运行结果:
using System.IO; namespace AchaoCalculate { class CreatFile { public CreatFile(string st) { StreamWriter sw = new StreamWriter("D:/subject.txt", true); sw.WriteLine(st); sw.Close(); } } }
using System; using System.IO; using System.Collections.Generic; using System.Text; namespace AchaoCalculate { class PrintCalcuate { public PrintCalcuate(int n) { int i = 0; int a, b, c, d, e, f; string st; Random rd = new Random(); while (i < n) { a = rd.Next(0, 100); b = rd.Next(0, 100); c = rd.Next(0, 100); d = rd.Next(0, 100); e = rd.Next(0, 100); f = rd.Next(1, 100); int m =rd.Next(0,9); switch (m) { case 0: int end1 = b * c - a; st = b + "*" + c + "-" + a + "=" + end1; if (end1 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 1: int end2 = e - c + b; st = e + "-" + c + "+" + b + "=" + end2; if (end2 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 2: int end3 = e + f * d + c; st = e + "-" + f + "*" + d + "+" + c + "=" + end3; if (end3 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 3: int end4 = b / f + e; st = b + "/" + f + "+" + e + "=" + end4; if (b % f == 0 && end4 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 4: int end5 = c / f + c * d; st = c + "/" + f + "+" + c + "*" + d + "=" + end5; if (c % f == 0 && end5 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 5: int end6 = e - c / f; st = e + "-" + c + "/" + f + "=" + end6; if (c % f == 0 && end6 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 6: int end7 = e * f - c; st = e + "*" + f + "-" + c + "=" + end7; if (end7 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 7: int end8 = e * f - c + a; st = e + "*" + f + "-" + c + "+" + a + "=" + end8; if (end8 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 8: int end9 = e + c / f - a; st = e + "+" + c + "/" + f + "-" + a + "=" + end9; if (c % f == 0 && end9 >= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; case 9: int end10 = c - a / f + a; st = c + "-" + a + "/" + f + "+" + a + "=" + end10; if (a % f == 0 && end10>= 0) { Console.WriteLine(st); CreatFile sw = new CreatFile(st); i++; } break; default: break; } } } } }
using System; namespace AchaoCalculate { class Program { static void Main(string[] args) { Console.WriteLine("请输入出题数:"); int n = Convert.ToInt32(Console.ReadLine()); PrintCalcuate calcuate1 = new PrintCalcuate(n); Console.ReadKey(); } } }
三、单元测试
测试通过
四、效能分析
(结果见下图)
五、提交代码
中途操作失误了几次,但是总体来说还算简单,甚至一开始总是把Git 写成get。
总结
这次代码写的对我来说还是比较长的吧,不知道怎么开头,也在中间卡壳了很多次然后在室友的指点下操作了一番,最终还是写了出来。然后像git的操作还是能照葫芦画瓢慢慢做出来。