基本的なC ++ 3.1タイトル

#include <iostreamの>
する#include <fstreamの>
する#include <ベクトル>
の#include <アルゴリズム>
の#include <マップ>
の#include <セット>

名前空間stdを使用。

//
//0.declare機能
無効Initialization_word(セット<文字列>&);
空make_map(constのセット<文字列>&、マップの<string、int型>&、&はifstream)。
空USER_QUERY(constのマップ<文字列、整数>&);
空display_word_count(constのマップ<文字列、整数>&、ofstreamの&);


INTメイン()
{
セット<ストリング> checkcharacter。
マップの<string、int型>単語数。

テキスト//1.enter
( "/ホーム/ zzm /デスクトップ/ test.txtの")in_fileはifstream。
ofstreamのo_file( "/ホーム/ zzm / otext.map");

もし(in_file || o_file!)
{CERR << "開いているファイルにできません-救済:\ n"は、
-1を返します。
}

Initialization_word(checkcharacter)。
make_map(checkcharacter、単語数、in_file)。
USER_QUERY(単語数)。
display_word_count(単語数、o_file)。
}


checkcharacterの//2.initialization。
ボイドInitialization_word(集合<ストリング>&check_word)
{
、静的文字列Excludecharacter [25] = { ""、 "および"、 "しかし"、 "その"、 "次に"、 "ある"、 "き"、 "CAN" 「」、、、、「彼」、「彼女」、「その」、「ある」、「、「持っている」「彼を」「持っていた」「の」、「のために」、「やった」「可能性」でした」、 "whice"、 "いつ"、 "有する"、 "だろう"}。

check_word.insert(Excludecharacter、Excludecharacter + 25);}

//3.makeマップ

ボイドmake_map(CONSTセット<ストリング>&check_map、地図<文字列、整数>&単語数、はifstream&in_file)
{
文字列ワード;
(in_file >>ワード)一方、
{
(check_map.count(ワード))もし
続けます。
単語数[単語] ++;
}
}

//4.display
ボイドUSER_QUERY(CONSTマップ<文字列、整数>&word_map)
{
文字列search_word。
裁判所未満<<「検索する単語を入力してください:Qを終了します」。
cinを>> search_word。

しばらく(search_word = "Q" && search_word.size()!)
{
マップ<文字列、整数> :: const_iteratorのそれを。
もし((それは= word_map.find(search_word))!= word_map.end())
{coutの<< "発見!" << IT->最初
<< <<その"発生" - >第二
<< "回\ n";}
他{COUT << search_word
<< "テキストで見つかりませんでした\ n";}
COUT << "\ nAnother検索(Qを終了します)?"。
cinを>> search_word。

 

//5.display単語数

ボイドdisplay_word_count(CONSTマップ<文字列、整数>&word_map、ofstreamの&OS)
{
マップ<文字列、整数> :: const_iteratorのITER = word_map.begin()、end_it = word_map.end()。
一方、(!ITER = end_it)
{OS << iter->第<< "("
<< iter->第<< ")"
<< ENDL。
++ ITER;}
OS << ENDL。
}

C ++は、学校のプログラムのテーマ3.1後冊、Linuxで実行されています。

おすすめ

転載: www.cnblogs.com/zzm1/p/12170308.html