-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6week_10.cpp
52 lines (50 loc) · 1.09 KB
/
6week_10.cpp
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
#include <iostream>
#include <string>
using namespace std;
class Histogram{
string text;
public:
Histogram(){};
Histogram(string text) {
this->text = text;
}
void put(string text){
this->text.append(text);
}
void putc(char text){
this->text += text;
}
void print(){
cout << endl << endl;
int n[26] = { 0 };
cout << text << endl;
int len = 0;
for (int i = 0; i < text.length(); i++){
text[i] = tolower(text[i]);
if (text[i] >= 'a' && text[i] <= 'z')
len++;
}
cout << "ÃÑ ¾ËÆĺª ¼ö " << len << endl;
for (int i = 0; i < text.length(); i++){
for (char c = 'a'; c <= 'z'; c++){
if (text[i] == c){
n[(int)c - 97]++;
}
}
}
for (int i = 0; i < 26; i++){
cout << (char)(i + 97) << " (" << n[i] << ") : ";
for (int j = 0; j < n[i]; j++){
cout << '*';
}
cout << endl;
}
}
};
int main(){
Histogram elvisHisto("Wise men say, only fools rush in But I can't help, ");
elvisHisto.put("falling in love with you");
elvisHisto.putc('-');
elvisHisto.put("Elvis Presley");
elvisHisto.print();
}