63 063
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #27931 in C++ for aseel

Question #27931
Write c++ Program that will input a sentence ended with dot, then count number of words, & number of small letters.
Expert's answer
#include <iostream>
#include <string>
using namespace std;



int main() {
string s;
do {
cout << "Input sentence ended with dot" << endl;
getline(cin,s);
} while (s[s.length()-1] != '.'); // intput sentence while don't ended with dot
int count_small_letters = 0;
for (int i = 0; i < s.length(); i++) { //counting small letters
if (s[i] >= 'a' && s[i] <= 'z')
count_small_letters++;
}
int count_words = 0;
bool new_word = true;
for (int i = 0; i < s.length();i++) {
if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) { // is letter
if (new_word) {
count_words++; & //counting new words
new_word = false; //counting only first letters of the words
}
}
else new_word = true; //symbols between words shows that next letter will begin new word
}
cout<< count_words << " words in sentence." << endl;
cout<< count_small_letters << " small letters in sentence." << endl;
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions