EE308 Lab1-2

weixin_54657016 weixin_54657016 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

目录

  • 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 🙂.

...全文

相关推荐

EE-308 LAB4 final version.7z

这是本次实验的压缩包

晨起剪桃花

早期颠覆性技术商业化加速:政府主导体系搭建步骤与路径.docx

早期颠覆性技术商业化加速:政府主导体系搭建步骤与路径

BIZKEEN

科技服务机构促成校企合作时,需遵循哪些规范化操作流程?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

美国5435家医院CMS星级质量评级数据集

本数据集基于美国CMS官办的医院质量比较数据库整理加工,覆盖美国56个州和地区的5435家医院,每条记录包含53个字段。数据以医院名录为基础,融合质量评级与衍生分析字段:既有医院名称、地址、所在县州、邮编、电话等基础信息,也包含医院类型、所有制类型、是否提供急诊服务等分类属性,核心是官方发布的总体星级评级与死亡相关指标表现统计(更好、无差异、更差三类计数及脚注),并额外提供所有制分组、急症护理与产科友好标识、评级分档、指标覆盖率、更好更差比率、净指标得分、高评级标记以及各院在本州医院中的占比等衍生字段。其中3166家医院拥有总体评级,4501家提供急诊服务。适用人群:医疗政策研究者、卫生统计分析师、医疗质量管理人员、公共卫生专业师生以及数据科学爱好者。使用场景:适合开展医院质量与所有制关系研究、各州医疗资源与评级分布对比、急诊服务覆盖缺口分析、评级影响因素建模与预测、医院地理分布与可达性研究等课题。其他说明:文件为CSV格式,附带数据字典与说明文档,字段规整、注释完备,可直接导入Python、R、Excel、PowerBI等工具使用,适合课程作业、毕业设计与商业演示,也可作为医疗领域数据仓库建模的入门样例。

licy__

战国BC401年世界历史地图矢量文件SHP格式.zip

本资源为《战国BC401年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.26 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

白水先森
评论
收藏 已收藏
分享
返回顶部