EE308Lab 1_2

ClutchMaster ClutchMaster 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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 code files that are read in
MU STU ID and FZU STU IDFZU:832002201 MU:20123825

· GitHub Repository

https://github.com/ClutchMasterzzz/Software-engineering/tree/main

· PSP form

Personal Software Process StagesTime (min)
Planning10
Analysis (including learning new knowledge)10
Development30
Test5
Postmortem & Process Improvement Plan20

·Description of problem-solving ideas

1.The first thing I need to think about is how do I read the c file into the program.
2.The requirements are divided into 4 levels, input the corresponding level can execute the corresponding code.
3.The third is to match the key words I'm looking for from the string I read and count them.

· Design and implementation process

img

· Code description

main method

int main() {
    //"C:\\Users\\Mr.SupX\\Desktop\\Software Engineering\\test.cpp"
    string address;
    cout << "Please input the file address" << endl;
    cin >> address;
    cin.clear(); //flush the flag
    cin.sync(); //clear the buffer
    int level;
    cout << "Please input the level you need" << endl;
    scanf("%d",&level);
    string str = readFileIntoString(address);
    vector<string> ans = dealWithString(str);
    // if - else & if -elseif -else
    vector<int> answer = find_if_else(ans);
    // switch-case
    vector<int> answer_switch = findSwitch(ans);
    //
    smatch result;
    regex pattern("void|signed|unsigned|short|long|int|float|double|char|enum|struct|union|typedef|Bool|Imaginary|Complex|const|volatile|restrict|inline|auto|static|extern|register|sizeof|goto|return|break|continue|if|else|switch|case|default|do\\s|while|for");
    string::const_iterator iterStart = str.begin();
    string::const_iterator iterEnd = str.end();
    string temp;
    int count = 0;
    while (regex_search(iterStart, iterEnd, result, pattern))
    {
        count ++;
        iterStart = result[0].second;
    }
    if(level == 1){
        cout << "total num: " << count << endl;
    }else if(level == 2){
        cout << "total num: " << count << endl;
        cout << "switch num: " << answer_switch.size() << endl;
        cout << "case num: ";
        for(int i=0;i<answer_switch.size();i++){
            cout << answer_switch[i] << " ";
        }cout << endl;
    }else if(level == 3){
        cout << "total num: " << count << endl;
        cout << "switch num: " << answer_switch.size() << endl;
        cout << "case num: ";
        for(int i=0;i<answer_switch.size();i++){
            cout << answer_switch[i] << " ";
        }cout << endl;
        cout << "if-else num: " << answer[0] << endl;
    }else if(level == 4){
        cout << "total num: " << count << endl;
        cout << "switch num: " << answer_switch.size() << endl;
        cout << "case num: ";
        for(int i=0;i<answer_switch.size();i++){
            cout << answer_switch[i] << " ";
        }cout << endl;
        cout << "if-else num: " << answer[0] << endl;
        cout << "if-elseif-else num:" << answer[1] << endl;
    }else{
        cout << "wrong level" << endl;
    }
    return 0;
}

Read_File

string readFileIntoString(string filename) {
    ifstream ifile(filename);
    ostringstream buf;
    char ch;
    while (buf && ifile.get(ch))
        buf.put(ch);
//返回与流对象buf关联的字符串
    ifile.close();
    return buf.str();
}

Find_switch

vector<int> findSwitch(vector<string> v1){
    vector<int> answer;
    stack<char> myStack;
    bool judge = false;
    int count = 0;
    for(int i=0;i<v1.size();i++){
        string strS = v1[i];
        if(strS.find("switch") != strS.npos){
            judge = true;
        }
        if(judge){
            if(strS.find('{') != strS.npos){
                myStack.push('{');
            }else if(strS.find('}') != strS.npos){
                myStack.pop();
            }
        }
        if(myStack.empty() != true){
            if(strS.find("case") != strS.npos){
                count ++;
            }
        }else{
            judge = false;
            if(count != 0){
                answer.push_back(count);
                count = 0;
            }
        }
    }
    return answer;
}

Find_if-else and if-elseif-else

vector<int> find_if_else(vector<string> v){
    stack<bool> mystack;
    vector<int> answer;
    int v1 = 0,v2 = 0;
    int size = 0;
    for(int i=0;i<v.size();i++){
        string strS = v[i];
        if(strS.find("else if") == strS.npos && strS.find("if") != strS.npos){
            mystack.push(false);
            size ++;
            continue;
        }else if(strS.find("else if") != strS.npos && mystack.empty() != true){
            mystack.top() = true;
            continue;
        }else if(strS.find("else if") == strS.npos && strS.find("else") != strS.npos){
            if(mystack.top() == true){
                v2 ++;
            }else{
                v1 ++;
            }
            mystack.pop();
            continue;
        }
    }
    answer.push_back(v1);
    answer.push_back(v2);
    return answer;
}
string readFileIntoString(string filename) {
    ifstream ifile(filename);
    ostringstream buf;
    char ch;
    while (buf && ifile.get(ch))
        buf.put(ch);
//返回与流对象buf关联的字符串
    ifile.close();
    return buf.str();
}

Count all Keywords

smatch result;
    regex pattern("void|signed|unsigned|short|long|int|float|double|char|enum|struct|union|typedef|Bool|Imaginary|Complex|const|volatile|restrict|inline|auto|static|extern|register|sizeof|goto|return|break|continue|if|else|switch|case|default|do\\s|while|for");
    string::const_iterator iterStart = str.begin();
    string::const_iterator iterEnd = str.end();
    string temp;
    int count = 0;
    while (regex_search(iterStart, iterEnd, result, pattern))
    {
        count ++;
        iterStart = result[0].second;
    }

· Unit test

img

·Summary

In this lab, I develop a c++ project and tried to advance it, I found it isreally important to have a plan and analysis before to do it. What's more I also tried to grasp the knowledge of markdown and how to upload project to github.

...全文

相关推荐

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 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

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