285
社区成员




The Link Your Class |
https://bbs.csdn.net/forums/MUEE308FZU202201 |
|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608837246 |
|
The Aim of This Assignment |
lab 1_2 |
|
MU STU ID and FZU STU ID |
832001325 or 20122926 |
|
Personal Software Process Stages |
Estimated time (minutes) |
real time (minutes) |
Planning |
20 |
25 |
Estimate |
10 |
5 |
Development |
200 |
210 |
Analysis |
30 |
40 |
Design Spec |
30 |
40 |
Design Review |
10 |
10 |
Coding Standard |
30 |
25 |
Design |
30 |
30 |
Coding |
100 |
60 |
Code Review |
10 |
10 |
Test and debug |
30 |
30 |
Reporting |
70 |
70 |
Size Measurement |
10 |
10 |
Postmortem & Process Improvement Plan |
20 |
30 |
Total |
600 |
585 |
The link of github: https://github.com/ZYu158/lab-1_2/tree/main
In this experiment, we need to count the number of special characters. For this, my idea is mainly divided into four steps:
1. Open the file, read each word in each line, and determine whether the word is a keyword. In this process, look for the switch structure and look for the structure of the if_else statement.
2. When reading each word, we should make sure that the word starts with what and ends with what. For example, in my idea, each string starts with a letter and ends with a non-letter.
3. Determine whether this letter is a keyword. As we all know, there are 32 keywords in c++, we can build an array to store the keywords, count them, and then read them in the form of pointer or subscript in the code.
4. Then it is to record the number of occurrences of each string and output it in the main function.
The flow chart:
void question1_2(string a[])
{
int i, j;
for (i = 0; i < cnt1; i++)
{
for (j = 0; j <= 31; j++)
{
if (a[i] == keyword[j])
{
keyword_num++;
temp2[cnt2++] = a[i];
}
}
if (a[i] == "switch")
{
switch_num++;
case_cnt++;
}
if (a[i] == "case")
{
casenum[case_cnt]++;
}
}
}
void question3_4()
{
stack <string> s;
stack <int> have_elseif;
for (int i = 0; i < if_elseif_else.size(); i++)
{
if (if_elseif_else[i] == "{")
{
s.push("{");
have_elseif.push(0);
}
else if (if_elseif_else[i] == "}")
{
while (s.top() != "{")
{
s.pop();
}
s.pop();
have_elseif.pop();
}
else if (if_elseif_else[i] == "if")
{
s.push("if");
have_elseif.pop();
have_elseif.push(0);
}
else if (if_elseif_else[i] == "else_if")
{
have_elseif.pop();
have_elseif.push(1);
}
else if (if_elseif_else[i] == "else")
{
if (have_elseif.top())
{
if_elseif_else_num++;
}
else
{
if_else_num++;
}
have_elseif.pop();
have_elseif.push(0);
while (s.top() != "if")
{
s.pop();
}
s.pop();
}
}
}
void output(int Level)
{
if (Level == 1)
{
cout << "total num: " << keyword_num << endl;
}
if (Level == 2)
{
cout << "total num: " << keyword_num << endl;
cout << "switch num: " << switch_num << endl;
cout << "case num: ";
for (int i = 1; i <= case_cnt; i++)
{
cout << casenum[i] << " ";
}
cout << endl;
}
if (Level == 3)
{
cout << "total num: " << keyword_num << endl;
cout << "switch num: " << switch_num << endl;
cout << "case num: ";
for (int i = 1; i <= case_cnt; i++)
{
cout << casenum[i] << " ";
}
cout << endl;
cout << "if-else num: " << if_else_num << endl;
}
if (Level == 4)
{
cout << "total num: " << keyword_num << endl;
cout << "switch num: " << switch_num << endl;
cout << "case num: ";
for (int i = 1; i <= case_cnt; i++)
{
cout << casenum[i] << " ";
}
cout << endl;
cout << "if-else num: " << if_else_num << endl;
cout << "if-elseif-else num: " << if_elseif_else_num << endl;
}
}
int main()
{
int level;
string filename, temp;
char buffer[1];
cout << "please input file path:";
cin >> filename;
ifstream fin(filename.c_str());
cout << "input level:";
cin >> level;
if (!fin)
{
cout << "File opening failure" << endl;
}
else
{
while (getline(fin, temp))
{ // Input from disk file, read in line by line, processed line by line
keywords(temp);
}
fin.close(); // close
}
question1_2(temp1);
question3_4();
output(level);
}
Finally:
This is the first time in my life that I use the PSP form. I find that the actual completion time is almost always longer than my estimated time, so I think my ability needs to be improved, which requires training. I use c++because I have a good grasp of it. The use of flow charts has brought me great benefits. I can clearly understand the logical relationship between the previous and subsequent steps. Finally, I learned how to use github and how important it is to look up data and revise it repeatedly as I write code