SE308_lab1_2

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

Catalogue

  • Lab1_2
  • GitHub repository
  • 1.PSP
  • 2.Description of problem-solving ideas
  • 3.Design and implementation process
  • 4.test file
  • 5.Test output
  • 6.Summary

Lab1_2

The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZU202201?category=0
The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/608734907
The Aim of This AssignmentLab1_2_solution
MU STU ID and FZU STU ID20122268 and 832001214

GitHub repository

https://github.com/xingwang133/SE308-lab1_2

1.PSP

Personal Software Process StagesEstimated time (minutes)real time (minutes)
Planning2025
Estimate55
Development150200
Analysis3030
Design Spec3030
Design Review1010
Coding Standard2520
Design3030
Coding90100
Code Review1010
Test and debug3040
Reporting5060
Size Measurement1010
Postmortem & Process Improvement Plan2025
Total510595

2.Description of problem-solving ideas

Since we used c++ in our course last semester, I am quite familiar with it now, so I decided to use c++ to complete this experiment. Solve the problem in stages by breaking it down.
1.Need to read the c file.
2.In order to meet the different Program Requirements, it is necessary to make corresponding code design for four different levels of tasks.

3.Design and implementation process

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<sstream>
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"
};
vector<int> Case_num;
int total_num = 0;
int switch_num = 0;
int case_num = 0;
int ifelse_num = 0;
int if_elseif_else_num = 0;
int stack[ 1000 ] = { 0 };
int top = -1;//Define the required variables

Define the function corresponding to the keyword

nt match( string a , string b )
{
    int correspond( char str );
    int pos = a.find( b , 0 );
    int len = b.length();    
    if( pos != string::npos )
    {
        if( pos == 0 ) 
        {
            if(correspond( a[ pos + len ] ) == 0 )
            {
                return 1;
            }
            else 
            {
                return 0;  
            }      
        }
        else
        {
            if(correspond( a[ pos + len] ) == 0 && correspond( a[ pos - 1] ) == 0 )
            {
                return 1;
            }
            else
            {
                return 0;
            }    
        }
    }
    return 0;
}
int correspond( char str )
{
    if( ( str <= 'z' && str >= 'a' ) || ( str <= 'Z' && str >= 'A' ) )
    {
        return 1;
    }
    else
    {
        return 0;    
    }    
}

Use keywords to count the text in the test file

void sort_1(string str)
{
    for(int i = 0; i < 32; i++ )
    {
        if(match( str , Keyword[i] ) == 1)
        {
            if( match( str , "switch" ) )
            {
                Case_num.push_back( case_num );
                switch_num++;
                case_num = 0;
            }
            if( match( str , "case" ))
            {
                case_num++;
            }
            total_num++;
            break;
        }
    }
}

void sort_2( string str )
{
    if( match( str , "else if" ) )
    {
        top++;
        stack[ top ] = 2;
    }    
    else
    {
        if( match( str , "else" ) )
        {
            if( stack[ top ] == 1 )
            {
                ifelse_num++;
                top--;
            }
            else
            {
                if( stack[ top ] == 2 )
                {
                    if_elseif_else_num++;
                    top--;
                }
            }
        }
        else
        {
            if(match( str ,"if" ) )
            {
                top++;
                stack[ top ] = 1;
            }
        }
    }
}

Output the count result

int main()
{
    int level;
    string file,temp;
    cout << "Enter the file path: " << endl;
    cin >> file;
    cout << "Enter the completion level: " << endl;
    cin >> level;
    ifstream File( file.c_str() );
    int correspond( string a,string b );
    int correspond( char str);
    void sort_1( string str );
    void sort_2( string str );
    while ( getline( File ,temp ))
    {
        istringstream istr ( temp );
        string str;
        if( level >= 3)
        {
            sort_2( temp );
        }
        while( istr >> str ) 
        {
            sort_1( str );
        }
    }
    if( level >= 1 )  //level1 and above
    {
        cout << "total num: " << total_num << endl;
    }
    if( level >= 2 ) //level2 and above
    {
        cout << "switch num: " << switch_num << endl;
        if( !Case_num.empty() )
        {
            Case_num.push_back(case_num);
        }
        else
        {
            Case_num.push_back(0);
        }
        cout << "case num: ";
        for ( int i = 1; i <= switch_num; i++)
        {
            cout<< Case_num[i] << " ";
        }
        cout << endl;
    }
    if( level >=3 ) //level3 and above
    {
        cout << "if_else num: " << ifelse_num << endl;
    }
    if( level >=4 )  //level4 and above
    {
        cout << "if_elseif_else num: " <<if_elseif_else_num << endl;
    }
}

4.test 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;  
}

5.Test output

img

6.Summary

  1. Learn how to use github and find solutions to problems
  2. Write a blog for the first time to explain your thoughts and strategies for solving the problem
...全文

相关推荐

EE308 Lab7 Demand Analysis and Prototype Design

Lab 7 Demand Analysis and Prototype DesignFormat DescriptionPSPIntroduction of productOther DetailsMain difficultiesWhat do you have to do for this issue?How do you solve it?What gains you have?Team collaboration recordMeeting picturesspecification / proto

调参侠鱼尾

EE308 Lab6 Team Presentation and Topic Selection Report

EE308 Lab6 Team Presentation and Topic Selection ReportFormat DescriptionTeam nameSpecific planning and description of the team projectTeam member style1. YUWEI JIANG2. YIFAN SHEN3. SHENKAI XIONG4. ZHU YIFAN5. BEICHEN ZHOUThe team's vision Format Descripti

调参侠鱼尾

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

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

BIZKEEN

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

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

BIZKEEN

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

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

licy__
评论
收藏 已收藏
分享
返回顶部