1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <iostream> #include <string> using namespace std; class Histogram { string histo; public: Histogram(string histo) { this->histo = histo; } Histogram& operator<<(string str); Histogram& operator<<(char c); void operator!(); }; Histogram& Histogram::operator<<(string str) { histo += str; return *this; } Histogram& Histogram::operator<<(char c) { histo += c; return *this; } void Histogram::operator!() { int len = 0; int abc[26] = { 0 }; for (int i = 0; i < histo.length(); i++) { cout << histo[i]; if (isalpha(histo[i])) { len++; for (int j = 0; j < 26; j++) { if ((char)(j + 97) == tolower(histo[i])) abc[j]++; } } } cout << "\n\n" << "총 알파벳 수 " << len << '\n'; for (int i = 0; i < 26; i++) { cout << (char)(i + 97) << ":"; for (int j = 0; j < abc[i]; j++) cout << "*"; cout << '\n'; } } int main() { Histogram song("Wise men say, \nonly fools rush in But I can't help, \n"); song << "falling" << " in love with you." << "- by "; song << 'k' << 'i' << 't'; !song; } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
| 명품 C++ Programming 실습문제 7장 2번 (0) | 2018.06.17 |
|---|---|
| 명품 C++ Programming 실습문제 7장 1번 (0) | 2018.06.17 |
| 명품 C++ Programming 실습문제 6장 8번 (0) | 2018.06.16 |
| 명품 C++ Programming 실습문제 6장 7번 (0) | 2018.05.26 |
| 명품 C++ Programming 실습문제 6장 6번 (0) | 2018.05.26 |