系統分析與設計課程個人項目作業1
阿新 • • 發佈:2018-09-24
strcmp href posit report read proc -o stand 總結
系統分析與設計課程個人項目作業1
1.項目地址:gitee地址
2.項目簡介
① 根據輸入顯示出給定文件的大致信息,具體包括字符數、單詞數、行數(基本功能),顯示註釋行、空行...(擴展功能) 、以圖形界面展示信息(高級功能).
② 根據用戶的輸入選擇目標文件,根據用戶的輸入判定是否生成新輸出文件.
3. 需求分析
具體說明如下: ① 用戶在命令行運用如下格式命令執行程序:wc.exe [ 參數 ] 輸入文件名 [ -o ] 輸出文件名. ② 對於參數選項具體說明:至少存在一項(-w :統計文件,-l 統計行數,-c :統計字符). ③ 對於輸入文件名選項具體說明:不可省略. ④ -o選項具體說明:可省略. ⑤:對輸出文件名選項具體說明:可省略,但倘若出現,前面一定跟著輸出"-o"參數.
4.psp表格
PSP2.1 | PSP階段 | 預估耗時(分鐘) | 實際耗時(分鐘 ) |
---|---|---|---|
Planning | 計劃 | 60 | 75 |
Estimate | 估計這個任務需要多少時間 | 15 | 10 |
Development | 開發 | 180 | 120 |
Analysis | 需求分析 (包括學習新技術) | 120 | 60 |
Design Spec | 生成設計文檔 | 60 | 45 |
Design Review | 設計復審 (和同事審核設計文檔) | 45 | 15 |
Coding Standard | 代碼規範 (為目前的開發制定合適的規範) | 15 | 10 |
Design | 具體設計 | 60 | 140 |
Coding | 具體編碼 | 60 | 75 |
Code Review | 代碼復審 | 20 | 30 |
Test | 測試(自我測試,修改代碼,提交修改) | 45 | 80 |
Reporting | 報告 | 60 | 85 |
Test Report | 測試報告 | 30 | 40 |
Size Measurement | 計算工作量 | 30 | 35 |
Postmortem & Process Improvement Plan | 事後總結, 並提出過程改進計劃 | 30 | 90 |
合計 | 830 | 920 |
5.解題思路
問題的關鍵點:幾個問題??
①不同於常見的控制臺程序,對於在命令行的輸入,我們如何 讀取出輸入信息?
②針對讀取的輸入,我們如何識別出不同的參數?
③針對已經識別出來對應的輸入參數,我們如何實現具體的功能?提出問題的解決方案
① 參見C語言命令行參數的使用
② 借助C語言庫函數strcmp與指定的字符串進行比較。(當然為了使得項目靈活性更高,我們可以將我們的參數名稱寫在配置文件中,抑或宏定義實現).
③ 對不同的參數,實現不同的函數,當我們識別出不同的參數時,調用不同的函數即可.
6. 程序設計實現過程
程序的主體大致由幾個函數組成:
- coput_Charnum
/*
*
* 統計文件中字符數目
* @輸入:char* outtextname:輸入文件名 char* inputtxtname:輸出文件名
* @輸出:將信息寫入 inputtxtname 指定的文件中,采用的是追加方式
**/
void coput_Charnum( char* infilename ,char* outfilname )
{
//文件指針
FILE* input = Openfile( infilename ,"r");
char ch = fgetc( input );
int char_count = 0;
while( !feof( input ) ){
ch = fgetc( input );
char_count ++;
}
//printf(" 統計字符數目:為%d ",char_count);
//在outfilename中寫入結果
FILE* output = Openfile( outfilname , "a+" );
//寫入文件
fprintf( output ,"%s, 字符數:%d\n", infilename , char_count);
Closefile( input ,output );
//printf("模擬統計字符數!");
return ;
}
- coput_Wordnum
/*
*
* 統計輸入文件單詞總數
* @輸入:char* outtextname:輸入文件名 char* inputtxtname:輸出文件名
* @輸出:將信息寫入 inputtxtname 指定的文件中,采用的是追加方式
**/
void coput_Wordnum( char* infilename ,char* outfilname )
{
//文件指針
FILE* input = Openfile( infilename , "r" );
char ch = fgetc( input );
int count = 0;
while( !feof( input ) ){
ch = fgetc( input );
if( ch == ‘\n‘ || ch == ‘ ‘){count ++;}
}
FILE* output = Openfile( outfilname , "a+" );
//outfilename中寫入結果,意此處的 count + 1
fprintf( output ,"%s, 單詞數:%d\n", infilename , count + 1 );
Closefile( input ,output );
return ;
}
- coput_Linenum
/*
* 統計總行數
*@輸入:char* outtextname:輸入文件名 char* inputtxtname:輸出文件名
*@輸出:將信息寫入 inputtxtname 指定的文件中,采用的是追加方式
**/
void coput_Linenum( char* infilename ,char* outfilname )
{
//文件指針
FILE* input = Openfile( infilename , "r" );
char ch = fgetc( input );
int count = 0;
while( !feof( input ) ){
ch = fgetc( input );
if( ch == ‘\n‘){count ++;}
}
//printf(" 統計字符數目:為%d ",char_count);
//在outfilename中寫入結果
FILE* output = Openfile( outfilname , "a+" );
//註意此處的 count + 1
fprintf( output ,"%s, 行數:%d\n", infilename , count + 1 );
Closefile( input ,output );
return ;
}
7.測試文件
[詳情gitee地址](https://gitee.com/TBLGSn/Homework1.git )
- 測試結果
1.程序在輸入正常的條件下,能較好的完成預期的工作
對於-w -c -l 參數均表現良好
2.程序在輸入有誤的條件下,不能完成預期的工作:
①.對於”,“的識別仍存在問題,具體表現在,-w 參數不能將其識別為分割符
②.對於中文字符,程序根本不能正常工作
③.對於空白文件-w -l 不能正常工作
8.參考文獻
- git pull時報錯fatal: Could not read from remote repository.
- 碼雲gitee+git入門篇(二)——代碼托管
- warning: LF will be replaced by CRLF in 解決辦法
系統分析與設計課程個人項目作業1