软件过程管理作业。。。
代码如下
#include<iostream>
#include<fstream>
using namespace std;
int main(void)
{
ifstream s("D:\\test5.txt");
char x;
int a[26] = {0},b[26];
int count1,count2,count3,countthe = 0,countspace = 0; //count1统计字母个数 count2/3作为关键字母定位标记 countthe记录the的个数 countspace 统计空格个数
while(s.get(x))
{
count1 ++;
if( x >= 65 && x <= 90 )
a[x - 65] ++;
if( x >= 97 && x <= 122 )
a[x - 97] ++;
if(x == 84 || x == 116)
count2 = count1;
if(x == 72 || x ==104)
count3 = count1;
if((x == 69 || x == 101) && (count1 - count3) == 1 && (count1- count2) == 2) //通过位置差来判断t、h、e的相对位置
countthe ++;
if(x == ' ' || x == 10)
countspace ++;
}
for(int i = 0;i < 26; i ++ )
{
printf("%c出现的频率是:%.2f\n",i+65,(a[i])*1.0 / count1);
}
printf("the的出现的次数及频率分别是:%d, %.2f",countthe,(countthe * 1.0) / (countspace + 1));
return 0;
}
一个是c++的文件流,然后是用数组存储相应的字符个数,最后是the的求取算法。评论区多多指教