EE308 Lab1-2

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

目录

  • CATALOGUE
  • Link of Github
  • 1.PSP form for work
  • 2.Description of problem solving ideas
  • 3.Design and implementation process
  • 4.Code description
  • 5.Unit test screenshots and description
  • 6.Unit test coverage optimization and performance testing
  • 7.Summary
(EE308 Lab1-2)
Self introduction of HUANG LEI

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 or C++ code files that are read in
MU STU ID and FZU STU ID20122586_832001315

CATALOGUE

🛑 Link to my Github code website

1.PSP form for work

Personal Software Process StagesEstimated Time Consumption (mins)Completed Time(mins)
Planning----
Estimate2015
Development----
Analysis90100
Design Specification5050
Design Review2520
Coding Standard2025
Design8090
Coding12001250
Code Review4045
Test10090
Reporting----
Test Report9080
Size Measurement2020
Postmortem & Process Improvement Plan6055
Total17951840

2.Description of problem solving ideas

💻 Programming Language :C++, (Java, Python)
Although I can choose from C++, Java, Python three programming languages, I finally choose C++. C++ has the advantages of rich function, strong expression ability, flexibility and convenience, and wide application 👍. I systematically learned object-oriented programming based on C++, so I used C++ for this experiment.

3.Design and implementation process

🚀 Design four levels to realize the requirement function.
🎲 Create the main function to read the path of a specific C file and the desired level to extract keywords.

code chart

4.Code description

💎 We should first know the 32 keywords.

keywords


①Input function ⌨:

#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<sstream>
#include<stack>
using namespace std;
string keywords[32]={"auto","double","int","struct","break","else","long","switch",
                     "case","enum","register","typedef","char","extern","return","union", 
                     "const","float","short","unsigned","continue","for","signed","void",
                      "default","goto","sizeof","volatile","do","if","while","static"
                    }; 
int peak =-1;    
int container[600]={0};                
int Total_Num=0;
int Switch_Num=0;
int Case_Num=0;
int if_else_Num=0;
int if_elseif_else_Num=0;
vector<int> Case; //Creates a one-dimensional vector with no specified length

②The main function 🪁:

int main() 
{    
    string C_file;
    string interim;
    int Level_Num;
    cout << "Print the path of C/C++ file: " << endl;
    cin >> C_file;
    cout << "Print the level of extract keywords: " << endl;                    
    cout << "Level1: total keywords" << endl;
    cout << "Level2: switch case and case" << endl;
    cout << "Level3: if else" << endl;
    cout << "Level4: if, else if, else" << endl;
    cin >> Level_Num;
    ifstream readfile(C_file.c_str()); //read in the C/C++ file
    void First_Level(string cha);
    void Second_Level(string cha);
    int assess_fun1(string A, string B);
    int assess_fun2(char cha);
    
    while(getline(readfile,interim)){
        istringstream strl (interim);
        string z;
        if(Level_Num >=3){
            Second_Level(interim);    
        }
        while (strl >>z){
            First_Level(z);
        }
    }
    
    if(Level_Num >=1){
        cout << "total num: " << Total_Num << endl;
    }
    if(Level_Num >=2){
        cout << "switch num: " << Switch_Num << endl;
        if(Case.empty()){
            Case.push_back(0);
        }
        else{
            Case.push_back(Case_Num);
        } 
        cout << "case num: ";
        for(int x =1; x<=Switch_Num; x++){ 
            cout << Case[x] << " "; 
        }
        cout << endl;
    }
    if(Level_Num >=3){
        cout << "if-else num: " << if_else_Num << endl;    
    }
    if(Level_Num >=4){
        cout << "if-elseif-else num: " << if_elseif_else_Num << endl;
    } 
}

③The function to find the number of keywords 🔍:

int assess_fun1(string A, string B){
    int pos = A.find(B,0);
    int Len = B.length();
    int assess_fun2(char cha);
    if(pos != string::npos){
        if(pos == 0){
            if(assess_fun2(A[pos+Len]) == 0 && assess_fun2(A[pos-1]) == 0){
                return 1;
            }
            else{
                return 0;
            }
        }    
        else{    
            if(assess_fun2(A[pos+Len]) == 0){
                return 1;
            }
            else{
                return 0;        
            }        
        }
    }
    return 0;
} 
    
int assess_fun2(char cha){  
    if((cha >='A' && cha <='Z') || (cha >='a' && cha <='z')){ 
        return 1;
    }
    else{
        return 0;
    }
}

④The function to calculate the number of keywords depend on different level 💡:

void First_Level(string cha){ //stand for the first two level 1 and 2;
    for (int i =0; i<32; i++){
        if(assess_fun1(cha,keywords[i])==1){
            if(assess_fun1(cha,"switch")){
                Case.push_back(Case_Num);
                Switch_Num++;
                Case_Num = 0;
            }
            if(assess_fun1(cha,"case")){
                Case_Num++;
            }
            Total_Num++;
            break;            
        }
    }
}

void Second_Level(string cha){ //stand for the second two level 3 and 4;
    if(assess_fun1(cha,"else if")){
        peak++;
        container[peak] =2;    
    }
    
    else{
        if(assess_fun1(cha,"else")){
            if(container[peak]==1){
                if_else_Num++;
                peak--;
            }
            else{
                if(container[peak]==2){
                    if_elseif_else_Num++;
                    peak--;
                }
            }
        }
        else{
            if(assess_fun1(cha,"if")){
                peak++;
                container[peak]=1;
            }
        }
    }
}

5.Unit test screenshots and description

🤩The test C 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; 
} 

Level1 👓 :

level1

Level2 🌈 :

level2

Level3 📸 :

level3

Level4 👀 :

level4


✔ The results of the unit tests are consistent with the sample given, and the code of the program implements the required function 😃.

6.Unit test coverage optimization and performance testing

unit test1


unit test2


unit test3

7.Summary

This assignment made me more familiar with C++ and made me realize that I must pay attention to time management in the process of software development. This assignment also made me more aware of my lack of ability, so I need to strengthen my programming skills before the big task 🙂.

...全文

相关推荐

EE-308 LAB4 final version.7z

这是本次实验的压缩包

晨起剪桃花

Microsoft.WinDbg-1.2610.1001.0-x64

Microsoft.WinDbg-1.2610.1001.0-x64

CSUer丶夜神゛

Claude 代码超强能力:核心技能库

Superpowers 是一套面向你的编码智能体的完整软件开发方法论,由一组可组合技能和若干初始指令构建而成,用以确保智能体真正使用这些技能。

yiersansiwu123d

PDF发票内容提取排版并结构化导出xlsx/cvs嵌入式ptyhon

【本地发票提取工具】 核心优势:不依赖传统粗糙 OCR,基于文字排版结构进行精准提取。仅“税网”下载及税网邮件发送的原版 PDF 发票(开票软件发送的不太支持)能实现开票明细级的秒级本地提取,告别只能提抬头、总额的尴尬。 可免费试用 3 天! 【用前须知】 去微软官网下载VC_redist.x64.exe运行修复运行库(必要的前置操作),之后再解压本工具rar,运行本exe即可。 VC_redist.x64.exe官网永久下载地址 https://learn.microsoft.com/zh-cn/cpp/windows/latest-supported-vc-redist 【安全须知】 个人开发暂未做代码签名,杀软可能会有误报拦截。遇到拦截请在杀软中添加信任/白名单即可。 VirusTotal扫描结果 2/61,主流杀软均通过,个别引擎因无签名误报。官网 virustotal.com 点击页面中间显眼的 “Choose file”(选择文件)按钮上传扫描。

信人远邮168

Flask校园二手交易平台课设

这是一份基于 Flask + SQLite 的校园二手交易平台课程设计完整资料,包含实验报告(Markdown、HTML、PDF 三种格式)、全部 Python 源码、8 个 Jinja2 页面模板、5 张运行截图、答辩 PPT。学生注册账号后发布闲置物品,同校同学按分类翻、按关键词搜,看中了在详情页留言咨询,管理员能下架违规商品。不接支付不做物流,买卖双方线下交易,平台只负责信息展示和沟通,一个学期课设能做完。 系统功能:用户注册登录登出,session 维持登录态;发布商品填标题、描述、价格、选六类分类,图片可选上传不强制;首页卡片网格展示在售商品,顶部搜索框按标题描述模糊匹配,下方分类按钮筛选,搜索和筛选可组合;商品详情页展示大图、完整描述、卖家昵称,登录用户能留言咨询;我的发布页能看自己挂过的所有商品并删除;管理员后台能看全部商品,一键下架违规品或恢复在售。 几个值得参考的实现点:密码用 Werkzeug 哈希加盐存储;登录接口不区分"用户不存在"和"密码错误",防枚举用户名;图片上传限制后缀和 2MB,文件名随机串重命名,防覆盖和传脚本;分类和搜索筛选组合用动态拼 SQL;首次启动自动建表写管理员账号;Bootstrap 5 栅格,手机浏览器也能看。 适合正在做 Web 课程设计、Python 后端入门的学生,以及想学习"Flask 蓝图 + SQLite + 登录鉴权 + 文件上传"完整小项目的自学者。拿到手后 cd src,pip install -r requirements.txt,python app.py,浏览器开 http://127.0.0.1:5000 即可,管理员账号 admin/admin123,普通用户自行注册。

小鹿( ﹡ˆoˆ﹡ )
评论
收藏 已收藏
分享
返回顶部