285
社区成员




The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
---|---|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
The Aim of This Assignment | do lab1-2 |
The Aim of This Assignment | <20124546_832001207> |
github!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | https://github.com/yusdar/114514 |
Personal Software Process Stages | Estimated time (minutes) | Real time (minutes) |
---|---|---|
Planning | 10 | 10 |
Estimate | 40 | 50 |
Development | 10 | 40 |
Analysis | 10 | 10 |
Design Spec | 10 | 10 |
Design Review | 10 | 10 |
Coding Standard | 10 | 10 |
Design | 10 | 10 |
Coding | 60 | 90 |
Code Review | 10 | 20 |
Test | 30 | 60 |
Reporting | 100 | 200 |
Test Report | 20 | 20 |
Size Measurement | 10 | 10 |
Postmortem & Process Improvement Plan | 10 | 10 |
Total | 350 | 560 |
For the questions raised by the topic, I thought that the language to be used was c++, because this programming language was learned last semester, and it was faster to review.
For a series of requirements required by the topic, I think the first thing to do is to realize the function of reading files. After implementation, it is obvious that there will be a lot of symbols in the code. Before we identify the key words in the code, we must extract the non symbolic part of the code.
is obvious. Compare each word extracted from the code with 32 keyword arrays and count them.
find switches first, and then calculate the number of cases until the end of traversal or find the next switch. If found, repeat the previous steps.
judge the nesting relationship according to the sequence of code if and else
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
string Keyword[32]=
{
"auto","break","case","char","const","continue","default","double",
"do","else","enum","extern","float","for","goto","if","int","long",
"register","return","short","signed","sizeof","static","struct",
"switch","typedef","union","unsigned","void","volatile","while"
};
struct KeywordnNum{
string name;
int num;
};
int keywordnum=0;
int main(){
string fileaddress;
string filecontent;
string testcontent;
vector<string> realvocabulary;
cout <<"Enter file address:";
cin >>fileaddress;
ifstream file;
file.open(fileaddress);
while(getline(file,testcontent)){
filecontent+=testcontent;
}
int j=0;
//cout <<filecontent;
for (int i=0;i<filecontent.length();i++){
j=0;
while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
//cout<<filecontent[i+j]<<endl;
j++;
}
if (j!=0){
realvocabulary.push_back(filecontent.substr(i,j));
//cout<<filecontent.substr(i,j)<<endl;
i+=j;
}
}
for (int i=0;i<realvocabulary.size();i++) {
for (j=0;j<32;j++){
if (realvocabulary[i]==Keyword[j]){
keywordnum++;
break;
}
}
}
cout<<"total num:"<<keywordnum<<endl;
}
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
string Keyword[32]=
{
"auto","break","case","char","const","continue","default","double",
"do","else","enum","extern","float","for","goto","if","int","long",
"register","return","short","signed","sizeof","static","struct",
"switch","typedef","union","unsigned","void","volatile","while"
};
struct KeywordnNum{
string name;
int num;
};
int keywordnum=0;
vector<int> switchcase;
int main(){
string fileaddress;
string filecontent;
string testcontent;
vector<string> realvocabulary;
cout <<"Enter file address:";
cin >>fileaddress;
ifstream file;
file.open(fileaddress);
while(getline(file,testcontent)){
filecontent+=testcontent;
}
int j=0;
//cout <<filecontent;
for (int i=0;i<filecontent.length();i++){
j=0;
while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
//cout<<filecontent[i+j]<<endl;
j++;
}
if (j!=0){
realvocabulary.push_back(filecontent.substr(i,j));
//cout<<filecontent.substr(i,j)<<endl;
i+=j;
}
}
for (int i=0;i<realvocabulary.size();i++) {
for (j=0;j<32;j++){
if (realvocabulary[i]==Keyword[j]){
keywordnum++;
break;
}
}
if (realvocabulary[i]=="switch"){
switchcase.push_back(0);
}
else if (realvocabulary[i]=="case"){
switchcase[switchcase.size()-1]++;
}
}
cout<<"total num:"<<keywordnum<<endl;
cout<<"switch num:"<<switchcase.size()<<endl;
cout<<"case num:";
for (j=0;j<switchcase.size();j++){
cout<<switchcase[j]<<' ';
}
cout<<endl;
}
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
string Keyword[32]=
{
"auto","break","case","char","const","continue","default","double",
"do","else","enum","extern","float","for","goto","if","int","long",
"register","return","short","signed","sizeof","static","struct",
"switch","typedef","union","unsigned","void","volatile","while"
};
struct ifelse{
bool iselseif =false;
bool iselse=false;
};
int keywordnum=0;
vector<int> switchcase;
int main(){
string fileaddress;
string filecontent;
string testcontent;
vector<string> realvocabulary;
vector<ifelse> fileifelse;
ifelse a;
cout <<"Enter file address:";
cin >>fileaddress;
ifstream file;
file.open(fileaddress);
while(getline(file,testcontent)){
filecontent+=testcontent;
}
int j=0;
//cout <<filecontent;
for (int i=0;i<filecontent.length();i++){
j=0;
while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
//cout<<filecontent[i+j]<<endl;
j++;
}
if (j!=0){
realvocabulary.push_back(filecontent.substr(i,j));
if (filecontent.substr(i,j)=="if" && filecontent.substr(i-5,7)!="else if"){
fileifelse.push_back(a);
}
else if(filecontent.substr(i,j+3)=="else if"){
//cout <<realvocabulary[i]+realvocabulary[i+1]<<endl;
for (int k=fileifelse.size()-1;k>=0;k--){
if (!fileifelse[k].iselse){
fileifelse[k].iselseif=true;
//cout<<k<<endl;
break;
}
}
}
else if(filecontent.substr(i,j)=="else"){
for (int k=fileifelse.size()-1;k>=0;k--){
if (!fileifelse[k].iselse){
fileifelse[k].iselse=true;
break;
}
}
}
//cout<<filecontent.substr(i,j)<<endl;
i+=j;
}
}
for (int i=0;i<realvocabulary.size();i++) {
for (j=0;j<32;j++){
if (realvocabulary[i]==Keyword[j]){
keywordnum++;
break;
}
}
if (realvocabulary[i]=="switch"){
switchcase.push_back(0);
}
else if (realvocabulary[i]=="case"){
switchcase[switchcase.size()-1]++;
}
}
cout<<"total num:"<<keywordnum<<endl;
cout<<"switch num:"<<switchcase.size()<<endl;
cout<<"case num:";
for (j=0;j<switchcase.size();j++){
cout<<switchcase[j]<<' ';
}
cout<<endl;
cout<<"if-else num:";
int b=0;
for (j=0;j<fileifelse.size();j++){
if (!fileifelse[j].iselseif){
b++;
}
}
cout<<b;
}
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
//#include<>
using namespace std;
string Keyword[32]=
{
"auto","break","case","char","const","continue","default","double",
"do","else","enum","extern","float","for","goto","if","int","long",
"register","return","short","signed","sizeof","static","struct",
"switch","typedef","union","unsigned","void","volatile","while"
};
struct ifelse{
bool iselseif =false;
bool iselse=false;
};
int keywordnum=0;
vector<int> switchcase;
int main(){
string fileaddress;
string filecontent;
string testcontent;
vector<string> realvocabulary;
vector<ifelse> fileifelse;
ifelse a;
cout <<"Enter file address:";
cin >>fileaddress;
ifstream file;
file.open(fileaddress);
while(getline(file,testcontent)){
filecontent+=testcontent;
}
int j=0;
//cout <<filecontent;
for (int i=0;i<filecontent.length();i++){
j=0;
while (filecontent[i+j]<='z' && filecontent[i+j]>='a'){
//cout<<filecontent[i+j]<<endl;
j++;
}
if (j!=0){
realvocabulary.push_back(filecontent.substr(i,j));
if (filecontent.substr(i,j)=="if" && filecontent.substr(i-5,7)!="else if"){
fileifelse.push_back(a);
}
else if(filecontent.substr(i,j+3)=="else if"){
//cout <<realvocabulary[i]+realvocabulary[i+1]<<endl;
for (int k=fileifelse.size()-1;k>=0;k--){
if (!fileifelse[k].iselse){
fileifelse[k].iselseif=true;
//cout<<k<<endl;
break;
}
}
}
else if(filecontent.substr(i,j)=="else"){
for (int k=fileifelse.size()-1;k>=0;k--){
if (!fileifelse[k].iselse){
fileifelse[k].iselse=true;
break;
}
}
}
//cout<<filecontent.substr(i,j)<<endl;
i+=j;
}
}
for (int i=0;i<realvocabulary.size();i++) {
for (j=0;j<32;j++){
if (realvocabulary[i]==Keyword[j]){
keywordnum++;
break;
}
}
if (realvocabulary[i]=="switch"){
switchcase.push_back(0);
}
else if (realvocabulary[i]=="case"){
switchcase[switchcase.size()-1]++;
}
}
cout<<"total num:"<<keywordnum<<endl;
cout<<"switch num:"<<switchcase.size()<<endl;
cout<<"case num:";
for (j=0;j<switchcase.size();j++){
cout<<switchcase[j]<<' ';
}
cout<<endl;
cout<<"if-else num:";
int b=0;
for (j=0;j<fileifelse.size();j++){
if (!fileifelse[j].iselseif){
b++;
}
}
cout<<b<<endl;
cout<<"if-elseif-else num:"<<fileifelse.size()-b;
}
I learned a lot from this experiment. For example, I have learned a lot from the analysis and evaluation before the program, how to use csdn to write a blog, and how to iterate versions. Thank you for software engineering! Experience the four points of happiness!