Sie sind auf Seite 1von 3

Problem no.

4
ex.1
int main()
{
char x[10];
int n,i,s=0;
cout<<"Enter any string\n";
cin>>x;
n=strlen(x);
for(i=0;i<n;++i)
{
if(x[i]=='a'||x[i]=='e'||x[i]=='i'||x[i]=='o'||x[i]=='u')
{
s=s+1;
}
}
cout<<s;
return 0;
}

ex.2
int vowelcount (char[],int,int)
{
int vow_cnt=0;
for(int i=0;i<strlen[];i++)
{
if(name[i] == 'a' || name[i] == 'e'||name[i] == 'i'||name[i] == 'o'||name[i] ==
'u')
{
vow_cnt++;
return vow+cnt;
}

ex.3
#include<iostream>
using namespace std;

int main(){

int index = 0;
int vowel = 0;

while (blah[index] != '\0') {

switch (blah[index]) {
case 'a':
vowel++;
break;
case 'e':
vowel++;
break;
case 'i':
vowel++;
break;
case 'o':
vowel++;
break;
case 'u':
vowel++;
break;} index++;}

cout << "Number of vowels was " << vowel;

while (true) {}

return 0;}

ex.4
#include<iostream>
#include<cstring>
using namespace std;

int vCount ( char *);

int main(){

char word[80];
cout << "enter a line:";
cin.getline (word, 80);
cout << "vowel count: " << vCount(word) << endl;

return 0;
}

// returns the number of vowels in a char array

int vCount ( char * pCh){
int vowels = 0;

while(*pCh){
if(strspn(pCh, "aeiou"))
vowels++;
pCh++;
}

return vowels;
}

ex.5 (its like prob3)

#include<iostream>
#include<cstring>
using namespace std;
int main(){
char line[150];
int i,v,c,ch,d,s,o;
o=v=c=ch=d=s=0;
cout << "Enter a line of string: " << endl;
cin.getline(line, 150);
for(i=0;line[i]!='\0';++i)
{
if(line[i]=='a'
|| line[i]=='e'
|| line[i]=='i'
|| line[i]=='o'
|| line[i]=='u'
|| line[i]=='A'
|| line[i]=='E'
|| line[i]=='I'
|| line[i]=='O'
|| line[i]=='U')
++v;
else if((line[i]>='a'&& line[i]<='z')
|| (line[i]>='A'&& line[i]<='Z'))
++c;
else if(line[i]>='0'&&c<='9')
++d;
else if (line[i]==' ')
++s;
}
cout << " Vowels: " << v << endl;
cout << " Consonants: " << c << endl;
cout << " Digits: " << d << endl;
cout << " White Spaces: " << d << endl;
return 0;
}

ex.6
#include <iostream>
#include <string>

int vowels = 0;

if (str == "a") vowels++;

if (str == "e") vowels++;
if (str == "i") vowels++;
if (str == "o") vowels++;
if (str == "u") vowels++;
if (str == "A") vowels++;
if (str == "E") vowels++;
if (str == "I") vowels++;
if (str == "O") vowels++;
if (str == "U") vowels++;
return 0;
}
int main(void) {
string input;
while ( true ) {
cout << "Enter a string or Q to quit: ";
getline( cin, input );
count_vowel ( input);
if ( input == "Q" )
break;
cout << " This string has " << vowels << " vowels!";
}
return 0;
}