INSTRUCTIONS Write a program that prompts the user to enter a single keystroke a
ID: 3620596 • Letter: I
Question
INSTRUCTIONSWrite a program that prompts the user to enter a single keystroke and stores the character pressed in a ‘char’ variable. The program then processes the keystroke and determines if the keystroke was a letter, numeral, or symbol. If the keystroke was a letter, display a message indicating whether the letter is a vowel or consonant. If the character is a numeral, information about whether the numeral is even or odd is displayed. If the character is a symbol, information is displayed indicating whether the symbol is found in the lower ASCII table (7 bit representations) or the upper ASCII table (8 bit representations).
Your program should make use of #define codes to classify the keystroke. Your program should contain at least one instance of an IF, IF-ELSE, IF-ELSE-CHAIN, and SWITCH-CASE structure. Use the following shell to start your program:
#include <stdio.h>
#ifndef __CHARCODES__
#define __CHARCODES__
// type codes
#define LETTER 1
#define NUMBER 2
#define SYMBOL 3
// sub-type codes
#define VOWEL 4
#define CONSONANT 5
#define ODD 6
#define EVEN 7
#define UPPER_ASCII 8
#define LOWER_ASCII 9
#endif
int main() {
char keyStroke = 0;
int typeCode = -1, subTypeCode = -1;
// GET THE KEYSTROKE (remember to clean phantoms)
// ANALYZE THE KEYSTROKE (IF, IF-ELSE, IF-ELSE-CHAIN here)
// DISPLAY RESULTS BASED ON SET CODES (SWITCH-CASE)
return 0;
}
Explanation / Answer
please rate - thanks #include <stdio.h>#ifndef __CHARCODES__
#define __CHARCODES__
// type codes
#define LETTER 1
#define NUMBER 2
#define SYMBOL 3
// sub-type codes
#define VOWEL 4
#define CONSONANT 5
#define ODD 6
#define EVEN 7
#define UPPER_ASCII 8
#define LOWER_ASCII 9
#endif
int main() {
char keyStroke = 0;
int typeCode = -1, subTypeCode = -1;
// GET THE KEYSTROKE (remember to clean phantoms)
printf("Enter a character: ");
keyStroke=getchar();
while (( getchar()) != ' ' );
// ANALYZE THE keyStroke (IF, IF-ELSE, IF-ELSE-CHAIN here)
if(keyStroke>='0'&&keyStroke<='9')
{typeCode=2;
if(keyStroke%2==0)
subTypeCode=7;
else
subTypeCode=6;
}
else if (toupper(keyStroke)>='A'&&toupper(keyStroke)<='Z')
{ typeCode=1;
if(toupper(keyStroke)=='A'||toupper(keyStroke)=='A'||
toupper(keyStroke)=='A'||toupper(keyStroke)=='A'||
toupper(keyStroke)=='A')
subTypeCode=4;
else
subTypeCode=5;
}
else
{typeCode=3;
if((int)keyStroke<128)
subTypeCode=9;
else
subTypeCode=8;
}
// DISPLAY RESULTS BASED ON SET CODES (SWITCH-CASE)
switch(subTypeCode)
{case 4: printf("%c: vowel ",keyStroke);
break;
case 5: printf("%c: consonant ",keyStroke);
break;
case 6: printf("%c: odd ",keyStroke);
break;
case 7: printf("%c: even ",keyStroke);
break;
case 8: printf("%c: upper ascii ",keyStroke);
break;
case 9: printf("%c: lower ascii ",keyStroke);
break;
}
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.