Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string.h>
- using namespace std;
- class kalimat{
- private:
- string input;
- public:
- void setinput(string);
- string getinput();
- void menu();
- void mainmenu();
- void index();
- void masukkan();
- void append();
- void hapus(){
- int x,y;
- cout<<"input start index : ";
- cin>>x;
- cout<<"input count to erase :";
- cin>>y;
- input.erase(x,y);
- setinput(input);
- }
- void copy(){
- string z;
- int x,y;
- cout<<"input replace string : ";
- cin>>z;
- cout<<"input start index : ";
- cin>>x;
- cout<<"input count to replace : ";
- cin>>y;
- input.replace(x,y,z);
- setinput(input);
- }
- void sub(){
- int x,y;
- cout<<"input start index : ";
- cin>>x;
- cout<<"input count to replace : ";
- cin>>y;
- input.substr(x,y);
- setinput(input);
- }
- };
- void kalimat::setinput(string input){
- this->input = input;
- }
- string kalimat::getinput(){
- return input;
- }
- void kalimat::masukkan(){
- string kata;
- cout<<"input your string : ";
- getline(cin,kata);
- setinput(kata);
- }
- void kalimat::mainmenu(){
- cout<<"your string : "<<getinput()<<endl;
- cout<<"====================================="<<endl;
- cout<<"1. manipulate your string"<<endl;
- cout<<"2. view your string status"<<endl;
- cout<<"3. exit"<<endl;
- cout<<"input : ";
- }
- void kalimat::menu(){
- cout<<"your string : "<<getinput()<<endl;
- cout<<"====================================="<<endl;
- cout<<"1. append your string"<<endl;
- cout<<"2. erase your string"<<endl;
- cout<<"3. replace yout string"<<endl;
- cout<<"4. substring your string"<< endl;
- cout<<"5. back to main menu"<<endl;
- cout<<"input : ";
- }
- void kalimat::append(){
- string masuk,hasil;
- cout<<"input append string : ";
- cin>>masuk;
- hasil=getinput()+masuk;
- setinput(hasil);
- cout<<"your string after append : "<<getinput()<<endl;
- }
- int main(){
- int pilih;
- kalimat kalimat;
- kalimat.masukkan();
- do{
- kalimat.mainmenu();
- cin>>pilih;
- if(pilih==1){
- do{
- kalimat.menu();
- cin>>pilih;
- if(pilih==1){
- kalimat.append();
- }else if(pilih==2){
- kalimat.hapus();
- }else if(pilih==3){
- kalimat.copy();
- }else if(pilih==4){
- kalimat.sub();
- }else if(pilih==5){
- kalimat.mainmenu();
- }
- }while(pilih<1||pilih>5);
- }else if(pilih==2){
- cout<<"lol";
- }
- }while(pilih<1||pilih>3||pilih!=3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement