EE308LAB1.2

XIiww 2022-10-28 02:43:20
The Link Your Class

https://bbs.csdn.net/forums/MUEE308FZU202201

The Link of Requirement of This Assignmenthttps://bbs.csdn.net/topics/608734907
The Aim of This AssignmenExtract keywords of different levels from the C or C++ code files that are read in.
MU STU ID and FZU STU ID20122217_832001320

GitHub Repository: git@github.com:xiwwww/EE308FZ.git

 

 

目录

1.PSP Form

2.Program Requirements

3.Code Description:

4.Summary

 

1.PSP Form

 

 

Personal Software Process Stages

Estimated time(min)

Time(min)

Planning

15

15

Estimate

20

30

Analysis

120

150

Design Spec

30

45

Design Review

30

45

Coding Standard

20

30

Design

60

90

Coding

400

500

Test

30

60

Reporting

45

60

Size Measurement

30

30

Postmortem&Process Improvement

40

50

total

810

1105

 

 

2.Program Requirements

 

1. Basic requirement: output "keyword" statistics

2. Advanced requirement: output the number of "switch case" structures, and output the number of "case" corresponding to each group

3. Uplifting requirement: output the number of "if else" structures

4. Ultimate requirement: output the number of "if, else if, else" structures

 

3.Code Description:

 for basic level 1

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using std::string;

void Count_Keywork_Switch_Case(string inputfile,int level) {//TODO(JZ)
    std::ifstream inFile(inputfile, std::ios::in); //open file
    string x;
	string y;
	int Keyword_num = 0;
    string keyword[32] = {"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"};
	for (int i = 0;i < x.length(); i++) {
			if (x[i] >= 'A' && x[i] <= 'z')
			{
				y += x[i];
			}
		}
			
		for (int a = 0; a < 32; a++) {
			if (keyword[a] == y) {
					
				Keyword_num += 1;
			}
		}
		}

Level 2: output the number of "switch case" structures, and output the number of "case" corresponding to each group.

if (y == "switch") {
			Count += 1;
			Switch_Loop += 1;
		}
		
		if (Switch_Loop > 0 && y == "case") {
			Case_Number += 1;
		}
		
		if (Switch_Loop > 0 && y == "default") {
			Case_Num += std::to_string(Case_Number);
			Case_Number = 0;
			Switch_Loop = 0;
		}

for level 3 and 4,output the number of "if else" structures and the number of "if, else if, else" structures. Before completing the more difficult requirements, you need to complete the Lower requirements. 

here is brief struc of my code, detail will be show in Github.result:

void Count_If_Elseif(string inputfile, int level) {
    while (getline(inFile, x)) {
 
		for (int i = 0; i < x.length(); i++) {
			if (x[i] >= 'A' && x[i] <= 'z')
			{
				if (x[i] == 'e' || x[i] == 'f' || x[i] == 'l' || x[i] == 's' || x[i] == 'i')
				{
					z += x[i];
				}
			}
 
		}
		
		if (z.length() >= 2 && z.substr(0, 2) == "if") {
			line.push_back(z.substr(0, 2));
 
		}
		
		if (z.length() >= 2 && z.length() <= 6 && z.substr(0, 4) == "else") {
			line.push_back(z.substr(0, 4));
 
		}
		
		if (z.length() >= 6 && z.substr(0, 6) == "elseif") {
			line.push_back(z.substr(0, 6));
 
		}
 
		z = "";
	}
	inFile.close();
 
    for (int a = 0; a < line.size(); a++) {//if else elseif 
		if (line[a] == "if") {
			Sec_else += 1;
			Sec_elseif += 1;
 
		}
		
		if (line[a] == "else" && Sec_else > 0) {
			Count_Ifelse += 1;
			Sec_else -= 1;
			Sec_elseif -= 1;
		}
		
		if (line[a] == "elseif" && Sec_elseif > 0) {
			Sec_else -= 1;
			Sec_elseif -= 1;
			Count_Elseif += 1;
		}
 
 
	}

result: 

total num: 35

switch num: 2

case num: 3 2

if-else num: 2

if -else if- else num: 2

 

4.Summary:

I think this assignment has gone through a lot of hardships. At the beginning, I was very confused when I saw the topic and didn't know how to start, so I consulted my classmates and inquired a lot of information. After writing the code, I kept debugging. Through this experiment, I have deepened my understanding of Python. At the same time, I have realized that my code ability is relatively weak and I need to keep practicing. I hope the next experiment will not be so hasty and confused.

    ...全文
    121 回复 打赏 收藏 转发到动态 举报
    写回复
    用AI写文章
    回复
    切换为时间正序
    请发表友善的回复…
    发表回复

    285

    社区成员

    发帖
    与我相关
    我的任务
    社区描述
    福州大学 梅努斯国际工程学院 软件工程(2022秋) 教学
    软件工程 高校
    社区管理员
    • LinQF39
    加入社区
    • 近7日
    • 近30日
    • 至今
    社区公告
    暂无公告

    试试用AI创作助手写篇文章吧