285
社区成员




The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201?category=0 |
---|---|
The Link of Requirement of This Assignment | https://bbs.csdn.net/topics/608734907 |
The Aim of This Assignment | Lab1_2_solution |
MU STU ID and FZU STU ID | 20122268 and 832001214 |
https://github.com/xingwang133/SE308-lab1_2
Personal Software Process Stages | Estimated time (minutes) | real time (minutes) |
---|---|---|
Planning | 20 | 25 |
Estimate | 5 | 5 |
Development | 150 | 200 |
Analysis | 30 | 30 |
Design Spec | 30 | 30 |
Design Review | 10 | 10 |
Coding Standard | 25 | 20 |
Design | 30 | 30 |
Coding | 90 | 100 |
Code Review | 10 | 10 |
Test and debug | 30 | 40 |
Reporting | 50 | 60 |
Size Measurement | 10 | 10 |
Postmortem & Process Improvement Plan | 20 | 25 |
Total | 510 | 595 |
Since we used c++ in our course last semester, I am quite familiar with it now, so I decided to use c++ to complete this experiment. Solve the problem in stages by breaking it down.
1.Need to read the c file.
2.In order to meet the different Program Requirements, it is necessary to make corresponding code design for four different levels of tasks.
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<sstream>
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"
};
vector<int> Case_num;
int total_num = 0;
int switch_num = 0;
int case_num = 0;
int ifelse_num = 0;
int if_elseif_else_num = 0;
int stack[ 1000 ] = { 0 };
int top = -1;//Define the required variables
Define the function corresponding to the keyword
nt match( string a , string b )
{
int correspond( char str );
int pos = a.find( b , 0 );
int len = b.length();
if( pos != string::npos )
{
if( pos == 0 )
{
if(correspond( a[ pos + len ] ) == 0 )
{
return 1;
}
else
{
return 0;
}
}
else
{
if(correspond( a[ pos + len] ) == 0 && correspond( a[ pos - 1] ) == 0 )
{
return 1;
}
else
{
return 0;
}
}
}
return 0;
}
int correspond( char str )
{
if( ( str <= 'z' && str >= 'a' ) || ( str <= 'Z' && str >= 'A' ) )
{
return 1;
}
else
{
return 0;
}
}
Use keywords to count the text in the test file
void sort_1(string str)
{
for(int i = 0; i < 32; i++ )
{
if(match( str , Keyword[i] ) == 1)
{
if( match( str , "switch" ) )
{
Case_num.push_back( case_num );
switch_num++;
case_num = 0;
}
if( match( str , "case" ))
{
case_num++;
}
total_num++;
break;
}
}
}
void sort_2( string str )
{
if( match( str , "else if" ) )
{
top++;
stack[ top ] = 2;
}
else
{
if( match( str , "else" ) )
{
if( stack[ top ] == 1 )
{
ifelse_num++;
top--;
}
else
{
if( stack[ top ] == 2 )
{
if_elseif_else_num++;
top--;
}
}
}
else
{
if(match( str ,"if" ) )
{
top++;
stack[ top ] = 1;
}
}
}
}
Output the count result
int main()
{
int level;
string file,temp;
cout << "Enter the file path: " << endl;
cin >> file;
cout << "Enter the completion level: " << endl;
cin >> level;
ifstream File( file.c_str() );
int correspond( string a,string b );
int correspond( char str);
void sort_1( string str );
void sort_2( string str );
while ( getline( File ,temp ))
{
istringstream istr ( temp );
string str;
if( level >= 3)
{
sort_2( temp );
}
while( istr >> str )
{
sort_1( str );
}
}
if( level >= 1 ) //level1 and above
{
cout << "total num: " << total_num << endl;
}
if( level >= 2 ) //level2 and above
{
cout << "switch num: " << switch_num << endl;
if( !Case_num.empty() )
{
Case_num.push_back(case_num);
}
else
{
Case_num.push_back(0);
}
cout << "case num: ";
for ( int i = 1; i <= switch_num; i++)
{
cout<< Case_num[i] << " ";
}
cout << endl;
}
if( level >=3 ) //level3 and above
{
cout << "if_else num: " << ifelse_num << endl;
}
if( level >=4 ) //level4 and above
{
cout << "if_elseif_else num: " <<if_elseif_else_num << endl;
}
}
#include <stdio.h>
int main(){
int i=1;
double j=0;
long f;
switch(i){
case 0:
break;
case 1:
break;
case 2:
break;
default:
break;
}
switch(i){
case 0:
break;
case 1:
break;
default:
break;
}
if(i<0){
if(i<-1){}
else{}
}
else if(i>0){
if (i>2){}
else if (i==2) {}
else if (i>1) {}
else {}
}
else{
if(j!=0){}
else{}
}
return 0;
}