Advertisement
Guest User

Untitled

a guest
May 20th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. using namespace std;
  4.  
  5. class kalimat{
  6. private:
  7. string input;
  8. public:
  9. void setinput(string);
  10. string getinput();
  11. void menu();
  12. void mainmenu();
  13. void index();
  14. void masukkan();
  15. void append();
  16. void hapus(){
  17. int x,y;
  18.  
  19.  
  20. cout<<"input start index : ";
  21. cin>>x;
  22.  
  23. cout<<"input count to erase :";
  24. cin>>y;
  25.  
  26. input.erase(x,y);
  27. setinput(input);
  28.  
  29. }
  30. void copy(){
  31. string z;
  32. int x,y;
  33.  
  34. cout<<"input replace string : ";
  35. cin>>z;
  36.  
  37. cout<<"input start index : ";
  38. cin>>x;
  39.  
  40. cout<<"input count to replace : ";
  41. cin>>y;
  42.  
  43. input.replace(x,y,z);
  44. setinput(input);
  45. }
  46.  
  47. void sub(){
  48. int x,y;
  49.  
  50. cout<<"input start index : ";
  51. cin>>x;
  52.  
  53. cout<<"input count to replace : ";
  54. cin>>y;
  55.  
  56. input.substr(x,y);
  57. setinput(input);
  58. }
  59. };
  60.  
  61. void kalimat::setinput(string input){
  62. this->input = input;
  63. }
  64.  
  65. string kalimat::getinput(){
  66. return input;
  67. }
  68.  
  69. void kalimat::masukkan(){
  70. string kata;
  71. cout<<"input your string : ";
  72. getline(cin,kata);
  73. setinput(kata);
  74. }
  75.  
  76. void kalimat::mainmenu(){
  77. cout<<"your string : "<<getinput()<<endl;
  78. cout<<"====================================="<<endl;
  79. cout<<"1. manipulate your string"<<endl;
  80. cout<<"2. view your string status"<<endl;
  81. cout<<"3. exit"<<endl;
  82. cout<<"input : ";
  83. }
  84.  
  85. void kalimat::menu(){
  86. cout<<"your string : "<<getinput()<<endl;
  87. cout<<"====================================="<<endl;
  88. cout<<"1. append your string"<<endl;
  89. cout<<"2. erase your string"<<endl;
  90. cout<<"3. replace yout string"<<endl;
  91. cout<<"4. substring your string"<< endl;
  92. cout<<"5. back to main menu"<<endl;
  93. cout<<"input : ";
  94. }
  95.  
  96. void kalimat::append(){
  97. string masuk,hasil;
  98. cout<<"input append string : ";
  99. cin>>masuk;
  100. hasil=getinput()+masuk;
  101. setinput(hasil);
  102. cout<<"your string after append : "<<getinput()<<endl;
  103. }
  104.  
  105.  
  106. int main(){
  107. int pilih;
  108. kalimat kalimat;
  109.  
  110. kalimat.masukkan();
  111. do{
  112. kalimat.mainmenu();
  113. cin>>pilih;
  114. if(pilih==1){
  115. do{
  116. kalimat.menu();
  117. cin>>pilih;
  118. if(pilih==1){
  119. kalimat.append();
  120. }else if(pilih==2){
  121. kalimat.hapus();
  122. }else if(pilih==3){
  123. kalimat.copy();
  124. }else if(pilih==4){
  125. kalimat.sub();
  126. }else if(pilih==5){
  127. kalimat.mainmenu();
  128. }
  129. }while(pilih<1||pilih>5);
  130. }else if(pilih==2){
  131. cout<<"lol";
  132. }
  133. }while(pilih<1||pilih>3||pilih!=3);
  134.  
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement