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

206: Write a program to create a class named "Circle" which has the property "radius". Define functions to calculate the area and circumference of the circle.

221: // In Task 2, we discussed multilevel inheritance with parameterized constructors for Student, UndergraduateStudent, and GraduateStudent classes in a university management system. Can you explain the advantages of using multilevel inheritance with specific details about the functions and data members in these classes? How were the parameterized constructors (e.g., setting student name, age, and ID) used to ensure that each class in the hierarchy correctly initializes its properties, such as creating an UndergraduateStudent named "John," aged 20, with a student ID of 12345

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