EE308_Lab1-2

Gen_power 2022-10-28 01:37:48

目录

  • Links
  • Github link
  • 1. PSP form
  • 2. Problem-solving ideas
  • 3. Code description
  • testcode.cpp
  • Keywords
  • Count
  • Output
  • 4. Summary

Links

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 AssignmentTo achieve a program function, it can extract keywords of different levels from the C or C++ code files that are read in.
MU STU ID and FZU STU ID20123116_832001212

Github link

1. PSP form

Personal Software Process StagesEstimated time/minutesCompleted Time/minutes
Planning3040
Estimate1530
Development3030
Analysis90120
Design Spec1020
Design Review2020
Coding Standard3035
Design5090
Coding120180
Code Review1015
Test2020
Postmortem & Process Improvement Plan3060
Total455660

2. Problem-solving ideas

img

3. Code description

testcode.cpp

#include <iostream>  
using namespace std;
int main() {  
    int i = 1;  
    double j = 0;  
    long f;  
    switch(i) {  
        case 0:  
        break;  
        case 1:  
        break;  
        case 2:  
        break;  
        default:  
        break;  
    }  
    switch(i) {  
        case 0:  
        break;  
        case 1:  
        break;  
        default:  
        break;  
    }  
    if (i < 0) {  
        if (i < -1) {}  
        else {}  
    }  
    else if (i > 0) {  
        if (i > 2){}  
        else if (i == 2) {}  
        else if (i > 1) {}  
        else {}  
    }  
    else {  
        if (j != 0) {}  
        else{}  
    }  
    return 0;  
}

Keywords

string Keyword[32]=
{
    "auto", "break", "case", "char", "const", "continue", "default", "double", 
    "do", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", 
    "register", "return", "short", "signed", "sizeof", "static", "struct", 
    "switch", "typedef", "union", "unsigned", "void", "volatile", "while"
};

Count

for (int i = 0; i < 32; i++ ) {
        if (match(str, Keyword[i]) == 1) {
            total_num++;
            break;
        }
    }
    for (int i = 0; i < 32; i++ ) {
        if (match(str, Keyword[i]) == 1){
            if (match(str, "switch") ) {
                Case_num.push_back(case_num);
                switch_num++;
                case_num = 0;
            }
            if (match(str, "case")){
                case_num++;
            }
            break;
        }
    }
if (match(str, "else if" )){
        top++;
        stack[top] = 2;
    }    
    else {
        if (match(str, "else")) {
            if (stack[top] == 1 ) {
                if_else_num++;
                top--;
            }
            else {
                if (stack[top] == 2 ) {
                    if_elseif_else_num++;
                    top--;
                }
            }
        }
        else {
            if (match(str, "if")) {
                top++;
                stack[top] = 1;
            }
        }
    }

Output

img

4. Summary

I think this task is difficult. The time I finish the report is beyond the estimated time but I have learnt a lot, such as C++ programing and github.

...全文
240 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

285

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程(2022秋) 教学
软件工程 高校
社区管理员
  • LinQF39
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧