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

Popular posts from this blog

88: Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: // Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >= 70% : Grade C Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F

205: Book Catalog: Define a struct to represent a book with attributes like title, author, and publication year. Write a program to create a catalog of books by taking user input and display books published after a certain year.

15: Take input of age and name of 3 people by user and determine oldest and youngest among them with his age. -_-_-_-_-_-_-_-_-(line with spaces input concept)-_-_-_-_-_-_-_-_