Bagosep

Manipulasi_string_header

Dec 9th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.79 KB | None | 0 0
  1. #ifndef BAGOSEP_H_INCLUDED
  2. #define BAGOSEP_H_INCLUDED
  3. #include <iostream>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. int banyak(char text[50]){
  9.     int banyak=0;
  10.     for(int kounter=0; text[kounter]!='\0'; kounter++)
  11.             {
  12.         if(text[kounter]>='A' && text[kounter]<='z' || text[kounter]==' ')          //strlen
  13.             {
  14.             banyak++;
  15.             }
  16.         }
  17.         return banyak;
  18.  
  19. }
  20. void salin (char text2[50], char text[50]){
  21.     int angka1;
  22.     for(int kounter=0; kounter<=angka1; kounter++)
  23.     {
  24.         text2[kounter]=text[kounter];                           //strcpy
  25.         if(text[kounter]=='\0'){
  26.             text2[kounter]='\0';
  27.         }
  28.     }
  29. }
  30. void salin2 (char text3[50], char text[50]){
  31.     int angka1;
  32.     for(int kounter=0; kounter<=angka1; kounter++)
  33.     {
  34.         text3[kounter]=text[kounter];                           //strcpy
  35.         if(text[kounter]=='\0'){
  36.             text3[kounter]='\0';
  37.         }
  38.     }
  39. }
  40. void balikperkata(char text[50]){
  41.     int kounter, i, j, kedua;
  42.     int pertama=0;
  43.     int angka1=banyak(text);
  44.     for(kounter=0; kounter<angka1; kounter++)
  45.     {
  46.             if(text[kounter]==' ' || kounter==angka1-1){
  47.                 kedua=kounter+1;                                           //Balik Per kata
  48.                 if(kounter==angka1-1){
  49.                     cout<<" ";
  50.                 }
  51.                 j=0;
  52.                 for(i=pertama; i<kedua; i++){
  53.                     cout<<text[kedua-1-j];
  54.                     j++;
  55.                     if(i==kedua-1){
  56.                         pertama=kounter+1;
  57.                     }
  58.                 }
  59.             }
  60.     }
  61.  
  62. }
  63. void balik(char text[100]){
  64.     int angka1=banyak(text);
  65.     for(int kounter=0; kounter<=angka1; kounter++)
  66.     {
  67.         if(text[kounter]=='\0'){
  68.             text[kounter]='\0';                            //strrev
  69.         }
  70.         cout<<text[angka1-kounter];
  71.     }
  72. }
  73. void besarSemua(char text[100]){
  74.     for(int kounter=0; text[kounter]!='\0'; kounter++)
  75.     {
  76.         if(text[kounter]>='A' && text[kounter]<='Z' || text[kounter]==' ')
  77.         {
  78.             cout<<text[kounter];                                                //Strupr
  79.         }
  80.         else if(text[kounter]>='a' && text[kounter]<='z')
  81.         {
  82.             text[kounter]=char(text[kounter]-32);
  83.             cout<<text[kounter];
  84.         }
  85.     }
  86. }
  87. void kecilSemua(char text[100]){
  88.     for(int kounter=0; text[kounter]!='\0'; kounter++)
  89.     {
  90.         if(text[kounter]>='A' && text[kounter]<='Z')
  91.         {
  92.             text[kounter]=char(text[kounter]+32);                               //Strlwr
  93.             cout<<text[kounter];
  94.         }
  95.         else if(text[kounter]>='a' && text[kounter]<='z' || text[kounter]==' ')
  96.         {
  97.             cout<<text[kounter];
  98.         }
  99.     }
  100. }
  101. int UcaseTotal(char text[100]){
  102.     int besar=0;
  103.     for(int kounter=0;text[kounter]!='\0';kounter++){
  104.         if (text[kounter]>='A' && text[kounter]<='Z'){
  105.             besar++;
  106.  
  107.         }else if(text[kounter]==' '){                                   //UcaseTotal
  108.             text[kounter]=' ';
  109.         }
  110.  
  111.     }
  112.     return besar;
  113. }
  114. int LcaseTotal(char text[100]){
  115.     int kecil=0;
  116.     for(int kounter=0;text[kounter]!='\0';kounter++){
  117.         if (text[kounter]>='A' && text[kounter]<='Z'){
  118.  
  119.         }else if(text[kounter]==' '){                                   //LcaseTotal
  120.             text[kounter]=' ';
  121.         }
  122.  
  123.         else{
  124.             kecil++;
  125.         }
  126.  
  127.     }
  128.     return kecil;
  129. }
  130. void HideVokal(char text[50]){
  131.     int angka1=banyak(text);
  132.     for(int kounter=0;kounter<angka1;kounter++){
  133.         if(text[kounter]=='A' || text[kounter]=='I' || text[kounter]=='U'||
  134.         text[kounter]=='E' || text[kounter]=='O'||text[kounter]=='a' || text[kounter]=='i' || text[kounter]=='u'||
  135.         text[kounter]=='e' || text[kounter]=='o'){                          //HideVokals
  136.                 text[kounter]=' ' ;
  137.             }
  138.         cout<<text[kounter];
  139.  
  140.     }
  141. }
  142. void HideKonsonan(char text[50]){
  143.     int angka1=banyak(text);
  144.     for(int kounter=0;kounter<angka1;kounter++){
  145.         if(text[kounter]=='A' || text[kounter]=='I' || text[kounter]=='U'||
  146.         text[kounter]=='E' || text[kounter]=='O'||text[kounter]=='a' || text[kounter]=='i' || text[kounter]=='u'||
  147.         text[kounter]=='e' || text[kounter]=='o'){                          //HideKonsonan
  148.             }
  149.         else {
  150.             text[kounter]=' ' ;
  151.         }
  152.         cout<<text[kounter];
  153.  
  154.     }
  155. }
  156. void hitungKata(char text[50]){
  157.     int angka1=banyak(text);
  158.     int angka=0;
  159.     for (int kounter=0;kounter<angka1;kounter++){
  160.             if(text[kounter]==' '){
  161.             angka++;
  162.             cout<<endl;                                                  //HitungBanyakKata
  163.             cout<<"Word # "<<angka+1<<" \t\t\t : ";}
  164.             else{
  165.                 cout<<text[kounter];
  166.             }
  167.         }
  168. }
  169. int totalVokal(char text[50]){
  170.     int vokal=0;
  171.     for(int kounter=0;text[kounter]!='\0';kounter++){
  172.         if(text[kounter]=='A' || text[kounter]=='I' || text[kounter]=='U'||
  173.         text[kounter]=='E' || text[kounter]=='O'||text[kounter]=='a' || text[kounter]=='i' || text[kounter]=='u'||
  174.         text[kounter]=='e' || text[kounter]=='o'){
  175.             vokal++;
  176.         }
  177.     }
  178.     return vokal;
  179. }
  180. int totalKonsonan(char text[50]){
  181.     int konsonan=0;
  182.     for(int kounter=0;text[kounter]!='\0';kounter++){
  183.         if(text[kounter]=='A' || text[kounter]=='I' || text[kounter]=='U'||
  184.         text[kounter]=='E' || text[kounter]=='O'||text[kounter]=='a' || text[kounter]=='i' || text[kounter]=='u'||
  185.         text[kounter]=='e' || text[kounter]=='o' || text[kounter]==' '){
  186.         }
  187.         else {
  188.             konsonan++;
  189.         }
  190.     }
  191.     return konsonan;
  192. }
  193. int totalSpasi(char text[50]){
  194.     int spas=0;
  195.     for(int kounter=0;text[kounter]!='\0';kounter++){
  196.         if(text[kounter]==' '){
  197.             spas++;
  198.         }
  199.  
  200.     }
  201.     return spas;
  202. }
  203. void textOffset(char text[50], int offset){
  204.     int ganti;
  205.     for(int kounter=0; text[kounter]!='\0'; kounter++){
  206.         if(text[kounter]==' '){
  207.             text[kounter]=' ';
  208.         }
  209.         else{
  210.             ganti=int(text[kounter])+offset;
  211.             if(text[kounter]>='a' && text[kounter]<='z'){
  212.                 if(ganti<97){
  213.                 ganti=ganti+26;
  214.             }
  215.                 else if(ganti>122){
  216.                     ganti=ganti-26;
  217.                 }
  218.             }
  219.             else if(text[kounter]>='A' && text[kounter]<='Z'){
  220.             if(ganti<65){
  221.                 ganti=ganti+26;
  222.             }
  223.             else if(ganti>90){
  224.                 ganti=ganti-26;
  225.             }
  226.         }
  227.             text[kounter]=char (ganti);
  228.         }
  229.     }
  230.     cout<<text;
  231. }
  232. #endif // BAGOSEP_H_INCLUDED
Add Comment
Please, Sign In to add comment