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

科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

三相电压型PWM整流器PI双闭环控制Matlab仿真

内容概要:本文档系统介绍了三相电压型PWM整流器的PI双闭环控制技术及其在Matlab/Simulink环境下的仿真建模方法,重点阐述了电流内环与电压外环的协同控制机制,旨在实现高功率因数、低电流谐波畸变及稳定的直流母线电压输出。内容涵盖多种典型电力电子变换器的建模与控制策略,包括三相维也纳(Vienna)整流器、双有源桥(DAB)变换器、LLC谐振变换器等,并深入探讨SVPWM调制、滞环电流控制、中点电位平衡、软开关技术、畸变抑制等关键技术。文档提供丰富的仿真模型、Mathcad计算书及参考文献,支持从基础控制结构到高级优化算法(如基于KKT条件的协同最小应力控制)的多层次研究与复现。; 适合人群:电气工程、自动化、电力电子与电力传动等相关专业的高校本科生、研究生,以及从事新能源发电、电动汽车、轨道交通等领域电能变换系统研发的科研人员与工程技术人员;要求具备Matlab/Simulink仿真基础及电力电子、自动控制理论的相关知识背景。; 使用场景及目标:①作为高校课程设计与实验教学的辅助材料,帮助学生掌握PWM整流器双闭环控制系统的设计流程与仿真方法;②支撑科研项目中对高性能整流器控制策略的验证、优化与EI级论文复现;③为工业界在新能源并网、车载充电机、直流配电系统等应用场景中的控制器开发提供仿真依据与参数设计工具;④结合Mathcad计算书实现不同功率等级与电压等级系统的自主建模与参数匹配。; 阅读建议:建议读者按照资源目录顺序循序渐进地学习,先掌握PI双闭环控制的基本架构与仿真调试方法,再逐步拓展至中点平衡控制、电网不平衡工况下的功率调节、软开关优化等高级主题;重点关注“顶级EI复现”案例以提升学术研究深度;推荐结合提供的仿真模型、计算书与参考文献进行对照分析与代码调试,强化理论与实践的融合能力。

抬头望远方

TPM2-Startup-学习手册.docx

内容概要:本文深入解析了TPM 2.0中首个必要命令TPM2_Startup的工作机制,涵盖其在芯片初始化中的核心作用、启动类型决策逻辑、内部九个初始化阶段的详细流程,以及DRTM/H-CRTM安全机制的实现原理。文档结合源码(ibmswtpm2-tpm2)与实测报文,系统阐述了Startup如何通过状态校验、locality控制、PCR管理、密码学初始化、DA防护、ACT定时器、NV索引处理等环节,确保TPM在安全可信的状态下启动,并重点剖析了commitNonce重置、DA计时器跨重启续接、ACT减半防攻击等关键安全设计。; 适合人群:对TPM安全芯片感兴趣的零基础或初级开发者,以及从事可信计算、固件安全、系统启动安全相关工作的研发人员。; 使用场景及目标:①理解TPM为何必须以Startup作为第一条命令及其安全意义;②掌握SU_CLEAR、SU_STATE、SU_RESUME、SU_RESTART、SU_RESET等启动类型的决策逻辑与状态迁移;③深入学习DRTM与H-CRTM机制,理解动态信任根的建立过程;④分析DA防护、ACT定时器、有序NV索引等子系统的初始化行为与安全考量;⑤通过实验复现各类启动场景,提升对TPM底层机制的实战理解。; 阅读建议:建议结合文档提供的源码注释、实测报文和动手实验逐步验证,重点关注Startup与Shutdown的配对关系、状态持久化机制(NV)以及各类标志位(如g_DrtmPreStartup、g_StartupLocality3)的作用,注意区分规范定义与具体实现间的差异,并利用附录常量与术语表辅助理解。

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