Abhijeet, a software programmer wants to create a program to check if the
character entered by user is a vowel or a consonant. Which type of loop he
should use? Explain the role of ‘==’operator and ‘||’ operator?
This is in C++
Answers
Answer:
In this example, if...else statement is used to check whether an alphabet entered by the user is a vowel or a constant.
To understand this example, you should have the knowledge of the following C++ programming topics:
C++ if, if...else and Nested if...else
Five alphabets a, e, i, o and u are known as vowels. All other alphabets except these 5 alphabets are known as consonants.
This program assumes that the user will always enter an alphabet.
Example: Check Vowel or a Consonant Manually
- see in photo
Output
The character entered by the user is stored in variable c.
The isLowerCaseVowel evaluates to true if c is a lowercase vowel and false for any other character.
Similarly, isUpperCaseVowel evaluates to true if c is an uppercase vowel and false for any other character.
If both isLowercaseVowel and isUppercaseVowel is true, the character entered is a vowel, if not the character is a consonant.
The isalpha() function checks whether the character entered is an alphabet or not. If it is not, it prints an error message.
- see in photo
Explanation:
I hope this helps for you
plz Mark me as brainliest
Explanation:
¤Five alphabets a, e, i, o and u are known as vowels. All other alphabets except these 5 alphabets are known as consonants.
¤This program assumes that the user will always enter an alphabet.
●include <iostream> using namespace std; int main() { char c; bool isLowercaseVowel, isUppercaseVowel; cout << "Enter an alphabet: "; cin >> c; // evaluates to 1 (true) if c is a lowercase vowel isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); // evaluates to 1 (true) if c is an uppercase vowel isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); // show error message if c is not an alphabet if (!isalpha(c)) printf("Error! Non-alphabetic character."); else if (isLowercaseVowel || isUppercaseVowel) cout << c << " is a vowel."; else cout << c << " is a consonant."; return 0;Get App
□C++ Program to Check Whether a character is Vowel or Consonant.
■In this example, if...else statement is used to check whether an alphabet entered by the user is a vowel or a constant.
■To understand this example, you should have the knowledge of the following C++ programming topics:
♧C++ if, if...else and Nested.
☆《Five alphabets a, e, i, o and u are known as vowels. All other alphabets except these 5 alphabets are known as consonants.
●This program assumes that the user will always enter an alphabet.》
♤Example: Check Vowel or a Consonant Manually#include <iostream> using namespace std; int main() { char c; bool isLowercaseVowel, isUppercaseVowel; cout << "Enter an alphabet: "; cin >> c; // evaluates to 1 (true) if c is a lowercase vowel isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); // evaluates to 1 (true) if c is an uppercase vowel isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U'); // show error message if c is not an alphabet if (!isalpha(c)) printf("Error! Non-alphabetic character."); else if (isLowercaseVowel || isUppercaseVowel) cout << c << " is a vowel."; else cout << c << " is a consonant."; return 0; }
¤Output
•Enter an alphabet: u u is a vowel.
•The character entered by the user is stored in variable c.
•The isLowerCaseVowel evaluates to true if c is a lowercase vowel and false for any other character.
•Similarly, isUpperCaseVowel evaluates to true if c is an uppercase vowel and false for any other character.
•If both isLowercaseVowel and isUppercaseVowel is true, the character entered is a vowel, if not the character is a consonant.
•The is alpha() function checks whether the character entered is an alphabet or not. If it is not, it prints an error message.