天天看點

軟工實踐第二次作業——個人項目實戰

1.Fork倉庫的Github項目位址

2.PSP表格:

PSP2.1 Personal Software Process Stages 預估耗時(分鐘) 實際耗時(分鐘)
Planning 計劃 60 30
• Estimate • 估計這個任務需要多少時間
Development 開發 600 440
• Analysis • 需求分析 (包括學習新技術) 120
• Design Spec • 生成設計文檔
• Design Review • 設計複審 20
• Coding Standard • 代碼規範 (為目前的開發制定合适的規範)
• Design • 具體設計
• Coding • 具體編碼 100
• Code Review • 代碼複審
• Test • 測試(自我測試,修改代碼,送出修改)
Reporting 報告 150
• Test Repor • 測試報告
• Size Measurement • 計算工作量
• Postmortem & Process Improvement Plan • 事後總結, 并提出過程改進計劃
合計 780 720

3.計算子產品接口的設計與實作過程

接收檔案查閱資料用ifstream fp(argv[1])

int main(int argc, char* argv[])
{
	int characters =0;//字元個數
	int words = 0;    //單詞個數
	int lines = 0;    //有效行數
	char ch;          //文本字元
	int lvalid = 0;   //判斷行有效
	int process = 0;  //自動機狀态
	ifstream fp(argv[1]);//打開檔案
	string word;      //接收單詞
    map<string,int> word_count;//構造map容器
	if (!fp)//判斷檔案是否打開
	{
		cout << "未能成功打開" << argv[1] << ",請檢查檔案是否存在";
		getchar();//給使用者檢視錯誤的時間
		exit(1);
	}
	while (fp.get(ch))//讀到檔案尾
           

寫result.txt參照資料用ofstream fout("result.txt");

int nSize = word_count.size(),i=1;
	multimap<int, string, greater<int> > mapt;

	for (map<string, int>::iterator it1 = word_count.begin(); it1 != word_count.end(); ++it1)
	{
		mapt.insert(pair<int, string>(it1->second, it1->first));//将word_count輸入到mapt
	}
	
	fp.close();
	ofstream fout("result.txt");
	fout << "characters: "<<characters<< endl;
	fout << "words: " << words << endl;
	fout << "lines: " << lines << endl;
	if (nSize <= 10)
	{
		for (map<int, string>::iterator it2 = mapt.begin(); it2 != mapt.end(); ++it2)
		{
			fout << "<" << it2->second << ">: " << it2->first << endl;
		}
	}
	else
	{
		for (map<int, string>::iterator it2 = mapt.begin(); ; ++it2)
		{
			if (i > 10) { break; }
			i++;
			fout << "<" << it2->second << ">: " << it2->first << endl;
		}
    }
	fout.close();
           

前幾天編譯原理剛好上了有關自動機的課程,于是這次作業就用上了

軟工實踐第二次作業——個人項目實戰
switch (process)//無窮自動機
			{
		case 0:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
			   else { word = ""; process = 0; }break;
		case 1:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
			   else { word = ""; process = 0; }break;
		case 2:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
			   else { word = ""; process = 0; }break;
		case 3:if (ch >= 97 && ch <= 122) { word = word + ch; process++; }
			   else { word = ""; process = 0; }break;
		case 4:if (ch != ' '&& ch != '\n') { word = word + ch; }
			   else { ++word_count[word]; process = 0; word = ""; words++; }break;
			}
           

4.計算子產品接口部分的性能改進

改進思路:由于對C++掌握不精,隻想到了按字元讀取檔案,在翻看資料時又看到說可能一次性讀取效果更好,但來不及更改等之後再改

5.計算子產品部分單元測試展示

input.txt

軟工實踐第二次作業——個人項目實戰

result.txt

軟工實踐第二次作業——個人項目實戰

測試結果lines為零很讓我驚訝,檢查代碼發現是因為我把換行符的出現視為一行,沒有問清是否是以換行符劃分行是我準備不足;

不過想不到其他劃分行的辦法查閱資料也沒發現其他方法,下次提早把疑問搞清。

6.計算子產品部分異常處理說明

有個異常是因為“”内變量會轉化為字元,在老師,同學的幫助下發現了問題換了一種表達ifstream fp(argv[1]);去掉了“”。

收獲:發現了自己的許多不足。一次作業就困難重重,離軟體開發還有很長的路要走。也收獲許多新知識——

參閱資料:

在【統計檔案中字元個數】這篇文章中我學會了讀寫檔案;

【Map容器的使用總結】教會了我map的使用;

還運用了不太熟練的map以value為準降序排序的方法。