63 189
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #27923 in C++ for aseel

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

int main()
{

string sentence="";
getline(cin,sentence);//get sentence from keyboard


int countupperCaseLetters = 0;//variable for upperCaseLetters
int countlowerCaseLetters = 0;//variable lowerCaseLetters
int countwords = 1;
for(unsigned int i = 0; i < sentence.length(); i++)
{
if (sentence[i] >= 'A' && sentence[i] <= 'Z')
{
countupperCaseLetters++;//calculate count upper CaseLetters
}
else if (sentence[i] >= 'a' && sentence[i] <= 'z')
{
countlowerCaseLetters++;//caluclate count lower CaseLetters
}
else if (sentence[i] == ' ')
{
countwords++;//caluclate Total number of words:
}
}
int Totalnumberofletters=countupperCaseLetters + countlowerCaseLetters;
// Show result
cout << "Total number of words: " << countwords <<
endl;
cout << "Total number of letters: " <<
Totalnumberofletters << endl;
cout << "Total number of capital letters: " <<
countupperCaseLetters << endl;
cout << "Total number of small letters: " <<
countlowerCaseLetters << endl;
getch();//delay
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