EE308Lab1-2

阮喆吉 阮喆吉 墨衍会员 · 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 AssignmentExtract keywords of different levels from the C code files that are read in
MU STU ID and FZU STU ID20124163 832002230

github Repository

https://github.com/ZhejiRuan/EE308_Lab1_2

1.Give the PSP form for this work.

Framework activities:what I could doESTIMATE TIME(MINUTE)
PlanningUnderstand the meaning of the problem, think of a rough solution process60
designProgram the idea and write a rough outline150
Code ReviewCheck for compliance with programming specifications and check for syntax errors90
TestImport different data for detection90
Postmortem & Process Improvement PlanDo an overall review to make sure the program works30
Total420

2.Problem Solving Ideas

First, find the method to read the c file.
Second, find c language keywords table, in the form of an array into the code,
Third, through the regular expression and stack to achieve the task.
Fourth, the requirements are divided into 4 levels, input the corresponding level can execute the corresponding code.

3.Design and implementation process

First, read the file from BufferedReader and put it together as a string.
Second, put the keyword table into the array,
Third, match all keywords according to the regular expression and count them.
Fourth, distribution solves Switch, case,if-else,if-elseif-else cases.

img

4.Code description. Show the key code of the project and explain the idea

First, gets user's input, reads the specified file and judge requirements.

        Scanner scanner = new Scanner(System.in);

        //Read C file from file address
        System.out.println("Please input the path of the code file");
        //String fileName = "D:\\Code\\software_engineering_lab1\\src\\sample.c";
        String fileName = scanner.nextLine();

        //Read the file
        BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
        String Cfilepath = "";
        String line = bufferedReader.readLine();
        while (line != null) {
            Cfilepath += line;
            line = bufferedReader.readLine();
        }
        
        //Completion Level: You can enter 4
        System.out.println("Please input the completion level (from low to high as 1, 2, 3, 4 )");
        int level = scanner.nextInt();

        //Judge requirements
        switch (level) {
            case 1:
                findKey(Cfilepath);
                break;
            case 2:  
                findKey(Cfilepath);
                findSwitchAndCase(Cfilepath);
                break;
            case 3:
                 findKey(Cfilepath);
                 findSwitchAndCase(Cfilepath);
                 processElse(Cfilepath,3);
            case 4:
                 findKey(Cfilepath);
                 findSwitchAndCase(Cfilepath);
                 processElse(Cfilepath,4);
                 break;
         }

Second, level 1, this is the function code for extract the word to store in an array.

public static void findKey(String s) {
            String keywords = "char,short,int,long,signed,unsigned,float,double,struct,union,enum,void,"
                    + "for,do,while,break,continue,if,else,goto,switch,case,default,return,"
                    + "auto,extern,register,static,typedef,const,sizeof,volatile";
            Pattern p1 = Pattern.compile(",");
            String[] cKeyword = p1.split(keywords);
            int totalNum = 0;
            for (String oneKey : cKeyword) {
                Pattern p = Pattern.compile(oneKey + "[^a-z]");
                Matcher matcher = p.matcher(s);
                while (matcher.find()) {
                    totalNum++;
                }
            }
            System.out.println("total num: " + totalNum);
        }

Third, level 2, find the switch and output the number of "case" corresponding to each group.

public static void findSwitchAndCase(String s) {
            Pattern p1 = Pattern.compile("switch");
            String[] switchs = p1.split(s);
            int switchNum = switchs.length - 1;
            System.out.println("switch num: " + switchNum);

            System.out.print("case num:");
            for (int i = 1; i < switchs.length; i++) {
                Pattern p2 = Pattern.compile("case");
                String[] cases = p2.split(switchs[i]);
                int caseNum = cases.length - 1;
                System.out.print(" " + caseNum);
            }
            System.out.println("");
        }

Fourth, level 3 and level 4, find the number of else if and if-else if -else.

public static void processElse(String code,int level) {
        int ifelNum = 0;
        int esifNum = 0;
        boolean lock = true;
        Stack stack = new Stack();
        Pattern pattern = Pattern.compile("else if|if|else");
        Matcher matcher = pattern.matcher(code);
        while (matcher.find()) {
            String temp = matcher.group();
            if ("if".equals(temp)) {
                stack.push(temp);
            } else if ("else if".equals(temp)) {
                stack.push(temp);
            } else if ("else".equals(temp)) {
                if ("if".equals(stack.peek())) {
                    stack.pop();
                    ifelNum++;
                } else {
                    while (!"if".equals(stack.peek())) {
                        stack.pop();
                        if (lock == true) {
                            esifNum++;
                            lock = false;
                        }
                    }
                    stack.pop();
                    lock = true;
                }
            }
        }
        if (level == 3) {
            System.out.println("if-else num: " + ifelNum);
        } else if (level == 4) {
            System.out.println("if-else num: " + ifelNum);
            System.out.println("if-elseif-else: " + esifNum);
        } else {
        }
    }

5.Unit test screenshots and description.

level 1:

img

level 2:

img

level 3 and level 4:

img

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

As shown in the figure below, there were problems with the previous codes at level 3 and level 4. After communicating with team members, we found the problem and corrected the code errors in time.

img

7.Summarize this assignment.

Through this experiment, I understand that in order to complete the experiment faster and better, we need to make a preliminary plan first, and we need to have a full understanding and analysis of the subject. Draw program flow chart, convenient for us to complete the implementation of the code. At the same time, when there is a problem in the experimental code, we should timely discuss the problem with the team members and solve the problem in time.

...全文

相关推荐

EE-308 LAB4 final version.7z

这是本次实验的压缩包

晨起剪桃花

基于混合储能协调控制的三相并网逆变系统设计【附说明文档】

内容概要:本文围绕“基于混合储能协调控制的三相并网逆变系统设计”展开,系统阐述了蓄电池与飞轮储能等混合储能系统在微电网中的协同控制策略。研究涵盖三相并网逆变器的能量管理、SOC(荷电状态)恒压恒流充放电控制、PQ控制与双闭环控制等核心技术,并基于Matlab/Simulink仿真平台实现了系统建模与动态仿真验证。文中深入探讨了飞轮储能系统的机侧PQ控制与网侧变流器的恒压双闭环控制,分析了微电网在调频调峰、功率协同分配等方面的运行特性,强调多能源间的协调优化与系统的快速动态响应能力,旨在提升微电网的运行稳定性、电能质量及能源利用效率。; 适合人群:具备电力电子、自动化或电气工程等相关专业背景,从事新能源发电、微电网控制、储能系统集成与优化等领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①深入研究混合储能系统在微电网中的协调控制机制与能量管理策略;②掌握三相并网逆变器的建模、控制算法设计及Matlab/Simulink仿真方法;③实现储能系统的高效充放电管理与并网功率精确控制;④为学术论文撰写、科研课题申报、工程项目开发或实验复现提供完整的技术方案与参考实例。; 阅读建议:建议结合所提供的仿真模型、说明文档及参考文献,按照系统架构从单元控制到整体协调的顺序分模块学习,重点关注各控制策略的设计原理、参数整定方法与协同逻辑。推荐在Matlab环境中动手复现仿真,通过调整参数和工况来观察系统响应,以深化对理论知识的理解和工程应用能力的掌握。

梦想科研社_研学

科技中介服务机构在服务企业时,如何通过平台降低服务门槛和操作复杂度?.docx

科技中介服务机构在服务企业时,如何通过平台降低服务门槛和操作复杂度?

BIZKEEN

运维管理基于Hyperfilelens的Docker Compose业务系统备份恢复:机房设备更换场景下的数据迁移与验证方案设计

内容概要:本文介绍了在机房存储设备更换及固件升级背景下,通过 Hyperfilelens 实现多套 Docker Compose 部署的业务系统备份与恢复的全过程。文章围绕备份迁移的实际操作,详细阐述了从主机接入、备份路径选择、策略配置、恢复执行到业务验证的七个关键步骤,并结合截图说明各环节的操作要点。特别强调了不仅要完成数据备份与恢复,还需核对目录结构、服务启动状态和业务功能可用性,确保迁移后系统完整可用。最终总结了 Hyperfilelens 在集中管理保护对象、制定备份策略、明确恢复目标和提供可核查记录方面的核心价值,倡导将备份作为常态化运维机制而非临时应急措施。; 适合人群:从事运维、系统管理及相关技术岗位,具备一定 Docker 和服务器管理经验的技术人员,尤其是面临机房设备更新或系统迁移任务的团队成员。; 使用场景及目标:①解决老旧存储设备更换过程中的业务系统平滑迁移问题;②实现基于 Docker Compose 架构的应用数据可靠备份与异机恢复;③建立可复用的备份恢复流程,提升运维自动化与可靠性。; 阅读建议:建议结合文中提到的平台界面和操作命令逐步实践,重点关注备份范围确认、一致性保护、恢复路径核对及业务端到端验证,避免仅依赖工具状态而忽视实际业务可用性。

。。。。609

chromedriver-mac-arm64-158.0.8127.18(Beta).zip

chromedriver-mac-arm64-158.0.8127.18(Beta).zip

LCG元
评论
收藏 已收藏
分享
返回顶部