-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordCount.cpp
92 lines (92 loc) · 2.48 KB
/
WordCount.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char sentence[1000];
int k,len,words=0,vowels=0,conso=0;
cout<<"Enter a sentence: "<<endl;
gets(sentence);
do
{
cout<<"\nThe sentence you entered is: \n";
puts(sentence);
cout<<"\nEnter a choice: \n1. Count the Words in it\n2. Count the Vowels in it\n3. Count the Consonants in it\n0. Exit.\n";
cin>>k;
switch(k)
{
case 1:
{
len=strlen(sentence);
for(int i=0; i<=len; i++)
{
if((sentence[i]==' '&&sentence[i+1]!=' ')||sentence[i]=='\0')
words++;
}
cout<<"\nThis sentence has total "<<words<<" words."<<endl;
break;
}
case 2:
{
for(int i=0; i<strlen(sentence); i++)
{
char c = sentence[i];
if (isalpha(c))
{
switch(c)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
vowels++;
break;
}
}
}
cout<<"\nIn this sentence, there are total "<<vowels<<" vowels"<<endl;
break;
}
case 3:
{
for(int i=0; i<strlen(sentence); i++)
{
char c = sentence[i];
if (isalpha(c))
{
switch(c)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
break;
default:
conso++;
}
}
}
cout<<"\nIn this sentence, there are total "<<conso<<" consonants"<<endl;
break;
}
case 0:
cout<<"Twas good helping you!";
break;
default:
cout<<"Invalid Input!"<<endl;
}
}while(k!=0);
return 0;
}