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:
Pingback: C++ projects for beginners with source code - Codeboks
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.
Great information. Lucky me I came across your site by chance.
I have saved it for later!
Pingback: Top 40 projects with C++ for beginners in 2021