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 93
|
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
// I used the following as reference
//https://www.uow.edu.au/~lukes/TEXTBOOK/notes-cpp/io/readtextfile.html
//http://www.cplusplus.com/forum/general/12721/
//http://www.cplusplus.com/forum/general/5264/
using namespace std;
int main()
{
int a, e, i, o, u, A, E, I, O, U;
a = 0, e = 0, i = 0, o = 0, u = 0, A = 0, E = 0, I = 0, O = 0, U = 0; //vowels count set to zero
char str[3000];
int v;
v = 0;
ifstream inFile;
inFile.open(" File location goes here ");
if (!inFile)
{
cout << "Unable to open file";
exit(1); // terminate with error
}
while ((v[v++] = infile.get()) != EOF)a;
{ //while open
for (v = 0; str[v] != '\0'; v++)
switch (toupper(str[v]))
{ // case open
//Lowercase vowels
case 'a':
a += 1;
break;
case 'e':
e += 1;
break;
case 'i':
i += 1;
break;
case 'o':
o += 1;
break;
case 'u':
u += 1;
break;
//uppercase vowels
case 'A':
A += 1;
break;
case 'E':
E += 1;
break;
case 'I':
I += 1;
break;
case 'O':
O += 1;
break;
case 'U':
U += 1;
break;
} // case close
} //while close
//outpost
cout << "A= " << A << endl;
cout << "E= " << E << endl;
cout << "I= " << I << endl;
cout << "O= " << O << endl;
cout << "U= " << U << endl;
cout << "a= " << a << endl;
cout << "e= " << e << endl;
cout << "i= " << i << endl;
cout << "o= " << o << endl;
cout << "u= " << u << endl;
return 0;
}
| |