After 24 + hours of struggle, I finally completed the first software project. There are many twists and turns in the middle, and I have gained a lot of experience.
Expected completion time:Review C ++ (one hour), conception (half an hour), coding (four hours), debugging (two hours), and others (half an hour ). Total (8 hours ).
Actual completion time:Review C ++ (two hours); conception (half an hour); coding (three hours); debugging (five hours +); Optimization (three hours ). Total (13 hours + ).
The first is question review.
There are three points to note in this requirement:
1. the composition of words. The first three must be letters, followed by letters or numbers with many meanings. Other characters are considered as delimiters.
2. Case Insensitive
3. The file in 123file cannot be regarded as a word, so pay special attention when using a regular expression.
The second is the preliminary idea of the software.
Here I think about the following points:
1. The first is the language selection, C ++ and C #. I have never used these two languages systematically. I learned C # By myself during the summer vacation. I also read c ++ programming ideas last semester. however, we finally chose C ++, which is similar to the C language.
2. process-oriented or object-oriented. This program has three parts, but the three parts do not run at the same time, but decide which part to run based on the input of the command line parameters. So I chose object-oriented programming. Write the three parts of the program into three classes respectively, and create the corresponding object according to the command line input. In this way, the design process is relatively clear and reduces the chance of errors.
Note: The three parts have the same functions. You can consider dividing classes and combining the same parts to reduce code duplication and reduce coding workload. (But I have not done so yet, so I have no energy to modify it)
3. file scanning. Before using the Java language, some file classes can be used directly, which is quite convenient. However, when I started writing a program, I found that C ++ does not have such a class. Therefore, I used the powerful structure _ finddata_t after various Baidu and inquiry personnel. (Although I have not fully understood the function of this struct) so that we can recursively scan the file directory.
4. Then the words are read. There are roughly two methods: one is to read characters one by one, and the other is to read all characters and then analyze them. I personally prefer the latter, because batch processing is highly efficient and the code is concise.
5. Finally, the data structure of result storage. One is a linear table and the other is a binary tree. However, the program involves searching for identical elements, so Binary Trees save a lot of time.
The following is the program test result. I first tested the installation directory of.
The performance analysis is as follows:
Because I didn't use a hash table, the program efficiency is not too high, but it is acceptable.
Problems encountered during encoding:
1. Initialization. It is best to initialize any object before use to avoid program crash.
2. Create a binary tree. I have committed this problem more than once. (Reflection should be taken) that is, when recursion is established, the newly created node is not connected to the root of the tree. So the program crashes.
3. program efficiency issues. At the beginning, I used vector to store the data. When the test data volume is large, it took a lot of time. Later, the binary tree was used for storage, which significantly improved the efficiency.
What have you learned:
1. Before programming, we should have a general idea of the program.
2. Good Programming habits should be developed to reduce the code error rate.
3. The program should be optimized in terms of data structures and algorithms.
Thoughts on the first project of Software Engineering