EE308-Lab1_2

xxxtfish xxxtfish 墨衍会员 · 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 AssignmentGitHub Using & Keywords Capturing
MU STU ID and FZU STU ID20121920_832002111
github :https://github.com/xxxtfish/xxxfish

PSP

Personal Software Process StagesESTIMATE TIME/MINUTESREAL TIME(MINUTE)
Planning4030
Estimate55
Development5055
Analysis4530
Design Spec1510
Design Review55
Coding Standard2015
Design6065
Coding200215
Code Review5045
Test2015
Reporting--
Test Report1510
Size Measurement1010
Postmortem&Process Improvement Plan2020
Total555530

Problem-solving idea
In the two years of university learning experience, although we have learned java, C and C++, personally, I am better at using C++ for programming, so my solution is to use C++ for code writing.


Design and implementation process

img


Code

Main code

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{    
    string test;
    vector <string> nums; 
    string filename;
    string KW[33] = {"auto", "break", "case", "char", "const", "continue",
        "default", "do", "double", "else", "enum", "extern", "float",
        "for", "foto", "if", "int", "long", "main", "register", "return", "short",
        "signed", "sizeof", "static", "struct", "switch", "typeof", "union",
        "unsigned", "void", "volatile", "while"};
    string ifelse_KW[3] = {"else if","if","else"};
    int KW_count = 0;    
    int switch_count = 0;
    int case_count = 0;
    int ifelse_KW_count[3] = {0};
    vector<int> casenum;
    vector<string> ifelse; 
    int ifelse_count = 0;
    int ifelseif_count = 0;
    ifstream inFile;
    cout<<"Please enter the file name: ";
    cin>>filename;
    cout<<"Please choose the level(1,2,3,4): ";
    int level;
    cin>>level;
    inFile.open(filename.c_str());
    if(inFile.fail())
    {
        cout<<"The file was not successfully open!"<<endl;
        exit(1);
    }
    string buf;

Level 1

while (getline(inFile,buf))
    {
        int i = 1, j = 1;    
        while(i < int(buf.size()) && j < int(buf.size())) 
        {
            if (isalpha(buf[i])) 
            {
                if (!isalpha(buf[j] )) 
                {
                    string s = buf.substr(i, j-i);
                    nums.push_back(s);//The vector () function adds a new element to the end of a vector, one element after the current last element
                    for (int k = 0; k < 33; k++) {
                        if (s == KW[k]) {
                            KW_count += 1;
                        }
                    }
                    i = j+1;
                    j = i;
                }
                else
                    j++;
            }
            else{
                i++;
                j = i;
            }
        }
    }
    if(level >= 1)
        cout<<"total num: "<<KW_count<<endl;

Level 2

if(level > 1)
    {
        for(int i = 0;i < int(nums.size());i++)
        {
            if(nums[i] == "switch")
            {
                switch_count += 1;
                
                for(int j = i+1;j < int(nums.size());j++)
                {
                
                    if (nums[j] == "case")
                        case_count += 1;
                    else if(nums[j] == "switch" )
                    {
                        i=j-1;
                        casenum.push_back(case_count);
                        case_count = 0;
                        break;
                    }
                    else if(j == int(nums.size()-1))
                    {
                        i = j;
                        casenum.push_back(case_count);
                        break;
                    }
                }
            }
        } 
        cout<<"switch num: "<<switch_count<<endl;
        cout<<"case num: ";
        for(int i = 0;i < int(casenum.size());i++)
        {
            cout<<casenum[i]<<"  ";
        }
        cout<<endl;
        inFile.close();
    }

Level 3 and level 4

if(level>2)
    {
        inFile.open(filename.c_str());
        if(inFile.fail())
        {
            cout<<"The file was not successfully open!";
            exit(1);
        }
        while (getline(inFile,buf))
        {
            for(int i = 0;i < 3;i++)
            {
                if(int(buf.find(ifelse_KW[i]) != -1))
                    ifelse_KW_count[i] = 1;
                else
                    ifelse_KW_count[i] = 0;
            }    
            if(ifelse_KW_count[1] == 1 && ifelse_KW_count[2] == 1)
            {
                ifelse_KW_count[0]=1;
                ifelse_KW_count[1]=0;
                ifelse_KW_count[2]=0;
            }    
            for(int i = 0;i < 3;i++)
            {
                if(ifelse_KW_count[i] == 1)
                    ifelse.push_back(ifelse_KW[i]);    
            }
        }
        for(int i=0;i<int(ifelse.size())-1;i++)
        {
            if(ifelse[i] == "if" && ifelse[i+1] == "else")
            {
                ifelse_count += 1;
            }
            if(ifelse[i] == "if" && ifelse[i+1] == "else")
            {
                ifelseif_count += 1;
            }    
        }
        if(level>2)
            cout<<"if-else num: "<<ifelse_count<<endl;
        if(level>3)
            cout<<"if-elseif-else num: "<<ifelseif_count<<endl;
    }
    return 0;
}


Output

img


Summarize
Through this experiment, I learned how to publish blog in CSDN. Although there are a lot of things that are not very thoughtful, for me, this is completely new territory, and it is a breakthrough to dare to try new areas. Secondly, I learned how to use GitHub and how to upload code to GitHub. Overall, this experiment has been very rewarding!🙂

...全文

相关推荐

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

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