Typing diary
명품 c++ programming 4장 10번 본문
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 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <iostream> #include <string> using namespace std; class Histogram { string sentence; int isAlphaCount = 0; int AlphaCount[26] = { 0 }; public: Histogram(string sentence) { this->sentence = sentence; this->sentence += '\n'; } void put(string sentence); void putc(char c); void print(); }; void Histogram::put(string sentence) { this->sentence += sentence; } void Histogram::putc(char c) { this->sentence += c; } void Histogram::print() { cout << sentence << endl << endl; for (int i = 0; i < sentence.length(); i++) { if (isalpha(sentence.at(i))) { isAlphaCount++; if (65 <= sentence.at(i) && sentence.at(i) <= 90) { sentence.at(i) -= 32; } AlphaCount[sentence.at(i) - 97]++; } } cout << "총 알파벳 수 " << isAlphaCount << endl << endl; for (int i = 0; i < 26; i++) { cout << (char)(i + 97) << '(' << AlphaCount[i] << ") "; for (int j = 0; j < AlphaCount[i]; j++) cout << '*'; cout << endl; } } int main() { Histogram elvisHisto("Wise men say, only fools ruch in But I can't help, "); elvisHisto.put("falling in love with you"); elvisHisto.putc('-'); elvisHisto.put("Elvis Presley"); elvisHisto.print(); } | cs |
'C, C++' 카테고리의 다른 글
명품 c++ programming 6장 8번 (0) | 2022.08.16 |
---|---|
명품 c++ programming 7장 Open Challenge (0) | 2022.08.16 |
c++ 참조 (0) | 2022.08.16 |
c++ 복사 생성자 (0) | 2022.08.16 |
c++ 메모리 동적할당 초기화, 메모리 누수 (0) | 2022.08.16 |