Individual project -word counter

Project git link

Word Counter

Project requirements

A command-line program designed wc.exe

  1. Achieve a simple and complete software tools (statistical characteristics of the source program).
  2. Unit test, regression test, performance test, the use of associated tools in the course of achieving the above program.
  3. To practice Personal Software Process (PSP), and gradually record their own time spent in each part of software engineering.

Features

basic skills
1. -c 输出文本的字符数
2. -w 输出文本的单词数
3. -l 输出文本的行数
extensions
1. -s 输出目录下所有符合的文件信息
2. -a 输出文本的注释行、空行、代码行
3. *.* 文件名支持输入通配符
Advanced Features
1. -x 单独使用,打开GUI界面,可以用图形界面选择文件,并输出信息

Difficulties encountered and solutions

1. The use of learning git

Baidu, official documents, understand the function of synchronizing folders + git version control

2. GUI

Using Qt realize, watching videos and documents can only guarantee the completion of a minimum
start using Win32Api want to achieve window, but did not succeed, so a high degree of encapsulation to use Qt, and more convenient
but before contact interface aspects of the graphic is relatively small , at the beginning there are still many do not understand the details, get in trouble

The key code or design specification (C ++)

Statistics overall function, -c -l -w -a

Row loop reads characters in the text, until you read the last line of each line item of its statistics, so you can have more convenient extensions.

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);
    }
}
Wildcards and traverse subdirectories, -s *. *

The complete system using the dir command to traverse subdirectories

//用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 graphical interface, -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);
    }
}

test

Graphics and a variety of computing



-s and the wildcard feature

We will look for files in subdirectories

In the end win, and if there is compliance with the wildcard in the current directory files directly match the resulting command line, enter *. * After entering the program would be a direct match for the filename where a compliant, making it impossible to use * parameter

PSP

PSP2.1 Personal Software Process Stages Estimated time consuming (minutes) The actual time-consuming (minutes)
Planning plan
· Estimate • Estimate how much time this task requires 10 15
Development Develop
· Analysis · Needs analysis (including learning new technologies) 400 610
· Design Spec Generate design documents 20 10
· Design Review · Design Review (and his colleagues reviewed the design documents) 0 0
· Coding Standard · Code specifications (development of appropriate norms for the current development) 10 10
· Design · Specific design 30 10
· Coding · Specific coding 180 240
· Code Review · Code Review 10 5
· Test · Test (self-test, modify the code, submit modifications) 30 100
Reporting report
· Test Report · testing report 60 30
· Size Measurement · Computing workload 5 10
· Postmortem & Process Improvement Plan · Hindsight, and propose process improvement plan 20 15
total 775 1060

Learning progress bar

project time
Simple Markdown 10
git 120
windowsAPI 180
Qt 300

Guess you like

Origin www.cnblogs.com/shakugannoshana/p/12530967.html