C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.

Leave a Comment
/* The  following C / C++ Program will count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph. User has to just enter the words/sentence/paragraph */

//CODE:-
#include<iostream>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int main()
{
const int maxlength = 1000;
char text[maxlength] = {0};
cout<<"Enter few words:\n\n";
cin.getline(text,maxlength);
cout<<"You Have Entered:\n"<<text<<endl;
int space=0;
int vow=0;
int consonants=0;
int special=0;
int ucase=0;
int lcase=0;
int intr=0;
int line=0;
for(int i = 0 ; text[i] != '\0' ; i++)
{
if(isalpha(text[i]))
{
if(text[i]>=65 && text[i]<=90)
{
ucase++;
}
else if(text[i]>=97 && text[i]<=122)
{
lcase++;
}
switch(tolower(text[i]))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
vow++;
break;
default:
consonants++;
break;
}}
else if(text[i]==' ')
{
space++;
}
else if((text[i]>=0&&text[i]<=47)||(text[i]>=58&&text[i]<=64)||(text[i]>=91&&text[i]<=96)||(text[i]>=123&&text[i]<=127))
{
special++;
}
else if(text[i]>=48 && text[i]<=57)
{
intr++;
}
else if(text[i]=='\n')
{
line++;
}
}
cout<<"No. of vowels="<<vow<<endl;
cout<<"No. of consonants="<<consonants<<endl;
cout<<"No. of spaces="<<space<<endl;
cout<<"No. of words="<<space+1<<endl;
cout<<"No. of special letters="<<special<<endl;
cout<<"No. of upper case letters="<<ucase<<endl;
cout<<"No. of lower case letters="<<lcase<<endl;
cout<<"No. of integers="<<intr<<endl;
cout<<"No. of lines="<<line;
system("pause");
return 0;
}


Screenshots:
C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.
C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.

0 comments: