EE308 Lab2

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

EE308 Lab2 Individual programing work

The Link Your Class https://bbs.csdn.net/forums/MUEE308FZ?category=0
The Link of Requirement of This Assignment https://bbs.csdn.net/topics/600798588
The Aim of This AssignmentGit/GitHub Using & Keywords Capturing
MU STU ID and FZU STU ID19105185 / 831901317

PSP

Personal Software Process StagesEstimated time(min)Time(min)
Planning3070
Estimate200700
Development--
Analysis180200
Design Spec1015
Design Review1015
Coding Standard3040
Design4060
Coding340580
Code Review60110
Test60290
Test Report6070
Postmortem & Process Improvement Plan· Design Review5060
Summary10702210

Stating with Git

Git installation tutorial https://www.cnblogs.com/ximiaomiao/p/7140456.html


Github tutorial https://www.bilibili.com/video/BV1Xx411m7kn?spm_id_from=333.999.0.0

GitHub Repository

My source code https://github.com/1615639948/Lab2/blob/main/Final.cpp

img

img

Ideas of solving the problem

  • Choice of language :The first is the problem of language selection. In our freshman year, we majored in electronic information engineering learned the language python. In our sophomore year, we learned Arduino C. in the second semester of our sophomore year, we learned C + +. Here, I first sent C language, because the C language I involved is only some simple single-chip microcomputer programming, which can not complete this task at all. However, python has been learning for too long and forgotten too much, so I can only choose C + + for programming. However in the process of writing, I obviously feel that C + + is cumbersome. In the later programming, I should learn more about python.

  • General idea flow chart

img

Text input :To be honest, I spent a lot of time on text input, because I didn't use C + + for a long time. At the beginning, I learned how to read text. At first, I was worried that I could only read .txt files instead of .cpp files, but after testing, it was found that it could be successfully implemented.

c++读取TXT文件内容 - 张成的博客 - 博客园 (cnblogs.com) https://www.cnblogs.com/nkzhangcheng/p/7722568.html

  • I first used the reading of the whole text. A txt variable of string type is created to receive the content of text, and then a vector < string > text is created to receive the elements in each txt as a quantity in the string array.

    void ReadFile(InputInformation input,vector<string> text){
        ifstream file(input.file_address);
        for (string txt; file >> txt;) {
            text.push_back(txt);
        }
        for (int i = 0; i < text.size(); ++i) {
            cout << text[i];
        }
    }
    

    This is the result of code testing:

img

  • However, I found it difficult to read the full text above after 3 and 4 questions, so I modified it to read line by line, that is, the form of the final code.

    int main()
    {
        int level;
        string filename,temp;
        cout<<"input the text address: ";
        cin>>filename;
        ifstream file(filename.c_str());
        if ( ! file)
        {
            cout << "File cannot be opened" <<endl;
        }else
        {
            while (getline(file,temp))
            {           // Input from disk file, read in line by line, processed line by line
                TakeKeywords(temp);
            }
            file.close();    // Close the file input stream
        }
    }
    

Text Processing :

  • Use the TakeKeywords function to convert the text. First, convert the string to an array of char, then process the char array, remove symbols, and concatenate adjacent letters, so that you can get a number of strings, and then compare the string with the keywords in the lexicon, you can pick out the correct string And store it in an array for questions 1 and 2.

  • In addition, vector if_elseif_else is used to store '{', '}', 'if', 'else if', 'else' during reading, which is used to solve problems 3 and 4. However, else_if is not easy to judge in the implementation process, and it will be pressed repeatedly in the process. Finally, whether else is pressed in the previous one is used to judge the condition.

    Flow chart of text conversion:

img

**This is my code implementation:**
void TakeKeywords(string s) {
    string str;
    int len = s.length();
    int symbol = 0; //Check if non-alphabetic characters are '{' or '}' and mark them
    const char* p = s.data();  //将string转化为char *[]
    for (int i = 0; i < len; ++i) {
        if (p[i] == '{')
        {
            symbol = 1;
        }
        if (p[i] == '}')
        {
            symbol = 2;
        }

        if ((p[i] >= 'a'&&p[i] <= 'z'||p[i] >= 'A'&&p[i] <= 'Z'))
        {
            str += p[i];
        }
        else
        {
            if (str == "")//No letters are encountered, but parentheses may be encountered, check, if any, press into IEE
            {
                if (symbol == 1){
                    if_elseif_else.push_back("{");
                }
                if (symbol == 2){
                    if_elseif_else.push_back("}");
                }
                symbol = 0;
                continue;
            }
            temp1[countNum] = str;
            countNum++;
            if (str == "else") //If we find an else if we find an else if we find an if after n Spaces
            {
                int j = i;
                while (p[j] == ' ' && j <= len){
                    j++;
                }
                if (p[j] == 'i' && p[j+1] == 'f'){
                    if_elseif_else.push_back("else_if");
                    i = j+2;
                    keyword_num++;
                }else{
                    if_elseif_else.push_back("else");
                }
            }
            if (str == "if"){  //I find if and I tell you if the previous one is else, if it's not, I push if in
                if(if_elseif_else.back() != "else"){
                    if_elseif_else.push_back("if");
                }
            }
            if (symbol == 1){
                if_elseif_else.push_back("{");
            }
            if (symbol == 2){
                if_elseif_else.push_back("}");
            }
            symbol = 0;
            str = "";
            continue;
        }
    }
}

The completion function of task 1 and 2:

The TakeKeywords() function completes all the preparations for the completion of subsequent tasks. I think task one or two is relatively simple in difficulty, but task three or four is more difficult.

Calculate12(). Get the required results through the use of arrays:

void Calculate12(string a[]){
    int i,j;
    for(i = 0;i < countNum;i++)
    {
        for(j = 0;j < 32;j++)//Decide if the word is the desired keyword
        {
            if(a[i] == key_word[j])
            {
                keyword_num++;
            }
        }
        if(a[i] == "switch")
        {
            switch_num++;
            case_count++;
        }
        if(a[i] == "case")
        {
            case_num[case_count]++;//Read from the first
        }
    }
}

The completion function of task 3 and 4:

I encountered great difficulties in solving the three four questions, because I couldn't use the C + + I learned to solve it well, so I consulted the relevant materials and finally decided to use the stack to solve the three four tasks.

The idea of matching parentheses, using the access stack, complete task 3. 4

**The flow chart of task three and four is as follows **:

img

The code of task three and four is as follows:

void Calculate34()
{
    stack <string> s;
    stack <int> have_elseif;
    for (int i = 0;i < if_elseif_else.size();i++)
    {
        if (if_elseif_else[i] == "{")
        {
            s.push("{");
            have_elseif.push(0);
        }
        else if (if_elseif_else[i] == "}")
        {
            while (s.top() != "{")
            {
                s.pop();
            }
            s.pop();
            have_elseif.pop();
        }
        else if (if_elseif_else[i] == "if")
        {
            s.push("if");
            have_elseif.pop();
            have_elseif.push(0);
        }
        else if (if_elseif_else[i] == "else_if")
        {
            have_elseif.pop();
            have_elseif.push(1);
        }
        else if (if_elseif_else[i] == "else")
        {
            if (have_elseif.top())
            {
                if_else_else_num++;
            }
            else
            {
                if_else_num++;
            }
            have_elseif.pop();
            have_elseif.push(0);
            while (s.top() != "if")
            {
                s.pop();
            }
            s.pop();
        }
    }
}

Final code test

The code implement can be seen in github.
Now we use the example to test:

img

  • Deficiency and reflection

    The {} determination mechanism is used to determine three or four tasks, but in the syntax of C and C + +, there can be no {} when writing ifelse statements, so I can't solve this situation.

Task test

img

Summary

  1. Use git for the first time, learn the basic git command, create a warehouse on GIT and upload this job.
  2. Through this assignment, I found the gap between myself and others' code level. When writing code, many ideas could not be realized in code. It was very distressing, but I gained a lot.
  3. When reading and writing files, we read a lot of other people's code, but we have many difficulties in implementing it ourselves. Therefore, when learning code, we should try more by ourselves instead of just listening to knowledge.
  4. Many small details are not handled well, making your code always wrong. It takes a lot of time in the process of continuous debugging, or your ideas are not comprehensive enough.
  5. Many students write in Python. The writing difficulty is much lower than that of C + +. I'm going to attack Python later and master more languages.
...全文

相关推荐

EE-308 LAB4 final version.7z

这是本次实验的压缩包

晨起剪桃花

春秋BC742年世界历史地图矢量文件SHP格式.zip

本资源为《春秋BC742年世界历史地图矢量文件SHP格式》压缩包,文件大小约 26.55 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

白水先森

春秋BC674年世界历史地图矢量文件SHP格式.zip

本资源为《春秋BC674年世界历史地图矢量文件SHP格式》压缩包,文件大小约 26.49 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

白水先森

欠驱动水面船舶的自适应神经(NN)控制圆形+直线轨迹跟踪控制研究(Matlab代码实现)

内容概要:本文针对欠驱动水面船舶在圆形和直线轨迹下的高精度跟踪控制问题,提出了一种基于自适应神经网络(Adaptive Neural Network, NN)的非线性控制方法。该方法有效应对船舶在欠驱动条件下存在的强耦合、非线性动力学特性以及外界环境干扰(如风浪流)等挑战。通过构建适当的神经网络逼近系统未知非线性项,并结合Lyapunov稳定性理论设计自适应律,确保闭环系统的全局一致最终有界性(UUB)。文中详细阐述了控制器结构设计、神经网络权重在线更新机制、控制律推导过程,并利用Matlab/Simulink平台对直线与圆形期望轨迹进行了仿真验证,结果表明所提方法具有良好的跟踪精度、动态响应性能与抗干扰能力,适用于复杂海洋环境下无人船的自主航行控制任务。; 适合人群:具备自动控制理论、船舶与海洋工程或机器人控制等相关专业背景,熟悉非线性系统分析、自适应控制原理,并掌握Matlab仿真工具的研究生、科研人员及从事无人船控制系统开发的工程技术人员。; 使用场景及目标:①研究欠驱动船舶在复杂轨迹下的自主跟踪控制策略;②掌握自适应神经网络在不确定非线性系统中的建模与补偿方法;③复现并拓展高水平期刊论文中的智能控制算法;④为无人水面艇(USV)的实际控制系统开发提供理论支持与仿真验证基础。; 阅读建议:建议读者结合文中的数学推导与Matlab代码实现同步学习,重点理解Lyapunov函数的构造思路、神经网络逼近机制及其参数自适应调整规律,有条件者可进一步将算法迁移至硬件在环(HIL)平台或实船系统进行测试,并与其他先进控制方法(如滑模控制、模型预测控制)开展性能对比分析。

欢多天天写代码

战国BC301年世界历史地图矢量文件SHP格式.zip

本资源为《战国BC301年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.28 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。

白水先森
评论
收藏 已收藏
分享
返回顶部