-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
271 lines (238 loc) · 11.2 KB
/
Copy pathmain.cpp
File metadata and controls
271 lines (238 loc) · 11.2 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include <iostream>
#include <string>
#include <vector>
#include "function.h"
using namespace std;
const string RED = "\033[31m";
const string GREAN = "\033[32m";
const string YELLOW = "\033[33m";
const string BLUE = "\033[34m";
const string MAGENTA = "\033[35m";
const string CYAN = "\033[36m";
const string Reset = "\033[0m";
int main()
{
char again;
do
{
int op;
string word;
vector<string> list =
{
"|--------------------------------------------------------|",
"| Program features |",
"|--------------------------------------------------------|",
"| [1] Manipulating texts. |",
"| [2] Reverse text. |",
"| [3] Substitute a letter in a word or a whole sentence. |",
"| [4] Swap a word from a group of words. |",
"| [5] Delete all space, right or left. |",
"| [6] Clean text. |",
"| [7] Zfill. |",
"| |",
"|________________________________________________________|"};
for (string v : list)
cout << CYAN << v << Reset << endl;
cout << YELLOW << "---------> Choose from the list <---------" << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> op;
cin.ignore();
system("cls");
if (op == 1)
{
int pick;
char answer;
vector<string> list =
{
"|-----------------------------------------------|",
"| Manipulating texts |",
"|-----------------------------------------------|",
"| [1] Convert text from small to capital |",
"| [2] Convert text from capital to small |",
"| [3] Switch from small to large and vice versa |",
"| |",
"|_______________________________________________|"};
for (string v : list)
{
cout << CYAN << v << Reset << endl;
}
cout << YELLOW << "---------> Choose from the list <---------" << Reset << endl;
do
{
cout << YELLOW << ": " << Reset;
cin >> pick;
cin.ignore();
if (pick < 1 || pick > 3)
{
cout << YELLOW << "Please choose from the list (1:3)" << Reset << endl;
}
} while (pick < 1 || pick > 3);
cout << RED << "Enter text" << Reset << endl;
cout << YELLOW << ": " << Reset;
getline(cin, word);
cout << RED << "Do you want to keep spaces between words (y/n)?" << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> answer;
bool keepSpace = (answer == 'y' || answer == 'Y');
if (pick == 1)
cout << RED << "[Result of To UpperCase]: " << Reset << GREAN << ChangeCase(word, pick, keepSpace) << Reset << endl;
else if (pick == 2)
cout << RED << "[Result of To LowerCase]: " << Reset << GREAN << ChangeCase(word, pick, keepSpace) << Reset << endl;
else if (pick == 3)
cout << RED << "[Result of To SwapCase]: " << Reset << GREAN << ChangeCase(word, pick, keepSpace) << Reset << endl;
}
else if (op == 2)
{
cout << RED << "Enter text" << Reset << endl;
cout << YELLOW << ": " << Reset;
getline(cin, word);
cout << RED << "[Result of To Revers]: " << Reset << GREAN << revers(word) << Reset << endl;
cout << YELLOW << "Successful operation" << Reset << endl;
}
else if (op == 3)
{
cout << RED << "Enter text" << Reset << endl;
cout << YELLOW << ": " << Reset;
getline(cin, word);
cout << MAGENTA << "text: " << word << Reset << endl;
char oldChar, newChar;
cout << RED << "Enter the character you want to modify." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> oldChar;
cout << RED << "Enter the new character." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> newChar;
cout << RED << "[Result]: " << Reset << GREAN << swapChar(word, oldChar, newChar) << Reset << endl;
}
else if (op == 4)
{
vector<string> words;
string text = "";
string replace, newWord;
int count = 1;
while (true)
{
cout << YELLOW << "#" << count << Reset << MAGENTA << " Enter the words you want to keep in a table." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> text;
if (text == "0")
break;
words.push_back(text);
count++;
}
cout << MAGENTA << "[ " << Reset;
for (string s : words)
{
cout << s << " " << ",";
}
cout << MAGENTA << " ]" << Reset << endl;
cout << RED << "Enter the word you want to change." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> replace;
cout << RED << "Enter the word you want to change." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> newWord;
swapWord(words, replace, newWord);
cout << MAGENTA << "[ " << Reset;
for (auto &v : words)
{
cout << v << ",";
}
cout << MAGENTA << " ]" << Reset << endl;
}
else if (op == 5)
{
// delet space all or right or left
char specialCh;
string Direction;
vector<string> lis =
{
"|------------------------------------|",
"| ----> Directions available <----- |",
"|------------------------------------|",
"| [1] RIGHT. |",
"| [2] LEFT. |",
"| [3] ALL. |",
"|____________________________________|"};
cout << RED << "Enter text" << Reset << endl;
cout << YELLOW << ": " << Reset;
getline(cin, word);
cout << RED << "Enter a special character that your sentence contains." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> specialCh;
cout << "\n";
for (string s : lis)
cout << CYAN << s << Reset << endl;
cout << YELLOW << "-----> Select the direction or direction number <-----" << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> Direction;
cout << RED << "[Result]: " << Reset << GREAN << trim(word, specialCh, Direction) << Reset << endl;
}
else if (op == 6)
{
char answerKeepSpace;
char Keepspecial = false;
char keep;
char specialCh = ' ';
cout << RED << "Enter text" << Reset << endl;
cout << YELLOW << ": " << Reset;
getline(cin, word);
cout << RED << "Do you want to keep something (y/n)?" << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> keep;
if (keep == 'y' || keep == 'Y')
{
Keepspecial = true;
cout << RED << "Enter the item you want to keep." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> specialCh;
}
else if (keep == 'n' || keep == 'N')
specialCh;
cout << RED << "Do you find it comfortable to keep distance (y/n)?" << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> answerKeepSpace;
bool keepSpace = (answerKeepSpace == 'y');
cout << RED << "[Result]: " << Reset << GREAN << cleanString(word, specialCh, keepSpace, Keepspecial) << Reset << endl;
}
else if (op == 7)
{
int width;
char fllCracter;
cout << RED << "Enter text." << Reset << endl;
cout << YELLOW << ": " << Reset;
getline(cin, word);
cout << RED << "Enter width number." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> width;
cout << RED << "Enter the thing you want to fill in the blanks." << Reset << endl;
cout << YELLOW << ": " << Reset;
cin >> fllCracter;
cout << RED << "[Result]: " << Reset << GREAN << Zfill(word, width, fllCracter) << Reset << endl;
}
else
{
cout << "Please select from the list (1:7)" << endl;
}
cout << "\nDo you want to do another operation (y/n) ?" << endl;
cout << ": ";
cin >> again;
system("cls");
} while (again == 'y' || again == 'Y');
cout << YELLOW << "|--------------------------------------------------------|" << Reset << endl;
cout << YELLOW << "| Program finished |" << Reset << endl;
cout << YELLOW << "|--------------------------------------------------------|" << Reset << endl;
cout << YELLOW << "| -- -- -- |" << Reset << endl;
cout << YELLOW << "| > Thank you for using the program! < |" << Reset << endl;
cout << YELLOW << "| --- - -- |" << Reset << endl;
cout << YELLOW << "| " << Reset << GREAN << "Created by Sa3dwy " << Reset << YELLOW << " |" << Reset << endl;
cout << YELLOW << "| " << Reset << MAGENTA << "LinkedIn: www.linkedin.com/in/amrsa3dwy " << Reset << YELLOW << " |" << Reset << endl;
cout << YELLOW << "| " << Reset << MAGENTA << "GitHub: www.linkedin.com/in/amrsa3dwy " << Reset << YELLOW << " |" << Reset << endl;
cout << YELLOW << "| " << Reset << MAGENTA << "Gmail: amrsaad0016a@gmail.om " << Reset << YELLOW << " |" << Reset << endl;
cout << YELLOW << "| " << Reset << MAGENTA << "All links: https://linktr.ee/sa3dwy " << Reset << YELLOW << " |" << Reset << endl;
cout << YELLOW << "| |" << Reset << endl;
cout << YELLOW << "| " << Reset << GREAN << "We wish you a productive and inspiring day! " << Reset << YELLOW << " |" << Reset << endl;
cout << YELLOW << "|________________________________________________________|" << Reset << endl;
ads();
return 0;
}