Individual features of the project source statistical procedures (C ++)

Zero, GitHub address

https://github.com/King-Authur/Word-count

First, the relevant requirements of the project

wc.exe is a common tool, it can count the number of characters of text files, words, and lines. The project asked to write a command line program, to mimic the function of the existing wc.exe, and be expanded, given the number of characters in a programming language source files, words, and lines.

Implement a statistical program, the number of characters it can correct statistics program file, the number of words, lines, and also has other extended functions, and can handle multiple files quickly.

Specific functional requirements:
a program mode processing user needs to: wc.exe [parameter] [file_name]

The basic feature list:
wc.exe -c file.c // returns the number of characters in the file file.c

The number of wc.exe -w file.c // Returns the file of the word file.c

wc.exe -l file.c // returns the number of rows of file file.c

Extensions:
-s recursive processing files that meet the conditions of the directory.
-a return more complex data (line / space lines / comment lines).

Blank line : Bank format all control characters or spaces, if included code, no more than a displayable character, such as "{."

Line : Bank codes comprises more than one character.

Comment lines : lines of code instead of the Bank, and the Bank includes comments.
An interesting example is that some programmers will add a comment behind a single character:
} //注释
In this case, the line belongs to the comment line.

[file_name]: file or directory name, you can handle general wildcard .

Advanced Features:

-x parameter . This parameter is used alone. If you have the command line parameters, the program will display a graphical interface , the user can select a single file through the interface , the program will display the file number of characters, lines, etc. All the statistics .

Demand For example :
  wc.exe -s -a * .c
returns the number of lines of code the current directory and all subdirectories * .c files, the number of blank lines, the number of comments.


Requires simplified
basic functions
support -c
support -w
support -l

Extended Function
Support -s parameter
support -a parameter
supports a variety of file wildcard (* ,?)

Advanced features
basic operating procedures of the Windows GUI
support through a graphical interface to select files
support information through a graphical interface to show files

Second, the difficulties encountered and solutions

(A) how to use the command line to run the program
after access to relevant information, we summarize the knowledge and methods, and write it again blog
https://blog.csdn.net/WHY995987477/article/details/104905196

(B) how to implement basic functions
First set a good standard of judgment

Characters: letters, characters in a computer
word: string consists of one or more letters form continuous
lines: the sum of blank lines and non-blank lines of
the line of code: a non-blank lines and non-comment line
blank lines: a space, a carriage return, tab,} row configuration of
comment lines: \\ contains and it is not contained within two double quotes

The idea is, step by step in accordance with the code that implements the standard, to calculate the results.

(C) how recursive queries folder
method found so far is to learn MFC, call the Windows API, such as FindFirstFile and FindNextFile function, still unresolved, is still learning.

(D) wildcard? And * how
unresolved

(E) to implement graphical interface
unresolved

Third, the key code and design specifications

Design
using a design procedure for the
Here Insert Picture Description
current implementation of the four functions

void get_flag(int argc, char **argv);
void calculate_information(char *file_path);
bool is_char(char ch);
void display();

The key code
This function is used to calculate all the questions you want to ask our data, including characters, words, lines, blank lines, comment lines number of lines of code.

void calculate_information(char *file_path);

Code implementation

void calculate_information(char *file_path){
FILE* fp = fopen(file_path, "r");//只读打开文件路径指向的文件
if(fp == NULL){//检测是否是有效路径
printf("!!!错误!!!\n请检查文件路径是否正确\n");
exit(-1);//关闭程序
}
char buffer[maxn_word_of_line];//存取当前行数据的缓存区
while(!feof(fp))//是否到文件尾
{
buffer[0] = '\0';
fgets(buffer, maxn_word_of_line, fp);//一整行读取
res.line++;

int len = strlen(buffer);
bool left_blank = true, is_Empty = true;
for(int i = 0; i < len; i++)
{
if(is_char(buffer[i]))///如果是非空字符
{
res.character++;///那么字符数要增加
is_Empty = false;///并且这一行不为空
}

if(isalpha(buffer[i]))///当它是字母时
{
if(left_blank)///当左边被其他字符隔开时
{
res.word++;///单词数目+1
left_blank = false;
}
}
else///当前字符不是字母
{
left_blank = true;///则视为它是隔开单词的字符
}
}
if(is_Empty)///这一行为空行
{
res.empty_line++;
}
else///这一行非空,判断一下是否为注释行
{
bool left_quote = false;///左双引号
bool slanting_bar = false;///斜杆
bool explain_flag = false;///注释行的标记
///过滤掉包含于字符串输出的“假注释”,例如:printf("//");
for(int i = 0; i < len; i++)
{
if(buffer[i] == '"')///如果是双引号
{
if(!left_quote)///如果没有左边匹配的双引号
{
left_quote = true;
}
else
{
left_quote = false;///左边有可以匹配的双引号
}
}

if(buffer[i] == '/' && buffer[i + 1] == '/')///如果有连续的两个反斜杠
{
slanting_bar = true;
}

if(!left_quote && slanting_bar)///如果斜杠没有被包含在字符串的输出中,则这一行必定为注释行
{
res.explain_line++;
explain_flag = true;
break;
}
}
if(!explain_flag)///不是注释行,就是代码行
{
res.code_line++;
}
}
}
}

This function reads the entire file line by line, each line traversing two can calculate all the information diverted, the information stored in the structure, constantly updated until the end of the file to read.
Output decide what the output from the passed parameters.

Fourth, the test run

Test together with the base portion of the extended portion -a
1, file test only two blank lines are
Here Insert Picture Description
correct

2, the test contains only two words, ten characters of the file
Here Insert Picture Description
is correct

3, test a simple code
Here Insert Picture Description
inspection found that
printf("\\");not to be mistaken for comment lines
printf("Hello world\n");//Hello worldand }//注释the right to be recognized as a comment line
results are also correct other data

Test file path
4, entered the wrong file path
Here Insert Picture Description
displays error messages

Five, PSP form

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

VI Project Summary

1, are not familiar with object-oriented programming, using the process-oriented programming
2, there is no recognition / ** / comment code
3, recursive file folder function graphical interface has not been completed and
4, are not familiar with the use of GitHub
5, and code to achieve when tested some small mistakes, resulting in more time spent
6, do not use Windows SDK programming
7 of their results are not satisfied, the follow-up will continue to update and improve
8,

VII reference source

Individual software engineering project work: https://edu.cnblogs.com/campus/gdgy/se18_12/homework/10477
Project blog template: https://www.cnblogs.com/vertextao/p/7469789.html
"building law ": https://max.book118.com/html/2019/0901/6141233210002101.shtm
VS2015 C ++ installation and simple unit test: https://www.cnblogs.com/xiaoyongwu/p/5289964.html

Guess you like

Origin www.cnblogs.com/Authur-gyc/p/12563500.html