189
社区成员




这个作业属于哪个课程 | 构建之法-2021秋-福州大学软件工程 |
这个作业要求在哪里 | https://bbs.csdn.net/topics/600574694 |
这个作业的目标 | 实现一个程序,对代码文档进行关键字提取与匹对 |
学号 | 031902622 |
PSP表
PSP Stages |
|
| ||
计划 | 0.2 | 0.2 | ||
时间预估 | 0.1 | 0.4 | ||
开发 | - | - | ||
需求分析 | 3 | 3 | ||
生成设计文档 | - | - | ||
设计复审 | - | - | ||
代码规范 | 1 | 2 | ||
具体设计 | 3 | 3 | ||
具体编码 | 15 | 14 | ||
代码复审 | - | - | ||
test | 1 | 1 | ||
报告 | 2 | 1 | ||
测试报告 | - | - | ||
计算工作量 | 0.1 | 0.1 | ||
总结与提高 | 2 | 4 | ||
总计 | 27.4 | 28.7 |
解题思路分析:
实现一个程序功能,它可以对读入的C或C++代码文件进行不同等级的关键字提取。
基础要求:输出关键字统计信息
进阶要求:输出有几组switch case结构,同时输出每组对应的case个数
拔高要求:输出有几组if else结构
终极要求:输出有几组if,else if,else结构
执行时,需向程序传入两个参数,第一个参数是代码文件的路径,第二个参数是完成等级(从低到高为1,2,3,4)
void BackslashSolve( string & file_name)
{
int s = file_name.length();
stack <char> temp;
while(s--)
{
temp.push(file_name[s]);
}
file_name ="";
while(!temp.empty())
{
file_name+=temp.top();
if(temp.top() == '\\')
file_name += '\\';
temp.pop();
}
}
if( ( isalpha(file_word[i]) && !isalpha(file_word[i+1]) ) )
temp_string = file_word.substr(index,i+1-index);
else
temp_string = file_word.substr(index,i+2-index);
if(keyword_queue.front() == "switch")
{
keyword_queue.pop();
while((keyword_queue.front() == "case" || keyword_queue.front() == "break" || keyword_queue.front() == "default") && !keyword_queue.empty())
{
if(keyword_queue.front() == "case")
f.sum_case[f.case_number]++;
keyword_queue.pop();
}
f.case_number++;
}
这里可以将case数组改成case链表
if(keyword_queue.front() == "if")
{
temp.push(keyword_queue.front());
keyword_queue.pop();
}
else if(keyword_queue.front() == "elseif")
{
temp.push(keyword_queue.front());
keyword_queue.pop();
}
else if(keyword_queue.front() == "else")
{
if(temp.top() == "if")
{
i++;
f.sum_if_else++;
temp.pop();
}
else
{
while(temp.top() == "elseif" && !temp.empty())
{
temp.pop();
}
if(!temp.empty())
{
j++;
f.sum_if_elseif_else++;
temp.pop();
}
}
keyword_queue.pop();
}
其中<istrream>占用时间最多
测试代码 :给的代码案例,另外对给的代码做了注释并测试。
还有那个性能分析,还是不太懂。
请花时间搞懂这个分析工具。