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!

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值