⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d_wfreq.h

📁 数据结构c++语言描述stl版 威廉兄弟的好书,值得看,这是配书代码
💻 H
字号:
#ifndef WORDFREQ_CLASS
#define WORDFREQ_CLASS

#include <iostream>
#include <string>

// maintains a word and its frequency of occurrence
class wordFreq
{
	public:
		// initialize word and set freq to 1
		wordFreq(const string& str): word(str), freq(1)
		{}

		// add 1 to the frequency
		void increment()
		{ freq++; }

		// equality operator compares the word for the objects
		friend bool operator== (const wordFreq& lhs, const wordFreq& rhs)
		{ return lhs.word == rhs.word; }

		// less than operator compares the word for the objects
		friend bool operator< (const wordFreq& lhs, const wordFreq& rhs)
		{ return lhs.word < rhs.word; }

		// output an object in the format:  word (freq)
		friend ostream& operator<< (ostream& ostr, const wordFreq& w)
		{
			ostr << w.word << " (" << w.freq << ')';
			return ostr;
		}

	private:
		string word;
		// number of times word found
		int freq;
};

#endif	// WORDFREQ_CLASS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -