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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int* vowCounter(string, int);
int* conCounter(string, int);
int main()
{
//Definition of str, as well as the menu display
string str,
a = "A) Count the number of vowels",
b = "B) Count the number of consonants",
c = "C) Count both the vowels and consonants",
d = "D) Enter another string instead",
e = "E) Exit the program";
char choice;
int vowelC = 0;
int consonC = 0;
int* vptr = 0;
int* cptr = 0;
do
{
cout << endl;
cout << "Enter a string: ";
cin >> str;
cout << endl;
cout << "What do you wish to do in the string? " << endl;
cout << a << endl;
cout << b << endl;
cout << c << endl;
cout << d << endl;
cout << e << endl;
cin >> choice;
{
switch (toupper(choice))
{
case 'A':
{
cout << *vptr;
cout << endl;
break;
}
case 'B':
{
cout << *cptr;
cout << endl;
break;
}
case 'C':
{
cout << *vptr;
cout << endl;
cout << *cptr;
cout << endl;
break;
}
case 'D':
{
continue;
break;
}
case 'E':
{
cout << "Exiting the program....." << endl;
break;
}
default:
{
cout << "Input is invalid, try again. ";
cout << endl;
break;
}
}
}
} while (toupper(choice) != 'E');
return 0;
}
int* vowCounter(string str, int vowelC)
{
int* vptr = new int[vowelC];
for (int i = 0; i < str.length(); i++)
{
int temp = toupper(str[i]);
if (temp == 'A', 'E', 'I', 'O', 'U')
{
vowelC++;
}
else
{
cout << "There are no vowels. " << endl;
}
}
return vptr;
}
int* conCounter(string str, int consonC)
{
int* cptr = new int[consonC];
for (int i = 0; i < str.length(); i++)
{
int temp = toupper(str[i]);
if (temp != 'A', 'E', 'I', 'O', 'U')
{
consonC++;
}
else
{
cout << "There are no consonants. " << endl;
}
}
cout << "Total consonants are " << consonC << endl;
return cptr;
}
|