GIT地址 | https://github.com/saodan |
GIT用戶名 | saodan |
學號后五位 | 32125 |
博客地址 | 個人博客 |
作業鏈接 | 作業鏈接 |
一、配置環境
1.VS2013安裝與配置

2.GIT安裝與配置

二、克隆項目
1.登錄我的github主頁
2.進入阿超倉庫的網址,點擊右上角的 Fork ,將阿超的四則運算庫拷貝到自己的同名倉庫中


3.將項目克隆到電腦文件夾(F:\軟工作業)

三、設計隨機數四則運算項目
1.設計思路:
隨機數生成:
設計思路:利用random生成隨機數,並用數字1、2、3、4代替運算符:+、-*、/。
int seed = Guid.NewGuid().GetHashCode();//隨機數種子
Random random = new Random(seed);
List<int> fh=new List<int>();
List<int> list=new List<int>();
for (int i = 0; i < len;)
{
int fh_len1 = random.Next(2,4);//fh_len1:題目的符號數量
for (int j = 0; j < fh_len1; j++)
{
int h = random.Next(1, 5);
fh.Insert(j, h);//隨機生成運算符
}
for (int j = 0; j < fh_len1 + 1; j++)
{
int h = random.Next(0, 101);
list.Insert(j, h);//生成隨機數
}
}
除數是否為0的判斷:
設計思路:利用字典索引,將數字還原成運算符,再判斷除號下一位是否為0
public bool test_ce(List<int> fh, List<int> list)
{
int j = 0;
Dictionary<int, string> hash = new Dictionary<int, string> { { 1, "+" }, { 2, "-" }, { 3, "*" }, { 4, "/" } };
foreach (int i in fh)
{
if (hash[i] != "/")
{
j++;
continue;
}
else
{
if (list[j + 1] != 0)
return true;
else
return false;
}
}
return true;
}
四則運算:
Dictionary<int, string> hash = new Dictionary<int, string> { { 1, "+" }, { 2, "-" }, { 3, "*" }, { 4, "/" } };
int len = fh.Count();
string ji=null;
/*組裝運算式*/
for(int i=0,j=0;i<len;)
{
if (j < fh.Count())
{
ji += list[i] + hash[fh[j]];
j++;
}
else
{
ji += list[i];
i++;
}
i++;
}
ji += list[len];
/*利用datatable().Compute進行四則運算*/
var r = new DataTable().Compute(ji, null);
int num;
if (int.TryParse(r.ToString(),out num))//判斷計算結果是否為整數
{
str = ji + "=" + r.ToString()+"\n";
Console.Write(str);
t = true;//判斷成功生成一個運算式
}
運行結果寫入txt
string path = @"F:/四則運算.txt";
File.WriteAllText(path, "");//清空文本
...
File.AppendAllText(path, str);
運行結果:

2.代碼提交
操作指南:如何使用git把本地代碼上傳(更新)到github上
四、單元測試
隨機數項目的編碼是在VS2013中完成的,但在進行單元測試時發現,我安裝的vs版本很難進行單元測試,所以就卸載了vs2013重新安裝了vs2017進行單元測試。
- 測試一:測試除數為0判斷模塊
- 測試二:測試小數判斷模塊
- 測試三: 計算值模塊測試,測試前,我先將計算值結果變量"r”改為public類型。
五、回歸測試

六、效能工具
運行效能工具前,修改Program類:
```c class Program { static void Main(string[] args) { //int len = int.Parse(Console.ReadLine()); Sui s = new Sui(/*len*/100000);//生成100000個運算式 } } ```


七、提交代碼到Github

八、存在的問題及感想體會
- 英語水平差,很難讀懂github的英文資料;在項目編碼時,很多的變量都采用的漢語拼音式的編碼;同時還不能熟練運用單元測試。像github中很多的資料是英文資料,所以提高英語水平對使用github,vs等項目工具很有幫助。