Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. //--------------------------------------------------------------------------------------//
  2. // APSC 177 Assignment 7
  3. // Date:
  4. // Name:
  5. // Student ID Number:
  6. // Brief Description:
  7. //--------------------------------------------------------------------------------------//
  8. #include <iostream>
  9. #include <string>
  10.  
  11. using namespace std;
  12.  
  13. int main ()
  14. {
  15. int voweltally, contally, uppertally, lowertally, punctally, wordtally;
  16. string text;
  17. int i;
  18.  
  19. cout << "Enter some text. Letters and the following punctuation only please . , : ; ! ?" << endl;
  20. cout << "Pressing enter/return will end the text." << endl;
  21. getline (cin, text);
  22.  
  23. //------------------------------------------------------------------------------------------------------------------------------------------------//
  24.  
  25. for( i = 0; i < text.length(); i++)
  26. {
  27. if( text[i]=='a' || text[i]=='A' || text[i]=='e' || text[i]=='E' || text[i]=='i'
  28. || text[i]=='I' || text[i]=='o' || text[i]=='O' || text[i]=='u' || text[i]=='U')
  29. voweltally++;
  30.  
  31. else if((text[i] >= 'b' && text[i] <= 'z') || (text[i] >= 'B' && text[i] <= 'Z'))
  32. contally++;
  33. }
  34.  
  35. //------------------------------------------------------------------------------------------------------------------------------------------------//
  36.  
  37. for( i = 0; i < text.length(); ++i)
  38. {
  39. if(text[i] >= 'a' && text[i] <= 'z')
  40. lowertally++;
  41.  
  42. else if(text[i] >= 'A' && text[i] <= 'Z')
  43. uppertally++;
  44. }
  45.  
  46. //------------------------------------------------------------------------------------------------------------------------------------------------//
  47.  
  48. for( i = 0; i < text.length(); i++)
  49.  
  50. if(text[i] == '.' || text[i] == ',' || text[i] == ':' || text[i] == ';' || text[i] == '!' || text[i] == '?')
  51. punctally++;
  52.  
  53.  
  54. //------------------------------------------------------------------------------------------------------------------------------------------------//
  55.  
  56. for( i = 0; i < text.length(); i++)
  57.  
  58. if(text[i] == ' ' && text[i-1] != ' ')
  59. wordtally++;
  60.  
  61. //------------------------------------------------------------------------------------------------------------------------------------------------//
  62.  
  63. cout << "The number of vowels is: " << voweltally << endl;
  64. cout << "The number of consonants is: " << contally << endl;
  65. cout << "The number of uppercase letters is: " << uppertally << endl;
  66. cout << "The number of lowercase letters is: " << lowertally << endl;
  67. cout << "The number of punctuation characters is: " << punctally << endl;
  68. cout << "The number of words is: " << wordtally << endl;
  69. cout << "Exiting program ..." << endl;
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement