关闭

List列表实现统计文档中单词出现的次数

539人阅读 评论(0) 收藏 举报

WordFreq.h代码:

#include<iostream>
#include<string>
using namespace std;
class WordFreq
{
private:
	int m_freq;
	string word;
public:
	WordFreq(const string str):word(str),m_freq(1){}
	void Incream()
	{
		m_freq++;
	}
	friend bool operator==(WordFreq& st1,WordFreq& st2)
	{
		return st1.word==st2.word;
	}
	friend bool operator<(WordFreq& st1,WordFreq& st2)
	{
		return st1.word<st2.word;
	}
	friend ostream& operator<<(ostream& os,WordFreq &st1)
	{
		os<<st1.word <<"'s frequence is "<<st1.m_freq<<endl;
		return os;
	}
};


cpp:

#include<iostream>
#include<string>
using namespace std;
class WordFreq
{
private:
	int m_freq;
	string word;
public:
	WordFreq(const string str):word(str),m_freq(1){}
	void Incream()
	{
		m_freq++;
	}
	friend bool operator==(WordFreq& st1,WordFreq& st2)
	{
		return st1.word==st2.word;
	}
	friend bool operator<(WordFreq& st1,WordFreq& st2)
	{
		return st1.word<st2.word;
	}
	friend ostream& operator<<(ostream& os,WordFreq &st1)
	{
		os<<st1.word <<"'s frequence is "<<st1.m_freq<<endl;
		return os;
	}
};


 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:438636次
    • 积分:5771
    • 等级:
    • 排名:第4445名
    • 原创:154篇
    • 转载:24篇
    • 译文:0篇
    • 评论:160条
    娜娜
    文章分类
    最新评论