EE308FZ Lab1-2

理塘丁真 2022-10-28 04:19:58

目录

  • 1.PSP form
  • 2.Description of problem-solving ideas.
  • Level 1
  • Level 2
  • Level 3and level 4
  • 3.Design and implementation process.
  • Separate the text from the code
  • Level 1
  • Level 2
  • 4.Code description.
  • Level 1
  • Level 2
  • Level 3
  • Level4
  • 5.Unit test screenshots and description.
  • 6.Unit test coverage optimization and performance testing, performance optimization screenshots and descriptions.
  • 7.Summarize

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 Assignmentdo lab1-2
The Aim of This Assignment<20124546_832001207>
github!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!https://github.com/yusdar/114514

1.PSP form

Personal Software Process StagesEstimated time (minutes)Real time (minutes)
Planning1010
Estimate4050
Development1040
Analysis1010
Design Spec1010
Design Review1010
Coding Standard1010
Design1010
Coding6090
Code Review1020
Test3060
Reporting100200
Test Report2020
Size Measurement1010
Postmortem & Process Improvement Plan1010
Total350560

2.Description of problem-solving ideas.

For the questions raised by the topic, I thought that the language to be used was c++, because this programming language was learned last semester, and it was faster to review.
For a series of requirements required by the topic, I think the first thing to do is to realize the function of reading files. After implementation, it is obvious that there will be a lot of symbols in the code. Before we identify the key words in the code, we must extract the non symbolic part of the code.

Level 1

is obvious. Compare each word extracted from the code with 32 keyword arrays and count them.

Level 2

find switches first, and then calculate the number of cases until the end of traversal or find the next switch. If found, repeat the previous steps.

Level 3and level 4

judge the nesting relationship according to the sequence of code if and else


3.Design and implementation process.

Separate the text from the code

img

Level 1

img

Level 2

img


4.Code description.

Level 1

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
 
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"
};

struct KeywordnNum{
    string name;
    int num;
};

int keywordnum=0;

int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                break;
            }
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
}

Level 2

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
 
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"
};

struct KeywordnNum{
    string name;
    int num;
};

int keywordnum=0;
vector<int> switchcase;
int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                break;
            }
        }
        if (realvocabulary[i]=="switch"){
            switchcase.push_back(0);
        }
        else if (realvocabulary[i]=="case"){
            switchcase[switchcase.size()-1]++;
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
    cout<<"switch num:"<<switchcase.size()<<endl;
    cout<<"case num:";
    for (j=0;j<switchcase.size();j++){
        cout<<switchcase[j]<<' ';
    }
    cout<<endl;
}

Level 3

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
 
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"
};

struct ifelse{
    bool iselseif =false;
    bool iselse=false;
};
int keywordnum=0;
vector<int> switchcase;
int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    vector<ifelse> fileifelse;
    ifelse a;
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
                if (filecontent.substr(i,j)=="if" && filecontent.substr(i-5,7)!="else if"){
                    fileifelse.push_back(a);
                }
                else if(filecontent.substr(i,j+3)=="else if"){
                    //cout <<realvocabulary[i]+realvocabulary[i+1]<<endl;
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselseif=true;
                            //cout<<k<<endl;
                            break;
                        }
                    }
                }
                else if(filecontent.substr(i,j)=="else"){
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselse=true;
                            break;
                        }
                    }
                }
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                
                

                break;
            }
        }
        if (realvocabulary[i]=="switch"){
            switchcase.push_back(0);
        }
        else if (realvocabulary[i]=="case"){
            switchcase[switchcase.size()-1]++;
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
    cout<<"switch num:"<<switchcase.size()<<endl;
    cout<<"case num:";
    for (j=0;j<switchcase.size();j++){
        cout<<switchcase[j]<<' ';
    }
    cout<<endl;
    cout<<"if-else num:";
    int b=0;
    for (j=0;j<fileifelse.size();j++){
        if (!fileifelse[j].iselseif){
            b++;
        }
    }
    cout<<b;
}

Level4

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
 
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"
};

struct ifelse{
    bool iselseif =false;
    bool iselse=false;
};
int keywordnum=0;
vector<int> switchcase;
int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    vector<ifelse> fileifelse;
    ifelse a;
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
                if (filecontent.substr(i,j)=="if" && filecontent.substr(i-5,7)!="else if"){
                    fileifelse.push_back(a);
                }
                else if(filecontent.substr(i,j+3)=="else if"){
                    //cout <<realvocabulary[i]+realvocabulary[i+1]<<endl;
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselseif=true;
                            //cout<<k<<endl;
                            break;
                        }
                    }
                }
                else if(filecontent.substr(i,j)=="else"){
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselse=true;
                            break;
                        }
                    }
                }
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                
                

                break;
            }
        }
        if (realvocabulary[i]=="switch"){
            switchcase.push_back(0);
        }
        else if (realvocabulary[i]=="case"){
            switchcase[switchcase.size()-1]++;
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
    cout<<"switch num:"<<switchcase.size()<<endl;
    cout<<"case num:";
    for (j=0;j<switchcase.size();j++){
        cout<<switchcase[j]<<' ';
    }
    cout<<endl;
    cout<<"if-else num:";
    int b=0;
    for (j=0;j<fileifelse.size();j++){
        if (!fileifelse[j].iselseif){
            b++;
        }
    }
    cout<<b<<endl;
    cout<<"if-elseif-else num:"<<fileifelse.size()-b;
    
}


5.Unit test screenshots and description.

img

img

img

img


6.Unit test coverage optimization and performance testing, performance optimization screenshots and descriptions.

img

img


7.Summarize

I learned a lot from this experiment. For example, I have learned a lot from the analysis and evaluation before the program, how to use csdn to write a blog, and how to iterate versions. Thank you for software engineering! Experience the four points of happiness!

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

285

社区成员

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

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