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
这是本次实验的压缩包
早期颠覆性技术商业化加速:政府主导体系搭建步骤与路径.docx
早期颠覆性技术商业化加速:政府主导体系搭建步骤与路径
科技服务机构促成校企合作时,需遵循哪些规范化操作流程?.docx
科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。
美国5435家医院CMS星级质量评级数据集
本数据集基于美国CMS官办的医院质量比较数据库整理加工,覆盖美国56个州和地区的5435家医院,每条记录包含53个字段。数据以医院名录为基础,融合质量评级与衍生分析字段:既有医院名称、地址、所在县州、邮编、电话等基础信息,也包含医院类型、所有制类型、是否提供急诊服务等分类属性,核心是官方发布的总体星级评级与死亡相关指标表现统计(更好、无差异、更差三类计数及脚注),并额外提供所有制分组、急症护理与产科友好标识、评级分档、指标覆盖率、更好更差比率、净指标得分、高评级标记以及各院在本州医院中的占比等衍生字段。其中3166家医院拥有总体评级,4501家提供急诊服务。适用人群:医疗政策研究者、卫生统计分析师、医疗质量管理人员、公共卫生专业师生以及数据科学爱好者。使用场景:适合开展医院质量与所有制关系研究、各州医疗资源与评级分布对比、急诊服务覆盖缺口分析、评级影响因素建模与预测、医院地理分布与可达性研究等课题。其他说明:文件为CSV格式,附带数据字典与说明文档,字段规整、注释完备,可直接导入Python、R、Excel、PowerBI等工具使用,适合课程作业、毕业设计与商业演示,也可作为医疗领域数据仓库建模的入门样例。
战国BC401年世界历史地图矢量文件SHP格式.zip
本资源为《战国BC401年世界历史地图矢量文件SHP格式》压缩包,文件大小约 2.26 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。


