-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWord.h
114 lines (79 loc) · 2.04 KB
/
Word.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef MAIN_WORD_H
#define MAIN_WORD_H
class Word {
public:
Word() {}
Word(std::string text) {
int i = 0;
while ((int)text[i] != 0) {
if (!std::ispunct(text[i]) && !std::isdigit(text[i])) {
this->value += text[i];
this->size++;
}
i++;
}
}
std::string getValue() {
return this->value;
}
int getSize() {
return this->size;
}
bool isLastLetterVowel() {
return this->isVowel(this->value[this->size - 1]);
}
float lettersRatio() {
float vowels = 1, consonants = 1;
for (int i = 0; i < this->size; i++) {
if (this->isVowel(this->value[i])) {
vowels++;
} else {
consonants++;
}
}
return consonants / vowels;
}
Word& operator = (Word& newWord) {
//проверка на самоприсваивание
if (this == &newWord) {
return *this;
}
this->value = newWord.getValue();
this->size = newWord.getSize();
return *this;
}
bool operator > (Word& right) {
float firstRatio = this->lettersRatio(), secondRatio = right.lettersRatio();
if (firstRatio == secondRatio) {
int i = 0;
while (this->value[i] != 0 && right.value[i] != 0) {
if ((int)tolower(this->value[i]) != (int)tolower(right.value[i])) {
return (int)tolower(this->value[i]) > (int)tolower(right.value[i]);
}
i++;
}
return false;
}
return firstRatio > secondRatio;
}
private:
// раскомментить, если надо с русскими буквами
// const char russianVowels[41] = "АУОЫИЭЯЮЁЕауоыиэяюёе";
const char vowels[6] = "aeiou";
int size = 0;
std::string value;
bool isVowel(char letter) {
letter = tolower(letter);
for (int i = 0; i < strlen(this->vowels); i++) {
if (letter == this->vowels[i]) {
return true;
}
}
// раскомментить, если надо с русскими буквами
// for (char p: this->russianVowels) {
// if (this->value[this->size - 2] == p) return true;
// }
return false;
}
};
#endif //MAIN_WORD_H