The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ?category=0 |
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/600798588 |
The Aim of This Assignment | Code personally & learn git and github & learn the process of writing a project & learn unit test and performance test |
MU STU ID and FZU STU ID | 19105886 &831902204 |
My Github Library
The code has been uploaded
https://github.com/zxc123asd456/nova
PSP FROM
Personal Software Process Stages | Estimated Time (minutes) | Actual Time (minutes) |
---|---|---|
Planning | 20 | 15 |
Estimate | 20 | 20 |
Development | 0 | 0 |
Analysis | 240 | 360 |
Design Spec | 0 | 0 |
Design Review | 0 | 0 |
Coding Standard | 30 | 30 |
Design | 60 | 50 |
Coding | 120 | 150 |
Code Review | 60 | 60 |
Test | 60 | 60 |
Test Report | 0 | 0 |
Size Measurement | 20 | 15 |
Postmortem & Process Improvement Plan | 20 | 20 |
Total | 650 | 780 |
Idea of solving problem
1. Decomposing tasks: When I first saw this problem, I scanned the requirements of the problem and found out the points that I had difficulty in, first, how to import the.c file, which form should be used for matching, and second, the definition of "keyword" and the judgment of different structures. Determined the difficulty, I probably want to convert the file into a string form for matching, so I first study the body of the code - the "keyword" part:
2. As for the keyword search part of the problem content, the first thing that came to my mind was the string matching problem I had learned in C language before. I went through the process to find the corresponding keyword and recorded it. So I think of all the key words to build a table to record, based on my choice of programming language is c + +, c + + object-oriented programming reminds me of the nature of class to create a program, to record the program object to establish an array of objects, the nature of the definition of each object are keywords and occurrences, keyword is encountered in traversed number plus one of the key words. But when I ran into trouble, it is how to keywords and application of a number of matches, check a lot of information here, spent a lot of time, later in the discussion with your classmates, I learned the find () function, can be directly through the find function to find the current string, if has the return key word in the correct value, Can solve the problem of both match each other, the next question is how to convert (.) c program into a string, as we can match the pattern, at first I think is will. C file save as. TXT file to read, to open the file on the network of function is complicated, at first I choose the fopen () function, I didn't find any strings, so I just opened the file. Then I went to in (), opened the.txt file successfully, and read the file line by line using getLine (). Having solved the input problem, I could write the function and test it.
Design implementation process
First we read the file, it is easy so let's just do it in the main method.
string file_name;
/* input file address*/
cout << "Please enter the file address:" << endl;
cin >> file_name;
ifstream in(file_name.c_str());//read the file (example:./test.c)./
string str;
if (in.is_open())
{
while (!in.eof())//file -> str
{
getline(in, str); //search by lines
Search_name(str);
Ifelse_judge();
}
}
else
{
cout << "Error opening " << file_name << " for input" << endl;
return -1;
}
Second Keyword record
Because only keywords and {} symbols are needed, only these are recorded. If the character is a letter, continue reading until it is a space, and then compare it with the keyword table. If it is one of the characters, note it down.
public:
string name;//Keyword
int number; //Keywords' numbers
void Search_name(string);//the function of searching keywords
void Print_number();
void Switch_search(int);
void Case_count(int);
void Ifelse_search(int);
void Ifelse_judge();
};
/*Define the keyword array*/
program keyword[32] =
{ "auto", 0,"break",0,"case",0,"char",0,"const", 0,"continue",0,"default",0,"do", 0,
"double",0,"else",0,"enum",0,"float",0,"for",0,"goto",0,"if",0,"int",0,
"long",0,"register",0, "while",
0,"reuturn",0,"short",0,"signed",0,"sizeof",0,"static", 0,
"struct",0,"switch",0,"typedef",0,"union",0,"unsigned",0,"void", 0 ,
"volatile",0,"while", 0 };
/*declare variables and functions*/
/*advanced requirements*/
int switch_number = 0;
int case_number[50] = {0};
/*further requirements*/
int ifelse_number = 0;
bool If_flg = false, Else_flg = false;
int Stack[101] = {0}; //define ifelse's stack
int top = 0; //stack's top
int flg = 0;//"else if"'s flag
/*final requirements*/
int ifelseifelse_number = 0;
The test results
The performance test
Summary
On the whole, I personally think this assignment helped me a lot.
1. This programming assignment clearly exposed my lack of programming ability caused by lack of practice at ordinary times, and I often felt difficult in the process of writing codes. Some problems could not be well realized even if I had certain ideas, which reminded me that the training of code ability should be emphasized at ordinary times.
2. Let me see the gap between myself and other students. When writing blogs, many students have finished their homework.
3. Exercise my ability of self-study, most have taught course code, before the work is the need to find information and contact the learned knowledge to complete, for all kinds of coding methods and new functions of learning, to learn, through the network to achieve different functions, I also find a lot of English websites, The ability to retrieve and query data has been improved.
4. I learned to test and improve the code performance after coding, which I had never used before. The test of the code was also an indispensable part of the whole process, which enabled me to have a deeper understanding of coding and project implementation.
5. Learned the basic usage of GitHub and some Git commands, committed my own code constantly, learned the basic operations of programmers, and had a better understanding and mastery of open-source coding methods in the future.
I see a long way to go. I hope I can do better and better in the following assignments and constantly improve my ability.