词汇量统计

113 篇文章 0 订阅
74 篇文章 1 订阅

 

考虑一个手机应用功能,统计出用户的(英语)词汇量

1. 录入词库

2. 统计,连续弹出单词让用户识别,统计出认识的词汇总量,给用户作参考

 

一个简单的例子,根据txt文本中的英文内容提前出单词

//5-22 get words from a text
void getWords()
{

	map <string, int> dic;
	map <string, int> :: iterator pIter;

	fstream infile;
	char buf[1024*8];
	
	//read a txt file and get the word in each line and store the words into a map
	infile.open("D:\\2013\\05\\book\\test.txt");
	while(!infile.eof()) //ÅжÏÎļşÊÇ·ñ¶Á½áÊø
	{
		infile.getline(buf, 1024*8);
		char* p = buf;
		char aWord[64] = {0};
		int pos = 0;
		while(*p != '\0')
		{
			if (*p != ' ' && *p != '(' && *p != '"' && *p != ',' && 
				*p != '.' && *p != ':' && *p != '?' && *p != ')' && *p != '[' && *p != ']'
				&& *p != '!')
			{
				aWord[pos++] = *p;
			}
			else
			{
				aWord[pos] = '\0';
				if (pos > 0)
				{
					//ignore the case
					if (aWord[0] >= 'A' && aWord[0] <= 'Z')
					{
						aWord[0] += ('a' - 'A');
					}
					string astr = aWord;
					dic[astr] = 1;
				}
				pos = 0;
			}
			p++;
		}

		
		if (pos > 0)
		{
			aWord[pos] = '\0';
			if (aWord[0] >= 'A' && aWord[0] <= 'Z')
			{
				aWord[0] += ('a' - 'A');
			}
			string astr = aWord;
			dic[astr] = 1;
		}
	}

	infile.close();

	//write the words into a text, each word takes one line
	fstream ofile;
	ofile.open("D:\\2013\\05\\book\\result.txt", ios::app );

	for ( pIter = dic.begin( ) ; pIter != dic.end( ) ; pIter++ )
	{
		ofile <<  pIter -> first << endl;
	}
	ofile.close();

}



 

5.22  Ag 4.44

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值