EE308FZ Lab1-2

理塘丁真 2022-10-28 04:19:58

目录

  • 1.PSP form
  • 2.Description of problem-solving ideas.
  • Level 1
  • Level 2
  • Level 3and level 4
  • 3.Design and implementation process.
  • Separate the text from the code
  • Level 1
  • Level 2
  • 4.Code description.
  • Level 1
  • Level 2
  • Level 3
  • Level4
  • 5.Unit test screenshots and description.
  • 6.Unit test coverage optimization and performance testing, performance optimization screenshots and descriptions.
  • 7.Summarize

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 Assignmentdo lab1-2
The Aim of This Assignment<20124546_832001207>
github!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!https://github.com/yusdar/114514

1.PSP form

Personal Software Process StagesEstimated time (minutes)Real time (minutes)
Planning1010
Estimate4050
Development1040
Analysis1010
Design Spec1010
Design Review1010
Coding Standard1010
Design1010
Coding6090
Code Review1020
Test3060
Reporting100200
Test Report2020
Size Measurement1010
Postmortem & Process Improvement Plan1010
Total350560

2.Description of problem-solving ideas.

For the questions raised by the topic, I thought that the language to be used was c++, because this programming language was learned last semester, and it was faster to review.
For a series of requirements required by the topic, I think the first thing to do is to realize the function of reading files. After implementation, it is obvious that there will be a lot of symbols in the code. Before we identify the key words in the code, we must extract the non symbolic part of the code.

Level 1

is obvious. Compare each word extracted from the code with 32 keyword arrays and count them.

Level 2

find switches first, and then calculate the number of cases until the end of traversal or find the next switch. If found, repeat the previous steps.

Level 3and level 4

judge the nesting relationship according to the sequence of code if and else


3.Design and implementation process.

Separate the text from the code

img

Level 1

img

Level 2

img


4.Code description.

Level 1

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
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"
};

struct KeywordnNum{
    string name;
    int num;
};

int keywordnum=0;

int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                break;
            }
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
}

Level 2

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
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"
};

struct KeywordnNum{
    string name;
    int num;
};

int keywordnum=0;
vector<int> switchcase;
int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                break;
            }
        }
        if (realvocabulary[i]=="switch"){
            switchcase.push_back(0);
        }
        else if (realvocabulary[i]=="case"){
            switchcase[switchcase.size()-1]++;
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
    cout<<"switch num:"<<switchcase.size()<<endl;
    cout<<"case num:";
    for (j=0;j<switchcase.size();j++){
        cout<<switchcase[j]<<' ';
    }
    cout<<endl;
}

Level 3

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
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"
};

struct ifelse{
    bool iselseif =false;
    bool iselse=false;
};
int keywordnum=0;
vector<int> switchcase;
int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    vector<ifelse> fileifelse;
    ifelse a;
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
                if (filecontent.substr(i,j)=="if" && filecontent.substr(i-5,7)!="else if"){
                    fileifelse.push_back(a);
                }
                else if(filecontent.substr(i,j+3)=="else if"){
                    //cout <<realvocabulary[i]+realvocabulary[i+1]<<endl;
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselseif=true;
                            //cout<<k<<endl;
                            break;
                        }
                    }
                }
                else if(filecontent.substr(i,j)=="else"){
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselse=true;
                            break;
                        }
                    }
                }
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                
                

                break;
            }
        }
        if (realvocabulary[i]=="switch"){
            switchcase.push_back(0);
        }
        else if (realvocabulary[i]=="case"){
            switchcase[switchcase.size()-1]++;
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
    cout<<"switch num:"<<switchcase.size()<<endl;
    cout<<"case num:";
    for (j=0;j<switchcase.size();j++){
        cout<<switchcase[j]<<' ';
    }
    cout<<endl;
    cout<<"if-else num:";
    int b=0;
    for (j=0;j<fileifelse.size();j++){
        if (!fileifelse[j].iselseif){
            b++;
        }
    }
    cout<<b;
}

Level4

#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
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"
};

struct ifelse{
    bool iselseif =false;
    bool iselse=false;
};
int keywordnum=0;
vector<int> switchcase;
int main(){
    string fileaddress;
    string filecontent;
    string testcontent;
    vector<string> realvocabulary;
    vector<ifelse> fileifelse;
    ifelse a;
    cout <<"Enter file address:";
    cin >>fileaddress;
    ifstream file;
    file.open(fileaddress);
    while(getline(file,testcontent)){
        filecontent+=testcontent;
        
        
    }
    int j=0;
    //cout <<filecontent;
    for (int i=0;i<filecontent.length();i++){
        j=0;
        while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
            //cout<<filecontent[i+j]<<endl;    
            j++;
        }
        if (j!=0){
            realvocabulary.push_back(filecontent.substr(i,j));
                if (filecontent.substr(i,j)=="if" && filecontent.substr(i-5,7)!="else if"){
                    fileifelse.push_back(a);
                }
                else if(filecontent.substr(i,j+3)=="else if"){
                    //cout <<realvocabulary[i]+realvocabulary[i+1]<<endl;
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselseif=true;
                            //cout<<k<<endl;
                            break;
                        }
                    }
                }
                else if(filecontent.substr(i,j)=="else"){
                    for (int k=fileifelse.size()-1;k>=0;k--){
                        if (!fileifelse[k].iselse){
                            fileifelse[k].iselse=true;
                            break;
                        }
                    }
                }
            //cout<<filecontent.substr(i,j)<<endl;
            i+=j;
        }
    }
    for (int i=0;i<realvocabulary.size();i++) {
        for (j=0;j<32;j++){
            if (realvocabulary[i]==Keyword[j]){
                keywordnum++;
                
                

                break;
            }
        }
        if (realvocabulary[i]=="switch"){
            switchcase.push_back(0);
        }
        else if (realvocabulary[i]=="case"){
            switchcase[switchcase.size()-1]++;
        }    
    }
    cout<<"total num:"<<keywordnum<<endl;
    cout<<"switch num:"<<switchcase.size()<<endl;
    cout<<"case num:";
    for (j=0;j<switchcase.size();j++){
        cout<<switchcase[j]<<' ';
    }
    cout<<endl;
    cout<<"if-else num:";
    int b=0;
    for (j=0;j<fileifelse.size();j++){
        if (!fileifelse[j].iselseif){
            b++;
        }
    }
    cout<<b<<endl;
    cout<<"if-elseif-else num:"<<fileifelse.size()-b;
    
}


5.Unit test screenshots and description.

img

img

img

img


6.Unit test coverage optimization and performance testing, performance optimization screenshots and descriptions.

img

img


7.Summarize

I learned a lot from this experiment. For example, I have learned a lot from the analysis and evaluation before the program, how to use csdn to write a blog, and how to iterate versions. Thank you for software engineering! Experience the four points of happiness!

...全文
375 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
内容概要:本文围绕“基于超局部模型与自抗扰ESO观测器的无模型预测电流控制改进策略”展开研究,提出一种结合超局部模型(ULM)与扩张状态观测器(ESO)的无模型预测电流控制(MFPCC)改进方法,旨在提升永磁同步电机(PMSM)电流环的动态响应性能与抗干扰能力。该策略利用超局部模型对系统行为进行局部逼近,避免依赖精确数学模型,同时引入自抗扰控制中的ESO实时观测并补偿系统内外部扰动,有效抑制参数摄动、负载变化及模型不确定性带来的影响。研究通过Simulink搭建完整的控制系统仿真模型,对传统MFPCC与所提改进策略进行对比分析,验证了新方法在电流跟踪精度、响应速度和鲁棒性方面的优越性。; 适合人群:具备电机控制、现代控制理论及Simulink仿真基础的电气工程、自动化及相关专业的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于高性能电机驱动系统中电流环控制器的设计与优化;②为无模型控制与自抗扰控制的融合应用提供技术参考;③支撑相关课题的仿真验证、论文复现与创新方法研究。; 阅读建议:建议读者结合Simulink仿真模型深入理解控制结构与参数整定过程,重点关注ESO的观测性能与扰动补偿机制,并可通过改变负载条件、参数偏差等工况进行鲁棒性测试,进一步掌握该改进策略的核心优势与适用边界。
内容概要:本文围绕Scratch图形化编程平台,详细阐述了《人体感应灯光系统》这一贴近生活的AI科创作品的设计与教学应用。通过模拟真实智能家居中人体感应灯的工作原理,利用Scratch的侦测、逻辑判断、亮度特效调节等功能,实现了人物靠近自动亮灯、延时熄灭及环境亮度自适应等仿真功能。文章系统拆解了从场景搭建、核心逻辑设计、分层编程实现到调试优化的完整开发流程,并提供了基础版与进阶版可直接导入的源码,支持零基础快速上手与高阶创新拓展。同时构建了“基础—进阶—高阶”三层阶梯式教学体系,适配常规课堂、创客社团与赛事培优等多元教学场景,推动中小学AI教育的生活化、实践化与创新化发展。 适合人群:小学高年级至初中阶段学生,信息技术教师,创客教育从业者,以及参与青少年科创赛事的师生。 使用场景及目标:①作为中小学人工智能通识课程的教学案例,帮助学生理解智能感应与控制逻辑;②用于校内创客社团开展项目式学习;③支撑学生参加AI科创类赛事,完成高质量作品创作与答辩准备;④布置为课后综合实践作业,提升动手能力与科技素养。 阅读建议:建议结合提供的Scratch源码进行实践操作,在复现基础上尝试参数调优与功能扩展,如增加音效提示、多区域感应等,深化对编程逻辑与智能系统设计的理解。

285

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程(2022秋) 教学
软件工程 高校
社区管理员
  • LinQF39
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧