-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanipulate.cpp
More file actions
187 lines (166 loc) · 3.78 KB
/
manipulate.cpp
File metadata and controls
187 lines (166 loc) · 3.78 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
#include <iostream>
#include <string>
using namespace std;
class tulisan{
private :
string kata;
public :
void set(string masuk){
this->kata=masuk;
}
string get(){
return this->kata;
}
};
tulisan ku;
void masuk(){
string in;
do{
cout<<"Input your string : ";
getline(cin,in);
}while(in.length()==0);
ku.set(in);
};
void cetak(){
cout<<"Your String : ";
cout<<ku.get();
cout<<endl;
};
void tambah(){
string in,temp;
temp=ku.get();
cout<<"Input append string : ";
getchar();
getline(cin,in);
temp.append(in);
ku.set(temp);
cout<<"Your string after append : ";
cout<<ku.get();
};
void hapus(){
int posisi,hapus;
string temp;
temp=ku.get();
do{
cout<<"Input start index [0..";
cout<<temp.length();
cout<<"] : ";
cin>>posisi;
}while(posisi<0||posisi>temp.length());
do{
cout<<"Input count to erase [1..";
cout<<(temp.length()-posisi);
cout<<"] : ";
cin>>hapus;
}while(hapus<1||hapus>(temp.length()-posisi));
temp.erase(posisi,hapus);
ku.set(temp);
cout<<"Your string after erase : ";
cout<<ku.get();
};
void ganti(){
int posisi,ganti;
string temp,in;
temp=ku.get();
cout<<"Input string to replace : ";
getchar();
getline(cin,in);
do{
cout<<"Input start index [0..";
cout<<temp.length();
cout<<"] : ";
cin>>posisi;
}while(posisi<0||posisi>temp.length());
do{
cout<<"Input count to replace [1..";
cout<<(temp.length()-posisi);
cout<<"] : ";
cin>>ganti;
}while(ganti<1||ganti>(temp.length()-posisi));
temp.replace(posisi,ganti,in);
ku.set(temp);
cout<<"Your string after replace : ";
cout<<ku.get();
};
void cabut(){
int posisi,cabut;
string temp;
temp=ku.get();
do{
cout<<"Input start index [0..";
cout<<temp.length();
cout<<"] : ";
cin>>posisi;
}while(posisi<0||posisi>temp.length());
do{
cout<<"Input count to substring [1..";
cout<<(temp.length()-posisi);
cout<<"] : ";
cin>>cabut;
}while(cabut<1||cabut>(temp.length()-posisi));
temp=temp.substr(posisi,cabut);
ku.set(temp);
cout<<"Your string after substring : ";
cout<<ku.get();
};
int jumlahkata(string hitung){
int jumlah=1;
for(int i=0;i<hitung.length();i++){
if(hitung[i]==' '){
jumlah++;
}
}
return jumlah;
}
void menu1(){
cout<<"======================================="<<endl;
cout<<"1. Manipulate your string"<<endl;
cout<<"2. View your string status"<<endl;
cout<<"3. Exit"<<endl;
cout<<"Choose : ";
};
void menu2(){
cout<<"======================================="<<endl;
cout<<"1. Append your string"<<endl;
cout<<"2. Erase your string"<<endl;
cout<<"3. Replace your string"<<endl;
cout<<"4. Substring your string"<<endl;
cout<<"5. Back to Main Menu"<<endl;
cout<<"Choose : ";
};
int main(){
int choice;
masuk();
do{
system("cls");
cetak();
menu1();
cin>>choice;
switch(choice){
case 1 : do{
system("cls");
cetak();
menu2();
cin>>choice;
switch(choice){
case 1 : tambah(); getchar();break;
case 2 : hapus(); getchar();getchar();break;
case 3 : ganti(); getchar();getchar();break;
case 4 : cabut(); getchar();getchar();break;
}
}while(choice!=5); break;
case 2 : system("cls");
cetak();
cout<<"Length size : ";
cout<<ku.get().length()<<endl;
cout<<"Capacity : ";
cout<<ku.get().capacity()<<endl;
cout<<"Amount of Words : ";
cout<<jumlahkata(ku.get())<<endl;
cout<<"Press Enter to Back Main Menu ...";
getchar();getchar();break;
case 3 : cout<<"=-= Open Our Vision and Encourage Ourself =-=";
getchar();getchar();break;
}
}while(choice!=3);
}