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

调参侠鱼尾

chrome-headless-shell-win32-159.0.8132.0(Canary).zip

chrome-headless-shell-win32-159.0.8132.0(Canary).zip

LCG元

惠普150 联想1821 1831 1831W定影清零,转印带清零

惠普150 联想1821 1831 1831W定影清零,转印带清零,报错不打印,通过清零软件可以清除。内附使用说明。

weixin_45614853

【电液伺服执行器与PI控制器】带有PI控制器的电液伺服执行器的模拟研究(Simulink仿真实现)

内容概要:本文围绕带有PI控制器的电液伺服执行器开展模拟研究,利用Simulink工具构建系统仿真模型,深入分析PI控制器在电液伺服系统中的控制性能与动态响应特性。研究内容涵盖系统建模、PI控制参数整定、仿真结果分析等关键环节,重点探讨PI控制器对系统稳定性、响应速度及抗干扰能力的优化作用,并通过仿真验证控制策略的有效性与实用性; 适合人群:具备自动控制原理、液压传动基础知识及Simulink仿真能力的自动化、机械电子、控制工程等相关专业的高校学生、研究生及工程技术人员; 使用场景及目标:①用于自动控制类课程的教学实验或课程设计,帮助学生深入理解电液伺服系统的工作原理与典型控制方法;②应用于工业高精度执行机构的控制器设计,为实际工程中的系统优化提供理论支撑与仿真验证手段; 阅读建议:文中提供的Simulink模型与仿真流程具备良好的可复现性,建议读者结合具体工况调整PI参数,进一步探究PID或其他先进控制算法的改进效果,以深化对控制系统设计的理解与应用能力。

三伯
评论
收藏 已收藏
分享
返回顶部