lab1-2

The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZU202201
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/608734907
The Aim of This Assignmentextract keywords
MU STU ID and FZU STU ID20123345_832002112

repository

commit
在这里插入图片描述

PSP table

PSPContent of the taskTime to plan for completion (min)Actual completion time (min)
Planningplan3010
EstimateEstimate how much time the task will take and map out the steps105
DevelopmentThe process of developing software--
AnalysisRequirements analysis (including learning new technology)3020
Design SpecGenerating design Documents--
Design ReviewDesign review--
Coding StandardCode specification (appropriate specification for current development)1020
DesignThe specific design6045
CodingSpecific coding500800
Code ReviewCode review6030
testTesting (self-testing, modifying code, submitting changes)400500
Test ReportTest results are reported and analyzed2020
Size MeasurementCalculation of effort55
Postmortem & Process Improvement PlanSummarize afterwards and propose the process improvement plan6060
Summaryconclusion11851515

Procedure

The process of solving the problem

  • first need to know how to read the file and read the contents of the file
  • After reading the contents of the file, you need to know how to divide the keywords. Fortunately, the test file only contains the key fields of switch, if-else and case, so you don’t need to consider so many cases. After these keywords structure division, and statistics of the number of occurrences
  • According to the document from the basic to progressive development, the first development of simple data reading function, can enhance the expansion, write all the keywords into an array, and then each time from the array for two-dimensional search, find the corresponding keywords, and then count the number. This section only contains some keywords. The range of a keyword is judged by the position of the parentheses and the beginning, end and end symbol of the keyword

flow chart

在这里插入图片描述
the switchcase
在这里插入图片描述

the if else
在这里插入图片描述

main code

count all num

string Count_Key_Num(const string& str) {
    int start_index = 0, end_index;;
    string NewStr = DeleMuch(str);
    end_index = NewStr.length();
    BinSearch(start_index, end_index, NewStr);
    regex z("else if");
    NewStr = regex_replace(NewStr, z, "elseif");
    for (int i = 0; i < KeyNum; i++)
    {
        if (key[i].num != 0)
        {
            TotalNum += key[i].num;
            // cout << key[i].word << " num: " << key[i].num << endl;
        }
    }
    cout << "total num: " << TotalNum << endl;
    // cout << NewStr << endl;
    return NewStr;
}

count switch case

string Count_SwiCase_Num(const string& str) {
    string NewStr = Count_Key_Num(str);
    int len = NewStr.length(), index = 0, cnt;
    stack<int> IdxStack;
    
    while ((index = NewStr.find("switch", index)) < len && (index != -1))
    {
        IdxStack.push(index);
        index++;
        // cout << "index:" << index << endl;
    }
    printf("switch num: %d\n", key[SwitchIdx].num);
    printf("case num:");
    vector<int> CaseNum;
    while (!IdxStack.empty())
    {
        cnt = 0, index = IdxStack.top() + 5; 
        while ((index = NewStr.find("case", index)) < len && (index != -1))
        {
            cnt++;
            index++;
        }
        len = IdxStack.top();
        IdxStack.pop();
        CaseNum.push_back(cnt);  
    }
    for (int i = CaseNum.size() - 1; i >= 0; i--)  
    {
        printf(" %d", CaseNum[i]);
    }
    putchar('\n');
    return NewStr;
}

count if-else

void Count_IfEls_Num(const string& str, int level) {
    string NewStr = Count_SwiCase_Num(str);
    string wd;
    stack<string> IfStack;
    int len = NewStr.length();
    if (isalpha(NewStr[0]))
    {
        wd += NewStr[0];
    }
    for (int i = 1; i < len; i++)
    {
        if (isalpha(NewStr[i]))
        {
            wd += NewStr[i];
        }
        else if (isalpha(NewStr[i - 1]) && !isalpha(NewStr[i]))
        {
            // 遇到 if elseif 入栈,遇到 else 出栈并根据情况计数
            if (wd == "if" || wd == "elseif")
            {
                IfStack.push(wd);
            }
            else if (wd == "else")
            {
                if (IfStack.top() == "elseif")
                {
                    ElsIfNum++;
                    while (IfStack.top() == "elseif")
                    {
                        IfStack.pop();
                    }
                }
                else
                {
                    IfElsNum++;
                }
                IfStack.pop();
            }
            wd = "";
        }
    }
    cout << "if-else num: " << IfElsNum << endl;
    if (level == 4)
    {
        cout << "if-elseif-else num: " << ElsIfNum << endl;
    }
    return;
}

Performance optimization
在这里插入图片描述

test screenshots
在这里插入图片描述

conclusion

  • By this section experiments, I realized that the difference in plan and actual, before I started to think, for example, when writing the ifelse judgment part is more complex, it takes me most of the time, but when I actually perform, I find the most time consuming part is actually build the whole project of the overall planning process, if a project in the early stage of the plan is perfect, The follow-up work will be clearer and less time-consuming.

  • I think it’s important to refer to other people’s code, and I refer to other people’s code in my own code. In the stack processing logic, originally wanted to implement through the array, but met some logic problems have been unable to solve, after searching the results of the Internet found that this method is very easy to use

  • For the writing part of the blog, I think it looks very simple, but it is very complicated to write, took a lot of time, almost today I have been writing this. As you write, you’ll need to keep reviewing your code, and you’ll probably find new bugs. At the same time, I also need to learn new knowledge, such as how to draw a flow chart with Markdown, although this time it is not very good. I think the process of writing a blog is to re-connect the various parts of this homework, which is equal to re-warming the whole process of doing homework. To sum up, this difficulty needs enough time to be solved

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值