EE308 Lab2
EE308 Lab2 Individual programing work
| The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZ?category=0 |
|---|---|
| The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/600798588 |
| The Aim of This Assignment | Git/GitHub Using & Keywords Capturing |
| MU STU ID and FZU STU ID | 19105185 / 831901317 |
PSP
| Personal Software Process Stages | Estimated time(min) | Time(min) |
|---|---|---|
| Planning | 30 | 70 |
| Estimate | 200 | 700 |
| Development | - | - |
| Analysis | 180 | 200 |
| Design Spec | 10 | 15 |
| Design Review | 10 | 15 |
| Coding Standard | 30 | 40 |
| Design | 40 | 60 |
| Coding | 340 | 580 |
| Code Review | 60 | 110 |
| Test | 60 | 290 |
| Test Report | 60 | 70 |
| Postmortem & Process Improvement Plan· Design Review | 50 | 60 |
| Summary | 1070 | 2210 |
Stating with Git
Git installation tutorial https://www.cnblogs.com/ximiaomiao/p/7140456.html
Github tutorial https://www.bilibili.com/video/BV1Xx411m7kn?spm_id_from=333.999.0.0
GitHub Repository
My source code https://github.com/1615639948/Lab2/blob/main/Final.cpp


Ideas of solving the problem
Choice of language :The first is the problem of language selection. In our freshman year, we majored in electronic information engineering learned the language python. In our sophomore year, we learned Arduino C. in the second semester of our sophomore year, we learned C + +. Here, I first sent C language, because the C language I involved is only some simple single-chip microcomputer programming, which can not complete this task at all. However, python has been learning for too long and forgotten too much, so I can only choose C + + for programming. However in the process of writing, I obviously feel that C + + is cumbersome. In the later programming, I should learn more about python.
General idea flow chart

Text input :To be honest, I spent a lot of time on text input, because I didn't use C + + for a long time. At the beginning, I learned how to read text. At first, I was worried that I could only read .txt files instead of .cpp files, but after testing, it was found that it could be successfully implemented.
c++读取TXT文件内容 - 张成的博客 - 博客园 (cnblogs.com) https://www.cnblogs.com/nkzhangcheng/p/7722568.html
I first used the reading of the whole text. A txt variable of string type is created to receive the content of text, and then a vector < string > text is created to receive the elements in each txt as a quantity in the string array.
void ReadFile(InputInformation input,vector<string> text){ ifstream file(input.file_address); for (string txt; file >> txt;) { text.push_back(txt); } for (int i = 0; i < text.size(); ++i) { cout << text[i]; } }This is the result of code testing:

However, I found it difficult to read the full text above after 3 and 4 questions, so I modified it to read line by line, that is, the form of the final code.
int main() { int level; string filename,temp; cout<<"input the text address: "; cin>>filename; ifstream file(filename.c_str()); if ( ! file) { cout << "File cannot be opened" <<endl; }else { while (getline(file,temp)) { // Input from disk file, read in line by line, processed line by line TakeKeywords(temp); } file.close(); // Close the file input stream } }
Text Processing :
Use the TakeKeywords function to convert the text. First, convert the string to an array of char, then process the char array, remove symbols, and concatenate adjacent letters, so that you can get a number of strings, and then compare the string with the keywords in the lexicon, you can pick out the correct string And store it in an array for questions 1 and 2.
In addition, vector if_elseif_else is used to store '{', '}', 'if', 'else if', 'else' during reading, which is used to solve problems 3 and 4. However, else_if is not easy to judge in the implementation process, and it will be pressed repeatedly in the process. Finally, whether else is pressed in the previous one is used to judge the condition.
Flow chart of text conversion:

**This is my code implementation:**
void TakeKeywords(string s) {
string str;
int len = s.length();
int symbol = 0; //Check if non-alphabetic characters are '{' or '}' and mark them
const char* p = s.data(); //将string转化为char *[]
for (int i = 0; i < len; ++i) {
if (p[i] == '{')
{
symbol = 1;
}
if (p[i] == '}')
{
symbol = 2;
}
if ((p[i] >= 'a'&&p[i] <= 'z'||p[i] >= 'A'&&p[i] <= 'Z'))
{
str += p[i];
}
else
{
if (str == "")//No letters are encountered, but parentheses may be encountered, check, if any, press into IEE
{
if (symbol == 1){
if_elseif_else.push_back("{");
}
if (symbol == 2){
if_elseif_else.push_back("}");
}
symbol = 0;
continue;
}
temp1[countNum] = str;
countNum++;
if (str == "else") //If we find an else if we find an else if we find an if after n Spaces
{
int j = i;
while (p[j] == ' ' && j <= len){
j++;
}
if (p[j] == 'i' && p[j+1] == 'f'){
if_elseif_else.push_back("else_if");
i = j+2;
keyword_num++;
}else{
if_elseif_else.push_back("else");
}
}
if (str == "if"){ //I find if and I tell you if the previous one is else, if it's not, I push if in
if(if_elseif_else.back() != "else"){
if_elseif_else.push_back("if");
}
}
if (symbol == 1){
if_elseif_else.push_back("{");
}
if (symbol == 2){
if_elseif_else.push_back("}");
}
symbol = 0;
str = "";
continue;
}
}
}
The completion function of task 1 and 2:
The TakeKeywords() function completes all the preparations for the completion of subsequent tasks. I think task one or two is relatively simple in difficulty, but task three or four is more difficult.
Calculate12(). Get the required results through the use of arrays:
void Calculate12(string a[]){
int i,j;
for(i = 0;i < countNum;i++)
{
for(j = 0;j < 32;j++)//Decide if the word is the desired keyword
{
if(a[i] == key_word[j])
{
keyword_num++;
}
}
if(a[i] == "switch")
{
switch_num++;
case_count++;
}
if(a[i] == "case")
{
case_num[case_count]++;//Read from the first
}
}
}
The completion function of task 3 and 4:
I encountered great difficulties in solving the three four questions, because I couldn't use the C + + I learned to solve it well, so I consulted the relevant materials and finally decided to use the stack to solve the three four tasks.
The idea of matching parentheses, using the access stack, complete task 3. 4
**The flow chart of task three and four is as follows **:

The code of task three and four is as follows:
void Calculate34()
{
stack <string> s;
stack <int> have_elseif;
for (int i = 0;i < if_elseif_else.size();i++)
{
if (if_elseif_else[i] == "{")
{
s.push("{");
have_elseif.push(0);
}
else if (if_elseif_else[i] == "}")
{
while (s.top() != "{")
{
s.pop();
}
s.pop();
have_elseif.pop();
}
else if (if_elseif_else[i] == "if")
{
s.push("if");
have_elseif.pop();
have_elseif.push(0);
}
else if (if_elseif_else[i] == "else_if")
{
have_elseif.pop();
have_elseif.push(1);
}
else if (if_elseif_else[i] == "else")
{
if (have_elseif.top())
{
if_else_else_num++;
}
else
{
if_else_num++;
}
have_elseif.pop();
have_elseif.push(0);
while (s.top() != "if")
{
s.pop();
}
s.pop();
}
}
}
Final code test
The code implement can be seen in github.
Now we use the example to test:

Deficiency and reflection
The {} determination mechanism is used to determine three or four tasks, but in the syntax of C and C + +, there can be no {} when writing ifelse statements, so I can't solve this situation.
Task test

Summary
- Use git for the first time, learn the basic git command, create a warehouse on GIT and upload this job.
- Through this assignment, I found the gap between myself and others' code level. When writing code, many ideas could not be realized in code. It was very distressing, but I gained a lot.
- When reading and writing files, we read a lot of other people's code, but we have many difficulties in implementing it ourselves. Therefore, when learning code, we should try more by ourselves instead of just listening to knowledge.
- Many small details are not handled well, making your code always wrong. It takes a lot of time in the process of continuous debugging, or your ideas are not comprehensive enough.
- Many students write in Python. The writing difficulty is much lower than that of C + +. I'm going to attack Python later and master more languages.
相关推荐
EE-308 LAB4 final version.7z
这是本次实验的压缩包
高校技术转移办公室人员如何高效开展技术需求挖掘工作?.docx
科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。
科技中介服务机构如何提升服务的专业性与用户粘性?.docx
科技中介服务机构如何提升服务的专业性与用户粘性?
高校技术转移办公室人员在组织科研成果展示时,如何提升推介材料的专业性与吸引力?.docx
科易网基于AI模型+行业大数据,在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,推出科技创新领域的AI+工具与数智化解决方案,推动科技创新与产业创新智能化发展。
三相并网逆变器无功功率扰动+孤岛检测控制算法仿真【参考文献+仿真】
内容概要:本文系统梳理了一套面向电力电子与新能源并网领域的仿真研究资源,聚焦三相并网逆变器的关键控制技术,涵盖无功功率扰动、孤岛检测算法、低电压穿越(LVRT)、中点电位平衡、虚拟同步发电机(VSG)、下垂控制、模型预测控制(MPC)、准PR控制及LCL滤波器设计等核心技术。资源包含多种逆变器拓扑结构(如T型三电平、Z源、ANPC、四桥臂等)的Simulink仿真模型,并结合扫频法进行正负序阻抗建模与稳定性分析,强调通过复现经典科研案例提升实际科研能力,适用于电力系统稳定性、微电网运行与可再生能源并网等方向的研究与验证。; 适合人群:电力电子、电气工程及其自动化、新能源科学与工程等相关专业的高校研究生、科研人员及从事光伏、储能逆变器开发的工程技术人员,需具备MATLAB/Simulink仿真基础和一定的电力系统控制理论知识。; 使用场景及目标:① 掌握三相并网逆变器在孤岛检测、无功调节、不平衡电网等复杂工况下的先进控制策略设计与仿真方法;② 借助提供的仿真模型与参考文献快速搭建科研平台,用于论文复现、课题开发或项目验证;③ 深入理解VSG、MPC、阻抗建模与下垂控制等关键技术的实现机制与工程应用路径。; 阅读建议:建议结合文中提供的网盘链接与公众号“荔枝科研社”获取完整仿真模型与参考资料,按照目录顺序循序渐进学习,注重理论推导与仿真实践相结合,优先复现基础模型再进行参数优化与创新拓展。


