Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cctype>
  4. using namespace std;
  5.  
  6. void swap(char& v1, char & v2);
  7. //Interchanges the value of v1 and v2
  8.  
  9. string remove(const string& s);
  10. //Return a copy of s but with extra whitespace removed.
  11.  
  12. string maeUpper(const string &s);
  13. //Return a copy of s that has all lowercase
  14. // charachters change to uppercase, with other characters unchanged.
  15.  
  16. int main()
  17. {
  18. string str;
  19. cout << "Please enter a sentances to be correcter\n"
  20. << "followed by pressing Return.\n";
  21. getline(cin, str);
  22. system("pause");
  23. return 0;
  24. }
  25.  
  26. void swap(char & v1, char& v2)
  27. {
  28. char temp = v1;
  29. v1 = v2;
  30. v2 = temp;
  31.  
  32. }
  33.  
  34. string remove(const string& s)
  35. {
  36. int start = 0;
  37. int end = s.length();
  38. string temp(s);
  39. {
  40. end--;
  41. swap(temp[start], temp[end]);
  42. }
  43. return temp;
  44. }
  45.  
  46. //Uses <cctype> and <string>
  47. string makeUpper(const string &s)
  48. {
  49. string temp(s);
  50. for (int i = 0; i < s.length();i++)
  51. temp[i] = toupper(s[i]);
  52. return temp;
  53. }
  54.  
  55.  
  56. string remove(const string& s, const string punct)
  57. {
  58. string noPunct; //Initialize to empty string
  59. int sLenght = s.length();
  60. int punctLenght = punct.length();
  61. for (int i = 0; i < sLenght;i++)
  62. {
  63. string aChar = s.substr(i, 1); // A one-charachter string
  64. int location = punct.find(aChar, 0);
  65.  
  66. //Find location of successive charcters
  67. //of src in punct.
  68.  
  69. if (location < 0 || location >= punctLenght)
  70. noPunct = noPunct + aChar; //aChar is not in punct, so keep it
  71. }
  72. return noPunct;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement