(2) Complete the GetNumOfSpaces() function, which returns the number of spaces in the user's string. (2 pts)
(3) In main(), call the GetNumOfSpaces() function and then output the returned result. (1 pt)
(4) Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for white spaces (spaces, tabs). Note: A tab is '\t'. Call the OutputWithoutWhitespace() function in main(). (2 pts)
#include <iostream>
#include <string>
usingnamespace std;
const string usrStr;
int result = 0;
//Returns the number of spaces in usrStr
int GetNumOfSpaces(const string usrStr) {
int i = 0;
for (i = 0; i < usrStr.length(); ++i) {
if (usrStr.at(i) == ' ') {
result = result + 1;
}
}
return result;
}
int main() {
const string usrStr;
cout << "Enter a sentence or phrase: " << endl;
getline (cin, usrStr);
cout << "You entered: " << usrStr << endl;
cout << GetNumOfSpaces(usrStr);
return 0;
}
main.cpp: In function 'int GetNumOfSpaces(std::string)':
main.cpp:9:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (i = 0; i < usrStr.length(); ++i) {