Advertisement
fvzy

C++ String Menampilkan Jumlah Kata

Dec 11th, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. /*
  2. Nama Program : Kalimat Spliter
  3. Dekripsi : Program untuk menentukan jumlah kata.
  4. Input : Kalimat
  5. Proses : Mengolah input kalimat
  6. Output : Menampilkan jumlah kata dalam sebuah kalimat
  7. Author : Ageung Hidayat
  8. NIM : TI111002
  9. */
  10.  
  11. #include<stdio.h>
  12. #include<iostream.h>
  13. #include<ctype.h>
  14.  
  15. void main()
  16. {
  17. /*Title*/
  18. cout<<"\t\t = = = = = = = = = = = = = = ="<<endl;
  19. cout<<"\t\t = | PROGRAM 1 | ="<<endl;
  20. cout<<"\t\t= MENAMPILKAN JUMLAH KATA ="<<endl;
  21. cout<<"\t\t = oleh : Ageung hidayat ="<<endl;
  22. cout<<"\t\t = = = = = = = = = = = = = = ="<<endl;
  23. cout<<"\n";
  24. char kalimat[100];
  25. int i, space=0;
  26. cout<<"Masukan Kalimat \t: ";
  27. cin.getline(kalimat, sizeof(kalimat));
  28. for(i=0; kalimat[i]; i++)
  29. {
  30. if(isspace (kalimat[i]) || ispunct (kalimat[i]))
  31. {
  32. space++;
  33. }
  34. }
  35.  
  36.  
  37. cout<<"\n";
  38. cout<<"Kalimat Diatas Terdiri Atas "<<space+1<<" Kata"<<endl;
  39. cout<<"\n"<<endl;
  40. cout<<"Keluaran Masing-Masing katanya adalah "<<endl;
  41. cout<<" ";
  42.  
  43.  
  44. for(i=0; kalimat[i]; i++)
  45. {
  46. if(isspace (kalimat[i]) || ispunct (kalimat[i]))
  47. {
  48. space++;
  49. cout<<""<<endl;
  50.  
  51. }
  52. cout<<kalimat[i];
  53. }
  54. cout<<""<<endl;
  55. getchar();
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement