EE308 Lab1-2

weixin_54657016 2022-10-28 01:36:06

目录

  • CATALOGUE
  • Link of Github
  • 1.PSP form for work
  • 2.Description of problem solving ideas
  • 3.Design and implementation process
  • 4.Code description
  • 5.Unit test screenshots and description
  • 6.Unit test coverage optimization and performance testing
  • 7.Summary
(EE308 Lab1-2)
Self introduction of HUANG LEI

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 of different levels from the C or C++ code files that are read in
MU STU ID and FZU STU ID20122586_832001315

CATALOGUE

🛑 Link to my Github code website

1.PSP form for work

Personal Software Process StagesEstimated Time Consumption (mins)Completed Time(mins)
Planning----
Estimate2015
Development----
Analysis90100
Design Specification5050
Design Review2520
Coding Standard2025
Design8090
Coding12001250
Code Review4045
Test10090
Reporting----
Test Report9080
Size Measurement2020
Postmortem & Process Improvement Plan6055
Total17951840

2.Description of problem solving ideas

💻 Programming Language :C++, (Java, Python
Although I can choose from C++, Java, Python three programming languages, I finally choose C++. C++ has the advantages of rich function, strong expression ability, flexibility and convenience, and wide application 👍. I systematically learned object-oriented programming based on C++, so I used C++ for this experiment.

3.Design and implementation process

🚀 Design four levels to realize the requirement function.
🎲 Create the main function to read the path of a specific C file and the desired level to extract keywords.

code chart

4.Code description

💎 We should first know the 32 keywords.

keywords


①Input function ⌨:

#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<sstream>
#include<stack>
using namespace std;
string keywords[32]={"auto","double","int","struct","break","else","long","switch",
                     "case","enum","register","typedef","char","extern","return","union", 
                     "const","float","short","unsigned","continue","for","signed","void",
                      "default","goto","sizeof","volatile","do","if","while","static"
                    }; 
int peak =-1;    
int container[600]={0};                
int Total_Num=0;
int Switch_Num=0;
int Case_Num=0;
int if_else_Num=0;
int if_elseif_else_Num=0;
vector<int> Case; //Creates a one-dimensional vector with no specified length

②The main function 🪁:

int main() 
{    
    string C_file;
    string interim;
    int Level_Num;
    cout << "Print the path of C/C++ file: " << endl;
    cin >> C_file;
    cout << "Print the level of extract keywords: " << endl;                    
    cout << "Level1: total keywords" << endl;
    cout << "Level2: switch case and case" << endl;
    cout << "Level3: if else" << endl;
    cout << "Level4: if, else if, else" << endl;
    cin >> Level_Num;
    ifstream readfile(C_file.c_str()); //read in the C/C++ file
    void First_Level(string cha);
    void Second_Level(string cha);
    int assess_fun1(string A, string B);
    int assess_fun2(char cha);
    
    while(getline(readfile,interim)){
        istringstream strl (interim);
        string z;
        if(Level_Num >=3){
            Second_Level(interim);    
        }
        while (strl >>z){
            First_Level(z);
        }
    }
    
    if(Level_Num >=1){
        cout << "total num: " << Total_Num << endl;
    }
    if(Level_Num >=2){
        cout << "switch num: " << Switch_Num << endl;
        if(Case.empty()){
            Case.push_back(0);
        }
        else{
            Case.push_back(Case_Num);
        } 
        cout << "case num: ";
        for(int x =1; x<=Switch_Num; x++){ 
            cout << Case[x] << " "; 
        }
        cout << endl;
    }
    if(Level_Num >=3){
        cout << "if-else num: " << if_else_Num << endl;    
    }
    if(Level_Num >=4){
        cout << "if-elseif-else num: " << if_elseif_else_Num << endl;
    } 
}

③The function to find the number of keywords 🔍:

int assess_fun1(string A, string B){
    int pos = A.find(B,0);
    int Len = B.length();
    int assess_fun2(char cha);
    if(pos != string::npos){
        if(pos == 0){
            if(assess_fun2(A[pos+Len]) == 0 && assess_fun2(A[pos-1]) == 0){
                return 1;
            }
            else{
                return 0;
            }
        }    
        else{    
            if(assess_fun2(A[pos+Len]) == 0){
                return 1;
            }
            else{
                return 0;        
            }        
        }
    }
    return 0;
} 
    
int assess_fun2(char cha){  
    if((cha >='A' && cha <='Z') || (cha >='a' && cha <='z')){ 
        return 1;
    }
    else{
        return 0;
    }
}

④The function to calculate the number of keywords depend on different level 💡:

void First_Level(string cha){ //stand for the first two level 1 and 2;
    for (int i =0; i<32; i++){
        if(assess_fun1(cha,keywords[i])==1){
            if(assess_fun1(cha,"switch")){
                Case.push_back(Case_Num);
                Switch_Num++;
                Case_Num = 0;
            }
            if(assess_fun1(cha,"case")){
                Case_Num++;
            }
            Total_Num++;
            break;            
        }
    }
}

void Second_Level(string cha){ //stand for the second two level 3 and 4;
    if(assess_fun1(cha,"else if")){
        peak++;
        container[peak] =2;    
    }
    
    else{
        if(assess_fun1(cha,"else")){
            if(container[peak]==1){
                if_else_Num++;
                peak--;
            }
            else{
                if(container[peak]==2){
                    if_elseif_else_Num++;
                    peak--;
                }
            }
        }
        else{
            if(assess_fun1(cha,"if")){
                peak++;
                container[peak]=1;
            }
        }
    }
}

5.Unit test screenshots and description

🤩The test C file:

#include <stdio.h> 
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; 
} 

Level1 👓 :

level1

Level2 🌈 :

level2

Level3 📸 :

level3

Level4 👀 :

level4


✔ The results of the unit tests are consistent with the sample given, and the code of the program implements the required function 😃.

6.Unit test coverage optimization and performance testing

unit test1


unit test2


unit test3

7.Summary

This assignment made me more familiar with C++ and made me realize that I must pay attention to time management in the process of software development. This assignment also made me more aware of my lack of ability, so I need to strengthen my programming skills before the big task 🙂.

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

285

社区成员

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

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