homeworkhelp111

chara

Feb 5th, 2022 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cctype>
  5.  
  6. using namespace std;
  7.  
  8. int GetNumOfCharacters(const string usrStr) {
  9.     int count = 0;
  10.     for (int i = 0; i < usrStr.length(); i++) {
  11.         if (usrStr[i]!=' ' or usrStr[i]!='\t') {
  12.             count++;
  13.         }
  14.     }
  15.     return count;
  16. }
  17.  
  18. void OutputWithoutWhiteSpace(const string usrStr) {
  19.     cout << "String with no whitespace: ";
  20.     for (int i = 0; i < usrStr.length(); i++) {
  21.         if (usrStr[i] != ' ' and usrStr[i] != '\t') {
  22.             cout << usrStr[i];
  23.         }
  24.     }
  25. }
  26. int main() {
  27.     int count;
  28.     string usrStr;
  29.     cout << "Enter a sentence or phrase:"<<endl;
  30.     getline(cin, usrStr);
  31.  
  32.     cout << endl;
  33.     cout << "You entered: " << usrStr << endl;
  34.     cout << endl;
  35.     count = GetNumOfCharacters(usrStr);
  36.     cout << "Number of characters: " << count<<endl;
  37.     OutputWithoutWhiteSpace(usrStr);
  38.     cout<<endl;
  39.     return 0;
  40. }
Add Comment
Please, Sign In to add comment