项目git链接
Word Counter
项目要求
设计一个wc.exe命令行程序
- 实现一个简单而完整的软件工具(源程序特征统计程序)。
- 进行单元测试、回归测试、效能测试,在实现上述程序的过程中使用相关的工具。
- 进行个人软件过程(PSP)的实践,逐步记录自己在每个软件工程环节花费的时间。
功能
基本功能
1. -c 输出文本的字符数
2. -w 输出文本的单词数
3. -l 输出文本的行数
扩展功能
1. -s 输出目录下所有符合的文件信息
2. -a 输出文本的注释行、空行、代码行
3. *.* 文件名支持输入通配符
高级功能
1. -x 单独使用,打开GUI界面,可以用图形界面选择文件,并输出信息
遇到的困难及解决方法
1.学习git的使用
百度,官方文档,明白了git同步文件夹+版本控制的功能
2.图形界面
使用Qt实现,看视频和文档,只能保证最低限度的完成
一开始想使用Win32Api实现窗口,但是没成功,所以去使用封装度很高的Qt了,比较方便
但是以前图形界面方面的接触比较少,一开始还是有很多细节不懂,比价麻烦
关键代码or设计说明(C++)
统计总函数,-c -l -w -a
按行循环读取文本中的字符,直到读取完最后一行,对每一行统计其项目,这样可以比较有方便的扩展功能。
void count(){
memset(&this->num, 0, sizeof(this->num));
string str;
while (getline(inFile, str))
{
num.ch += count_char(str);
num.word += count_word(str);
num.line += count_line(str);
num.codeline += code_comment(str).first;
num.comment += code_comment(str).second;
num.spaceline += isspace(str);
}
}
通配符和遍历子目录,-s *.*
利用system的dir命令完成子目录的遍历
//用system的dir命令获取文件目录
void GetAllDir(const string &dir)
{
freopen(pathFileName, "w", stdout);
system((string("dir /b 2>NUL ") += dir).c_str());
fclose(stdout);
freopen("CON", "w", stdout);
}
//筛选出文件目录,存入vector并返回
vector<string> GetSubDir(string dir)
{
GetAllDir(dir);
vector<string> res;
string str;
ifstream ifs(pathFileName);
if (!ifs.is_open())
{
cout << "Fail";
exit(0);
}
while (ifs >> str)
{
string t = dir;
(t += "\\") += str;
QFileInfo fi(t.c_str());
if (fi.isDir())
res.push_back(t);
}
ifs.close();
return res;
}
Qt的图形界面,-x
//按钮被点击后的操作
void MainWindow::on_pushButton_clicked()
{
//弹出文件选择界面
QString FilePath = QFileDialog::getOpenFileName(this);
WC wc;
//输出统计的信息
if(wc.open(FilePath.toStdString())){
wc.count();
QString str="";
((str += " 字符 数量 : ")+= int_to_Qstring(wc.num.ch))+= "\n";
((str += " 单词 数量 : ")+= int_to_Qstring(wc.num.word))+= "\n";
((str += " 行数 :")+= int_to_Qstring(wc.num.line))+= "\n";
((str += " 代码行 :")+= int_to_Qstring(wc.num.codeline))+= "\n";
((str += " 注释行 :")+= int_to_Qstring(wc.num.comment))+= "\n";
(str += " 空白行 :")+= int_to_Qstring(wc.num.spaceline);
QMessageBox::information(this,"Word Counter",str);
}
}
测试
图形和各种计算
-s和通配符功能
会寻找子目录下的文件
在win的终端下,如果当前的目录下有符合通配符的文件会直接匹配上,导致命令行命令输入*.*后进入程序的会是直接匹配为其中一个符合的文件名,导致无法使用*参数
PSP
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | ||
· Estimate | · 估计这个任务需要多少时间 | 10 | 15 |
Development | 开发 | ||
· Analysis | · 需求分析 (包括学习新技术) | 400 | 610 |
· Design Spec | · 生成设计文档 | 20 | 10 |
· Design Review | · 设计复审 (和同事审核设计文档) | 0 | 0 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | 10 | 10 |
· Design | · 具体设计 | 30 | 10 |
· Coding | · 具体编码 | 180 | 240 |
· Code Review | · 代码复审 | 10 | 5 |
· Test | · 测试(自我测试,修改代码,提交修改) | 30 | 100 |
Reporting | 报告 | ||
· Test Report | · 测试报告 | 60 | 30 |
· Size Measurement | · 计算工作量 | 5 | 10 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | 20 | 15 |
合计 | 775 | 1060 |
学习进度条
项目 | 时间 |
---|---|
简单的Markdown | 10 |
git | 120 |
windowsAPI | 180 |
Qt | 300 |