Question: Write a void function, called NumberOfWordsAndSentences, that, when given a string, will return the number of spaces AND the number of periods. For example, if
Write a void function, called NumberOfWordsAndSentences, that, when given a string, will return the number of spaces AND the number of periods. For example, if the function is given "We all live in a yellow submarine." , your function should find the number of spaces to be 6 and the number of periods to be 1. You may assume that the string can be very large.
Answer in C++
#include
//write your function here
int main() {
string userString; int numSpaces = 0; int numPeriods = 0; getline( cin, userString); NumberOfWordsAndSentences( userString, numSpaces, numPeriods);
cout << "The number of spaces is " << numSpaces << " and the number of periods is " << numPeriods << "." << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
