183
社区成员




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 | Read keywords and statement structures in files and learn to use Git |
MU STU ID and FZU STU ID | 19104375 & 831902106 |
Before we learn to use Git, what do we need to know about Reversion control.
Definition: Revision control is a software engineering technique used during development to manage the history of changes made to files, directories, or projects. It can be easily viewed and backed up to restore previous versions.
It can help us:
git add . # add the babababab
git commit -m"comment" # put the comment such as time, author in the comment block
git push origin main
download Git on https://git-scm.com/
Personal Software Process Stages | Estimated Time/minutes | Completed Time/minutes |
---|---|---|
Planning | 30 | 45 |
Estimate | 20 | 30 |
Development | ||
Analysis | 60 | 120 |
Design Spec | 20 | 60 |
Design Review | 5 | 10 |
Coding Standard | 40 | 60 |
Design | 30 | 120 |
Coding | 240 | 600 |
Code ReviewPlanning | 30 | 60 |
Test | 30 | 60 |
Reporting | 60 | 100 |
Test Report | 60 | 40 |
Size Measurement | 15 | 30 |
Postmortem&Process Improvement | 60 | 30 |
total | 670 | 1265 |
Before completing the more difficult requirements, you need to complete the Lower requirements.
Before we type "int main", we need to prepare the following things.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
/*for switch*/
struct CaseNum{
bool activate_switch=false;
bool activate_brace=false;
};
/*for case*/
CaseNum c[100];
static int structNum =0;
int caseArr[100] = {0};
static int casePos=0;
/*for if*/
struct The_if{
bool hasIf = false;
bool elseIf = false;
bool hasElse= false;
};
The_if ifArr[100];
int ifArrPos = -1;
static int IE=0, IEE=0;
The entire file needs to be read first. Use c++ file input output stream, through the Internet access to the relevant information to master the relevant usage of ifstream.
char file_add[100];
cin >> file_add;
ifstream cpp_file(file_add);
The second is to read the contents of the file. Here getLine is used to read the contents of the file line by line and transpose unused strings to Spaces. However, before we start, we need to determine if there is a next row.
getline(fstream, str); // Make the content of the file into a string.
while(!cpp_file.eof()){
getline(cpp_file, line);
for(int i=0;i<line.length();i++){
if( ! (line[i]>='a' && line[i]<='z' || line[i]>='A'&&line[i]<='Z' || line[i]>='0' && line[i]<='9' || line[i] == '{' || line[i]=='}' || line[i]=='_' ||line[i]=='/' || line[i]=='"'))
line[i]=' ';
}
/* For later convenience, we firstly transpose unused strings to Spaces. */
string str;
istringstream is(line); /* Read a separate string in each line*/
}
3.1.1 Keywords list and Store code
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 |
const string Keywords_list[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"};
3.1.2 The number of Keywords
while(is >> str){
if(str[0]=='"'||str[0] == '/') continue;
/*Exclude comments and "double-quoted" text from the result*/
for(int i=0; i < 32; i++){
if( str.length() == keylen[i] ){
if( str.compare(Keywords_list[i])==0 )
Keywords_num++;
}
/*In this forLoop, if the length and information were the same as the list keyword, Keywords_num++, and we can get the total number of the keywords.*/
}
while(is >> str){
if(str[0]=='"'||str[0] == '/') continue;
/*Exclude comments and "double-quoted" text from the result*/
if( str.compare(Keywords_list[i])== 0 && i==25)
c[structNum].activate_switch=true;
if( str.compare("{")==0 && c[structNum].activate_switch==true)
c[structNum].activate_brace=true;
if(c[structNum].activate_switch && c[structNum].activate_brace ){
if( str.compare(Keywords_list[i])==0 && i==2) /*Only when both are active can the count begin*/
caseArr[casePos]++;
}
if(c[structNum].activate_switch && c[structNum].activate_brace && str.compare("}")==0){
structNum++;
casePos++;
}
}
while(is >> str){
if(str[0]=='"' || str[0]=='/') continue;
/*Exclude comments and "double-quoted" text from the result*/
if( line.find("else if")>=0 && line.find("else if")<line.length()){
ifArr[ifArrPos].elseIf = true;
} else if( line.find("if")>=0 && line.find("if")<line.length()){
ifArrPos++;
while(ifArr[ifArrPos].hasElse && ifArrPos<100)
ifArrPos++;
ifArr[ifArrPos].hasIf = true;
} else if ( line.find("else")>=0 && line.find("else")<line.length()) {
ifArr[ifArrPos].hasElse = true;
ifArrPos--;
while(ifArr[ifArrPos].hasElse==true && ifArrPos>=0)
ifArrPos--;
}
}
The_if ifArr[100];
int ifArrPos = -1;
static int IE=0, IEE=0;
for(int i=0;i<100;i++){
if(ifArr[i].hasIf){
if(ifArr[i].elseIf) IEE++;
else{ IE++;
}
}
}
Read the sample file and set the extraction level to a maximum of 4, resulting in the following output.
Using Visual Studio to measure the Proference
I haven't used c++ programming for a long time, and it was a bit intermittent at the beginning of writing, so this experiment was very challenging for me. This assignment is relatively simple if it judges the more standard code like the sample, but it is very difficult if it meets a special case and requires many special cases. Therefore, some special if else_if else structure judgment still exists some problems by the deadline of assignment. Through this assignment, I learned a lot of things that I had never used before, such as Git, Typora, Github... All in all, the experiment was very rewarding and rewarding.
And I want the next experiment to be easier!