Program to Find Vowels, Consonants, Words And Alphabets In C++



#include <iostream>

#include<string>

using namespace std;


int main()
{
int v = 0;
int other = 0;
int space = 0;
int alphabets = 0;
string s;
cout << "Enter a string of your choice: ";
getline(cin, s);
cout << s << endl;

for (int i = 0; i < s.length(); i++) {

if (s.at(i) == 'a' || s.at(i) == 'e' || s.at(i) == 'i' || s.at(i) == 'o' || s.at(i) == 'u' || s.at(i) == 'A' || s.at(i) == 'E' || s.at(i) == 'I' || s.at(i) == 'O' || s.at(i) == 'U' )

{

v++;

}

else if (s.at(i) == ' ') {

other++;

}

}

for (int i = 0; i < s.length(); i++) {

//checking with if condition string.

if (s.at(i) == ' ') {

space++;

}

}

for (int i = 0; i < s.length(); i++) {
if (s.at(i) != ' ') {

alphabets++;

}

}

cout << "Vowels are: " << v << endl;
cout << "Consonants are " << (s.length() - v - other) << endl;
cout << "Words are: " << (space + 1) << endl;
cout << "Alphabets are: " << alphabets << endl;

}

OUTPUT:



Comments