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

这是本次实验的压缩包

晨起剪桃花

弱电网下光伏并网逆变器序阻抗建模仿真复现扫频法【序阻抗判断稳定性】

内容概要:本文聚焦于弱电网条件下光伏并网逆变器的序阻抗建模与稳定性分析,系统阐述了基于扫频法的阻抗特性仿真与复现方法。通过构建正负序阻抗模型,深入剖析逆变器在弱电网环境中的动态响应特性,结合锁相环、电流环等关键控制环节对系统阻抗的影响机制,采用序阻抗稳定性判据评估多机并网或复杂电网条件下的系统稳定裕度。研究在Simulink平台中实现激励信号注入、频率响应采集与阻抗曲线绘制,为高比例新能源接入背景下并网系统的稳定性分析提供了可靠的仿真手段与理论支撑,尤其适用于SCI级别论文成果的复现与拓展验证。; 适合人群:电力电子、新能源并网技术及相关领域的硕士/博士研究生、科研人员,以及从事光伏逆变器、微电网稳定控制开发的工程技术人员。; 使用场景及目标:①掌握扫频法在电力电子装置阻抗建模中的具体实施流程;②理解并应用基于序阻抗的稳定性判据进行系统稳定边界分析;③用于高水平学术论文(如SCI期刊)中阻抗建模与稳定性分析部分的仿真复现与方法验证; 阅读建议:建议读者结合文中所述方法与提供的参考文献,自主搭建Simulink仿真模型,逐步完成扰动信号设计、数据采集、傅里叶分析及阻抗拟合全过程,深入探究控制参数变化对系统阻抗特性和稳定性的具体影响,强化理论与实践的融合能力。

欢多天天写代码

三相并网逆变器虚拟阻抗+统一有源阻尼策略SVPWM+SPWM调制仿真

内容概要:本文档系统性地介绍了三相并网逆变器的核心控制技术及其在复杂电网环境下的仿真应用,重点涵盖虚拟阻抗与统一有源阻尼策略在SVPWM和SPWM调制方式下的实现方法,旨在提升逆变器的稳定性与电能质量。内容包括无功功率扰动孤岛检测、中点电位平衡控制、低电压穿越(LVRT)、模型预测控制(MPC)、正负序分离、电网前馈控制等关键技术,并扩展至风储联合调频、微电网下垂控制、虚拟同步发电机(VSG)、构网型逆变器等多种典型电力系统应用场景。所有技术均配有基于Simulink/Matlab平台的完整仿真模型、参考文献及说明文档,强调理论分析与仿真实践的深度融合,突出科研中“借力”与创新思维的重要性。; 适合人群:电气工程、自动化、新能源等相关专业的研究生、科研人员及从事电力电子与可再生能源系统开发的工程师;具备MATLAB/Simulink仿真基础和电力系统专业知识的技术人员。; 使用场景及目标:①开展三相并网逆变器控制策略的研究与优化设计;②复现高水平学术论文中的控制算法;③完成毕业课题、科研项目或工程仿真验证;④掌握虚拟阻抗、有源阻尼、SVPWM/SPWM调制、MPC、VSG等核心技术的建模与实现方法;⑤支撑微电网、构网型变流器等前沿方向的科研攻关。; 阅读建议:建议按照资源目录结构化学习,优先选择与自身研究方向契合的内容模块,结合提供的仿真模型、参考文献和说明材料进行实操演练,注重从理论推导到仿真实现的全过程理解,充分利用共享网盘资源深化技术掌握,提升科研效率与创新能力。

欢多天天写代码

chromedriver-win32-159.0.8133.0(Canary).zip

chromedriver-win32-159.0.8133.0(Canary).zip

LCG元

计算机“101计划”《人工智能引论》教学大纲+课件+实训案例

计算机“101计划”《人工智能引论》教学大纲+课件+实训案例

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