120: Write a program that takes a character as input and checks if it's an uppercase letter, lowercase letter, digit, or special character. If it's a letter, check if it's a vowel or a consonant. Display appropriate messages for each case. Make this program using user defined functions.
// Write a program that takes a character as input andchecks if it's an uppercase letter,
// lowercase letter,digit, or special character. If it's a letter, check if it'sa vowel or a consonant.
// Display appropriatemessages for each case.
#include <iostream>
using namespace std;
template <typename T>
T inum(string x);
void char_type(char x);
bool isVowel(char x);
int main()
{
char character = inum<char>("Enter a character: ");
char_type(character);
return 0;
}
template <typename T>
T inum(string x)
{
T y;
cout << x;
cin >> y;
return y;
}
void char_type(char x)
{
switch (x)
{
case 'A' ... 'Z':
if (isVowel(x))
{
cout << x << " is an Uppercase vowel digit\n";
}
else
{
cout << x << " is an Uppercase consonant digit\n";
}
break;
case 'a' ... 'z':
if (isVowel(x))
{
cout << x << " is a lowercase vowel letter\n";
}
else
{
cout << x << " is a lowercase consonant letter\n";
}
break;
case '0' ... '9':
cout << x << " is a digit\n";
break;
default:
cout << x << " is a special character; ";
break;
}
}
bool isVowel(char x)
{
switch (x)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
return true;
break;
default:
return false;
break;
}
}
Comments
Post a Comment