SE308_lab1_2
Catalogue
- Lab1_2
- GitHub repository
- 1.PSP
- 2.Description of problem-solving ideas
- 3.Design and implementation process
- 4.test file
- 5.Test output
- 6.Summary
Lab1_2
| 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 |
GitHub repository
https://github.com/xingwang133/SE308-lab1_2
1.PSP
| 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 |
2.Description of problem-solving ideas
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.
3.Design and implementation process
#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;
}
}
4.test file
#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;
}
5.Test output

6.Summary
- Learn how to use github and find solutions to problems
- Write a blog for the first time to explain your thoughts and strategies for solving the problem
相关推荐
EE308 Lab7 Demand Analysis and Prototype Design
Lab 7 Demand Analysis and Prototype DesignFormat DescriptionPSPIntroduction of productOther DetailsMain difficultiesWhat do you have to do for this issue?How do you solve it?What gains you have?Team collaboration recordMeeting picturesspecification / proto
EE308 Lab6 Team Presentation and Topic Selection Report
EE308 Lab6 Team Presentation and Topic Selection ReportFormat DescriptionTeam nameSpecific planning and description of the team projectTeam member style1. YUWEI JIANG2. YIFAN SHEN3. SHENKAI XIONG4. ZHU YIFAN5. BEICHEN ZHOUThe team's vision Format Descripti
chrome-headless-shell-win32-159.0.8132.0(Canary).zip
chrome-headless-shell-win32-159.0.8132.0(Canary).zip
惠普150 联想1821 1831 1831W定影清零,转印带清零
惠普150 联想1821 1831 1831W定影清零,转印带清零,报错不打印,通过清零软件可以清除。内附使用说明。
【电液伺服执行器与PI控制器】带有PI控制器的电液伺服执行器的模拟研究(Simulink仿真实现)
内容概要:本文围绕带有PI控制器的电液伺服执行器开展模拟研究,利用Simulink工具构建系统仿真模型,深入分析PI控制器在电液伺服系统中的控制性能与动态响应特性。研究内容涵盖系统建模、PI控制参数整定、仿真结果分析等关键环节,重点探讨PI控制器对系统稳定性、响应速度及抗干扰能力的优化作用,并通过仿真验证控制策略的有效性与实用性; 适合人群:具备自动控制原理、液压传动基础知识及Simulink仿真能力的自动化、机械电子、控制工程等相关专业的高校学生、研究生及工程技术人员; 使用场景及目标:①用于自动控制类课程的教学实验或课程设计,帮助学生深入理解电液伺服系统的工作原理与典型控制方法;②应用于工业高精度执行机构的控制器设计,为实际工程中的系统优化提供理论支撑与仿真验证手段; 阅读建议:文中提供的Simulink模型与仿真流程具备良好的可复现性,建议读者结合具体工况调整PI参数,进一步探究PID或其他先进控制算法的改进效果,以深化对控制系统设计的理解与应用能力。


