Program takes a string and calculates the number of vowels, digits and white spaces

Calculates the Number of Vowels, Digits and White Spaces

Write program takes a string object from the user and calculates the number of vowels, digits and white-spaces

Object: Write a Program takes a string and calculates the number of vowels, digits and white spaces. C++ projects for beginners with source code

Code:

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
string tex;
int i,vol,dig,whtsp;
vol=dig=whtsp=0;
cout<<“Writer any string: “;
getline(cin,tex);
for(i=0;tex[i]!=’\0′;i++)
{
if(tex[i]==’a’||tex[i]==’e’||tex[i]==’i’||tex[i]==’o’||tex[i]==’u’||tex[i]==’A’||tex[i]==’E’||tex[i]==’O’||tex[i]==’U’)
{
vol++;
}
else if(tex[i]>=’0’&&tex[i]<=’9′)
{
dig++;
}
else if(tex[i]==’ ‘)
{
whtsp++;
}
}
cout<<“Vowels in this string: “<<vol<<endl;
cout<<“\nDigits in this string: “<<dig;
cout<<“\nWhite-Spaces in this string: “<<whtsp;
getch();
}

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
	string tex;
	int i,vol,dig,whtsp;
	vol=dig=whtsp=0;
	cout<<"Writer any string: ";
	getline(cin,tex);
	for(i=0;tex[i]!='\0';i++)
	{
		if(tex[i]=='a'||tex[i]=='e'||tex[i]=='i'||tex[i]=='o'||tex[i]=='u'||tex[i]=='A'||tex[i]=='E'||tex[i]=='O'||tex[i]=='U')
		{
			vol++;
		}
		else if(tex[i]>='0'&&tex[i]<='9')
		{
			dig++;
		}
		else if(tex[i]==' ')
		{
			whtsp++;
		}
	}
	cout<<"Vowels in this string: "<<vol<<endl;
	cout<<"\nDigits in this string: "<<dig;
	cout<<"\nWhite-Spaces in this string: "<<whtsp;
	getch();
}

Output:

Program takes a string and calculates the number of vowels, digits and white spaces

 

4 thoughts on “Program takes a string and calculates the number of vowels, digits and white spaces”

  1. Pingback: C++ projects for beginners with source code - Codeboks

  2. sql interview questions

    We are a group of volunteers and opening a new scheme in our community.
    Your web site offered us with valuable info to work on. You’ve done an impressive job and our entire
    the community will be grateful to you.

  3. Pingback: Top 40 projects with C++ for beginners in 2021

Leave a Comment

Your email address will not be published.