Write c++ Program that will input a sentence ended with dot, then count number of words, & number of small letters.
1
Expert's answer
2013-05-01T12:09:34-0400
#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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment