/* Program for displaying whether the entered character is a digit or an arithmetic operator or small or capital letter. */ # include <iostream> # include <cmath> using namespace std; bool isDigit(char); bool isSmall(char); bool isCapital(char); bool isArithmeticOperator(char); int main() { char ch,character; //For Displaying Menu for (int i = 1; i <= 80; i++) cout << "_"; cout << "Menu:\nTo enter a Digit, press 'd' or 'D'.\nTo enter an Arithmetic Operator, press 'a' or 'A'.\n"; cout << "To enter a Small Letter, press 's' or 'S'.\nTo enter a Capital Letter, press 'c' or 'C'.\n"; cout << "To Exit, press 'e' or 'E'.\n"; for (int i = 1; i <= 80; i++) cout << "_"; cout << endl; //For Inputting choice do { cout << "Enter your Choice?"; cin >> ch; if (ch != 'a' && ch != 'A' && ch != 's' && ch != 'S' && ch != 'c' && ch != 'C' && ch != 'd' && ch != 'D' && ch != 'e' && ch != 'E') { cout << "Invalid Input.......\n"; } } while (ch != 'a' && ch != 'A' && ch != 's' && ch != 'S' && ch != 'c' && ch != 'C' && ch != 'd' && ch != 'D' && ch != 'e' && ch != 'E'); //For inputting Character if (ch!='e' && ch!='E') { cout << "Enter Character?\t"; cin >> character; } //For checking Entered Choice and display result switch (ch) { case 'd' : case 'D': if (isDigit(character)) cout << "Yes, Entered character is a Digit.\n"; else cout << "No, Entered character is not a Digit.\n"; break; case 'a' : case 'A': if (isArithmeticOperator(character)) cout << "Yes, Entered character is an Arithmetic Operator.\n"; else cout << "No, Entered character is not an Arithmetic Operator.\n"; break; case 's' : case 'S': if (isSmall(character)) cout << "Yes, Entered character is a Small Alphabet.\n"; else cout << "No, Entered character is not a Small Alphabet.\n"; break; case 'c' : case 'C': if (isCapital (character)) cout << "Yes, Entered character is a Capital Alphabet.\n"; else cout << "No, Entered character is not a Capital Alphabet.\n"; break; } return 0; } bool isDigit(char ch) { if (ch >= 48 && ch <= 57) return 1; else return 0; } bool isArithmeticOperator(char op) { if (op == '+' || op == '-' || op == '*' || op == '/' || op == '^') return 1; else return 0; } bool isSmall(char ch) { if (ch >= 97 && ch <= 122) return 1; else return 0; } bool isCapital(char ch) { if (ch >= 65 && ch <= 90) return 1; else return 0; }
OUTPUT-1
No comments:
Post a Comment