EE308 LAB 1-2
|
The Link Your Class |
bbs.csdn.net/forums/MUEE308FZU202201 |
|
The Link of Requirement of This Assignment |
bbs.csdn.net/topics/608734618 |
|
The Aim of This Assignment |
extract keywords of different levels |
|
MU STU ID and FZU STU ID |
20122934_832001114 |
PSP Form
| Personal Software Process Stages | Estimated time(min) | Time(min) |
|---|---|---|
| Planning | 30 | 50 |
| Estimate | 100 | 100 |
| Development | 10 | 10 |
| Analysis | 100 | 100 |
| Design Spec | - | - |
| Design Review | 10 | 30 |
| Coding Standard | 30 | 40 |
| Design | 40 | 50 |
| Coding | 100 | 100 |
| Code Review | 90 | 80 |
| Test | 120 | 130 |
| Test Report | 60 | 60 |
| Postmortem & Process Improvement Plan· Design Review | 40 | 50 |
| Summary | 630 | 700 |
Procedure
Accroding to the task article, It is obvious that we need to know how to read the file and read the contents of the file. Firstly, we should know how to divide the keywords. the test file only contains the key fields for switch, if-else, and case, so we can finish it quickly.After dividing the structure of these keywords, the number of occurrences is counted.I developed a simple data reading function, can enhance the expansion, all the keywords are written into an array, and then each time from the array of two-dimensional search, find the corresponding keywords, and then count the number. So do that, we can finish the task.
Flow chart

According to the c code make a judgment
to find the number fo the factors

Get the Answers
The Code
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <stack>
using namespace std;
const int maxn = 100;
string &replace_all(string &str, const string &old_value, const string &new_value)
{
while (true)
{
string::size_type pos(0);
if ((pos = str.find(old_value)) != string::npos)
str.replace(pos, old_value.length(), new_value);
else
break;
}
return str;
}
int main()
{
int total_num = 0;
int switch_num = 0;
int case_num = 0;
int if_else_num = 0;
int if_elseif_else_num = 0;
int level;
stack<int> if_else_container;
string codes;
string filename;
ifstream inFile;
string keyword[32]={"void","char","int","float","double","short","long","signed","unsigned",
"struct","union","enum","typedef","sizeof","auto","static","register","extern","const","volatile",
"return","continue","break","goto","if","else","switch","case","default","for","do","while"};
cout << "Type in the file name: " ;
cin >> filename;
cout << "Type in the requirement 1 2 3 or 4 ";
cin >> level;
inFile.open(filename.c_str());
if(inFile.fail())
{
cout << "\nThe file was not successfully opened."
<< "\nPlease check that the file currently exists or type the error name."
<< endl;
exit(1);
}
//Basic Requirement
string Codes[maxn];
int counter=0;
while (getline(inFile, codes))
{
int i,j;
string a;
for(i=0; i<codes.size(); i++)
{
if(codes[i]>='a' && codes[i]<='z')
{
for(j=i; codes[j]>='a' && codes[j]<='z'; j++);
a=codes.substr(i,j-i);
Codes[counter]=a;
counter++;
for(int k=0;k<32;k++)
{
if(a == keyword[k])
{
total_num++;
break;
}
}
i=j;
}
else
{
j=i;
}
}
if (codes.rfind("else if") < maxn)
{
if_else_container.push(1);
}
else if (codes.rfind("else") < maxn)
{
if_else_container.push(2);
}
else if (codes.rfind("if") < maxn)
{
if_else_container.push(0);
}
int index = 0;
replace_all(codes, "(", " ");
replace_all(codes, ")", " ");
replace_all(codes, "{", " ");
replace_all(codes, ":", " ");
replace_all(codes, ";", " ");
istringstream str(codes);
string filter;
string last = "";
}
stack<int> tmp;
while (!if_else_container.empty())
{
int top_element = if_else_container.top();
if_else_container.pop();
if (top_element == 2)
{
tmp.push(2);
}
if (top_element == 1)
{
tmp.push(1);
}
if (top_element == 0)
{
if (tmp.top() == 2)
{
if_else_num++;
tmp.pop();
}
else if (tmp.top() == 1)
{
if_elseif_else_num++;
while (tmp.top() != 2)
{
tmp.pop();
}
tmp.pop();
}
}
}
cout << "total numbers: " << total_num << endl;
// Advanced Requirement
int m,n;
int corresponding_case[maxn] = {0};
for(m=0; m<counter; m++)
{
if(Codes[m] == "switch")
{
switch_num++;
for(int n=m+1; n<counter; n++)
{
if(Codes[n] == "case")
corresponding_case[switch_num]++;
else if(Codes[n] == "switch")
{
m=n-1;
break;
}
}
}
}
if(level >= 2)
{
cout << "switch numbers: " << switch_num << endl;
for(int a=1; a<=switch_num; a++)
{
cout << " the number of case corresponding to switch" << a << ": " << corresponding_case[a] << endl;
}
}
//Uplifting Requirement
if(level >= 3)
{
cout << "if-else numbers: " << if_else_num << endl;
}
if(level >= 4)
{
cout << "if-elseif-else numbers: " << if_elseif_else_num << endl;
}
}
The Summary
First of all, this is my first time classification task, the task that I deeply realize that my programming ability not so beautiful, I also have many shortcomings of my analysis of the problem is not clear, this led to I will complicate and difficult to write a simple code, I hope I can continue to grow and improve the level of their code.
Secondly, this experiment introduced me to GitHub for the first time. Although it was difficult for me to access Github for some special reasons, I finally succeeded in creating my account and successfully storing my code.
Finally, I realized the importance of time management. Using the psp spreadsheet, I knew when to do each task, which gave me a clearer and more specific goal and a sense of urgency. Although there is a certain gap between the completion time and the estimated time, I will continue to improve my code level, and strive to be able to complete the task within the scheduled time.
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
chrome-headless-shell-win32-159.0.8132.0(Canary).zip
chrome-headless-shell-win32-159.0.8132.0(Canary).zip
惠普150 联想1821 1831 1831W定影清零,转印带清零
惠普150 联想1821 1831 1831W定影清零,转印带清零,报错不打印,通过清零软件可以清除。内附使用说明。
【电液伺服执行器与PI控制器】带有PI控制器的电液伺服执行器的模拟研究(Simulink仿真实现)
内容概要:本文围绕带有PI控制器的电液伺服执行器开展模拟研究,利用Simulink工具构建系统仿真模型,深入分析PI控制器在电液伺服系统中的控制性能与动态响应特性。研究内容涵盖系统建模、PI控制参数整定、仿真结果分析等关键环节,重点探讨PI控制器对系统稳定性、响应速度及抗干扰能力的优化作用,并通过仿真验证控制策略的有效性与实用性; 适合人群:具备自动控制原理、液压传动基础知识及Simulink仿真能力的自动化、机械电子、控制工程等相关专业的高校学生、研究生及工程技术人员; 使用场景及目标:①用于自动控制类课程的教学实验或课程设计,帮助学生深入理解电液伺服系统的工作原理与典型控制方法;②应用于工业高精度执行机构的控制器设计,为实际工程中的系统优化提供理论支撑与仿真验证手段; 阅读建议:文中提供的Simulink模型与仿真流程具备良好的可复现性,建议读者结合具体工况调整PI参数,进一步探究PID或其他先进控制算法的改进效果,以深化对控制系统设计的理解与应用能力。
FYZN PcbDesigner.App.1.0.18.12-win10.rar
打开与保存 常用格式直接读写:打开、编辑、保存 .PcbDoc(含设计规则、层叠等信息)也能打开看结构 原理图文档:打开 / 新建 .SchDoc,和 PCB 文档一起在左侧项目树里管理,双击节点即可重开 另存为通用 ASCII:原理图与 PCB 都能导出为 ASCII 格式,方便文本比对、脚本处理,或交给别的流程 底图参考:需要对着图描的时候,可以给每个图层各放一张参考底图,与文件分开存 JSON,迁移工程时能一起带走 最近文件:最近打开的文件列表里可以直接右键「打开文件位置」 win10版本


