EE308-Lab1_2

xxxtfish 2022-10-27 00:54:04
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!🙂

...全文
139 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
FASMARM v1.42 This package is an ARM assembler add-on for FASM. FASMARM currently supports the full range of instructions for 32-bit and 64-bit ARM processors and coprocessors up to and including v8. Contents: 1. ARM assembly compatibility 2. UAL and pre-UAL syntaxes 3. IT block handling 4. Alternate encodings 5. Output formats 6. Control directives 7. Data definitions 8. Defining registers lists inside macros 9. Half-precision number formatting 10. Variants supported 11. Further information 12. Version history _______________________________________________________________________________ 1. ARM assembly compatibility There are a few restrictions how the ARM instruction set is implemented. The changes are minor and mostly have a minor impact. For the most part the basic instruction outline is the same. Where possible the original style is used but there are some differences: Not everything matches the ARM ADS assembly style, where possible the original style is used but there are some differences 1) label names cannot begin with a digit 2) CPSIE and CPSID formats are changed, use "iflags_aif" form instead of "aif" (eg. "CPSIE iflags_i" instead of "CPSID i") 3) SRS with writeback must have a separating space after the mode number and before "!" (eg. "SRSDB 16 !" instead of "SRSDB 16!") 4) macro, rept, irp, format, if, virtual etc. are all significant changes from the ARM ADS, so you will need to re-write those sections of existing code Original ARM Syntax | fasmarm Syntax ----------------------+---------------------- cpsie a | cpsie iflags_a | srsdb #29! | srsdb #29 ! ;or, | srsdb 29 ! _______________________________________________________________________________ 2. UAL and pre-UAL syntaxes fasmarm supports the original pre-UAL syntax and the newer UAL syntax. These two syntaxes only affect THUMB encodings. UAL stands for: Universal Assembly Language. pre-UAL syntax is selected wi

285

社区成员

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

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