189
社区成员




这个作业属于哪个课程 | https://bbs.csdn.net/forums/fzuSoftwareEngineering2021?category=0 |
这个作业的要求在哪里 | https://bbs.csdn.net/topics/600574694 |
这个作业的目标 | GitHub的使用,代码规范,完成一个程序 |
学号 | 031902101 |
在完成更高要求的情况前,需完成前置的要求。
PSP | Personal Software Process Stages | 预估耗时(小时) | 实际耗时(小时) |
Planning | 计划 | 1 | 1 |
Estimate | 估计这个任务需要多少时间 | 15.5 | 13.7 |
Development | 开发 | - | - |
Analysis | 需求分析 (包括学习新技术) | 2 | 1.5 |
Design Spec | 生成设计文档 | - | - |
Design Review | 设计复审 (审核设计文档) | - | - |
Coding Standard | 代码规范 (为目前的开发制定合适的规范) | 1 | 1 |
Design | 具体设计 | 2 | 1.6 |
Coding | 具体编码 | 6 | 5 |
Code Review | 代码复审 | 1 | 1 |
Test | 测试(自我测试,修改代码,提交修改) | 1 | 0.6 |
Reporting | 报告 | - | - |
Test Report | 测试报告 | - | - |
Size Measurement | 计算工作量 | 1 | 1 |
Postmortem & Process Improvement Plan | 事后总结, 并提出过程改进计划 | 0.5 | 1 |
合计 | 15.5 | 13.7 |
void readtxt(string file)
{
ifstream infile;
infile.open(file.data()); //将文件对象与文件连接起来
assert(infile.is_open()); //假如失败,输出错误消息,并终止程序运行
char c;
infile >> noskipws;
while (!infile.eof())
{
infile>>c;
a[n++]=c;
}
infile.close(); //关闭文件输入
count();
for(int i=0;i<n;i++){
if(a[i]=='i'&&a[i+1]=='f'&&a[i+2]=='(')
;
}
}
字符串的提取
struct key //构建结构体数组,关键字按顺序排列
{
char *word;
int count;
} keywords[] = {
"auto",0,"break",0,"case",0,"char",0,"const",0,"continue",0,"default",0,"do",0,
"double",0,"else",0,"enum",0,"extern",0,"float",0,"for",0,"goto",0,"if",0,
"int",0,"long",0,"register",0,"return",0,"short",0,"signed",0,"sizeof",0,"static",0,
"struct",0,"switch",0,"typedef",0,"union",0,"unsined",0,"void",0,"volatile",0,"while",0,
};
//关键字的个数等于数组长度除以单个元素的长度
#define NKEYS (sizeof keywords / sizeof(struct key))
int j=0;
int getword(char *word, int lim)
{
char *w = word;
for( j;j<n;j++)
{if(isspace(a[j]))
continue;
else break;}//跳过空白符
*w++ = a[j];
if (!isalpha(a[j])) //不是字母的情况
{
*w ='\0';
return a[j++];
}j++;
for ( ; --lim > 0; w++)
{
if (!isalnum(*w = a[j++])) //输入不是字母或数字时,该单词结束
{
j--;
break;
}
}
*w = '\0'; //字符串结束符'\0'
return word[0]; //返回值为单词的第一个字符
}
统计关键字个数并输出
void count(){
int m;
char word[100000];
for(int i=0;i<n;i++)
{
getword(word, 100000);
if (isalpha(word[0])) //word的第一个单词为字母
{
if ((m = binsearch(word, keywords, NKEYS)) >= 0)
{keywords[m].count++;}//在结构体中查找成功,关键字计数加1
}
}
int sum=0;
for (int i = 0; i < NKEYS;i++)
{sum+=keywords[i].count;
}
cout<<"total num:"<<sum<<endl;
}
这次作业花费了挺多的时间,也是第一次完成的一个项目吧,因为自己之前学习时候的不牢固,只能完成最基础的要求,但也学到了许多新东西,比如说Git的使用,如何用c++进行文件的读取,还有就是vs的一些应用。希望自己以后能学更多的东西,完善好这次的个人作业,努力从基础level提升到终极level。
流程图不够明确,图中没有开始终止,或又没有文字进行说明,从图中看只是一个循坏部分