IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> EE308 LAB2 -> 正文阅读

[开发工具]EE308 LAB2

LAB2 Progress Logging

The Link Your ClassMU-EE308
The Link of Requirement of This AssignmentLAB 2 Individual work
The Aim of This Assignmentlab 2
MU STU ID and FZU STU ID<19015339_831902126>

My Github Link:
Github

My Code Style:
My Code Style

Ⅰ. Use Git to conduct version control

1. Create Github Repository

2. Clone your Repo to local

First we enter a working directory and create your local directory to store all your local repositories.
在这里插入图片描述
You may notice that all the commands are liken Linux commands, exactly! I strongly recommend you to revise Linux commands before using Git.
Secondly, using SSH to clone the remote repository to local. I assume that you have already set up your SSH on Github.
在这里插入图片描述
在这里插入图片描述
Great!

3. Make your first commit!

First enter the local repo:
enter_local_repo
You can see that the name of repo is set as origin automatically.
Select the file you want to upload to local repository and commit it to the local repository. Here, I use the command:

git add file_name

and

git commit -m "some commit info"

Of course, you can check the status using the command:

git status

Here is my commit process:
make_commit

4. Push local to remote

Use the command:

git push -u origin main

to push the local change to remote.

push_to_remote
Now, check out the Github remote repo, you can see the change have already been made.

Ⅱ. PSP Form

Personal Software Process StagesEstimated Time/minutesCompleted Time/minutes
Planning--
Estimate1515
Development--
Analysis120180
Design Spec4045
Design Review 2030
Coding Standard3020
Design5080
Coding12001400
Code Review Planning6045
Test90120
Reporting--
Test Report6045
Size Measurement1010
Postmortem&Process Improvement12090
total18152080

Ⅲ. Description of problem-solving ideas

The first two tasks is easy: Use a setto store all the keywords. First preprose all the code and extract all the keywords and }, {. Then just traverse them and we can obtain the result.
The last two task is a little bit tricky: The if-elseand if-else if-elsecan nested. The main idea is here:

1. Extract the keywords if and else and consider else-if as one keyword
2. At the same time, also extract the "level" of each of them like this:

完美处理多层嵌套

3. Then, we can process the if-else and if-else if-else with all the levels
4. Traverse the same level at a time.

Ⅳ. Design and implementation process & Code Description

在这里插入图片描述

The functions in the mainlevel is:
在这里插入图片描述

Preprocess

The pathstore the path of our test file and I create a vectorcalled codeto store all the codes in the test file. And the int levelwas used to store the solution level.
Then the read()and readFile()functions are used to read the user input, i.e. path and level, and read in all the content in the test file.
In order to be more convenient, the function preprocess()is used to delet every non-letter(except they are {or}) character.
在这里插入图片描述
在这里插入图片描述

Count keywords

After these process, we can count the keywords now! Just traverse all the codeand count them.

const set<string> keywords = {"auto", "break", "case", "char", "const",
							  "continue", "default", "do", "double", "else",
							  "enum", "extern", "float", "for", "goto", "if",
							  "int", "long", "register", "return", "short",
							  "signed", "sizeof", "static", "struct", "switch",
							  "typedef", "union", "unsigned", "void",
							  "volatile", "while"};
/* 
Return the total num of keywords in a code file
the path directed to.
*/
int countKeywords(vector<string> &code)
{
	int total_num = 0;
	for (int i = 0; i < code.size(); i++)
	{
		if (keywords.find(code[i]) != keywords.end())
		{
			total_num++;
		}
	}
	return total_num;
}

And the result is seemingly perfect:
在这里插入图片描述

Count switchand case

The idea of this part is same as the last one. Just traverse it and count switchand case.
The function here is countSwitchAndCase()
The result is here:
在这里插入图片描述

Count if-else

At this part, the relationship of functions is:
solve() -> countIfElse() -> extractKeyLevel() -> extractIfElse()
In the solve()funtion, call the countIfElse()funtion, in this one, call extractKeyLevel(), which is used to extract the ifand elseand else ifkeywords and its “level”, this function needs the value returned by function extractIfElse(), which returned the vector of only the ifand elseand else ifkeywords and {}.
After getting all the return value of extractKeyLevel() extractIfElse()function, the countIfElse()
could work:
在这里插入图片描述
Define a pair, which store the keyword in its first slot, and the “level” in the second slot.
在这里插入图片描述
The idea is here:
Traverse the vector, when it encounters if, meaning that the count process should start.
Create the second pointer, used to track the end of if-else.
When the second pointer encounters else if, meaning that this must not be an if-else.
When it encounters an else, and have the same level at the same time, meaning that it can be counted as an if-else.
So here is the result:
在这里插入图片描述

Count if-else if-else

The idea is liken the last one.
在这里插入图片描述
And the result is:
在这里插入图片描述

Ⅴ. Unit test screenshots and description

A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. Here is my unit test:
在这里插入图片描述

Ⅵ. Performance Testing

use clock()function to test performance of my code.

	#include "stdlib.h"
	#include "time.h"
	clock_t start, finish;
	double duration;
	start = clock();
	/*My code here*/
	finish = clock();
	duration = (double)(finish - start) / CLOCKS_PER_SEC;
	printf("%f seconds\n", duration);

On my machine, the result is 0.003s, which is really good.
在这里插入图片描述
And the Time complexityis also no more than O ( n 2 ) O(n^2) O(n2), which is also acceptable.

Ⅶ. Summary

In this lab, I was so struggling with the writing code part.
My commit record:
在这里插入图片描述

What did I learn:

  • Revise every thing of C++
  • How to use Git
  • Planning before coding is so important
  • Performance Testing
  • Unit Testing

See you next lab!

在这里插入图片描述

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-09-24 10:47:05  更:2021-09-24 10:47:28 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/16 2:37:52-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码