/* This program demonstrates * 1. Fall through and character inputs for a switch statement * 2. sizeof operator * 3. unsigned qualifier * 4. Working with characters * 5. Conditional Operator * * Using character variables * A char variable is an integer type, so it can be assigned integer values. However, * doing so might result in unexpected behavior, since the numbers translate to * different characters using an internal code (ASCII - to be covered later). * * To assign a character value to a char variable, we need to pace the character * in single quotes. * Single quotes char values can only be a single charcater or in certain cases, * an escaped character (ones that begin with \, followed by a character. * * Using if/switch statements with char variables * char variables might be used in boolean expressions just like ints and doubles. * The only difference is that chracter literals must be a single chracter or an * existing escape sequence, enclosed in single quotes. * * The Conditional operator * A simple if-else statement with ONLY ONE LINE in the if block and the * else block can be written using the conditional operator. * The conditional operator is the only ternary operator (operator with 3 * operands) we'll cover in this course. * This is the syntax: * (condition used for the if) ? line in the if block : line in the else block; */ #include using namespace std; int main() { /* The following example will read in a character representing a month and print the * name of the month and the number of days in that month in a standard calendar year. * This demonstrates how to use a char variable in a switch statement. The case labels * need to be single quoted. */ char month; cout<<"Enter the month (letter): "; cin>>month; int daysInMonth=0; switch(month) { case 'F': daysInMonth=28; // February break; case 'A': // April case 'j': // June case 'S': // September case 'N': daysInMonth=30; // November break; case 'J': // January case 'M': // March case 'm': // May case 'U': // July, since both J's were taken already case 'a': // August case 'O': // October case 'D': daysInMonth=31; // December break; default: cout<<"Invalid month"<>a; cout<<"User entered: "<>x>>y>>z; (x>y) ? (x>z) ? largest = x : largest = z : (y>z) ? largest = y : largest = z ; cout<<"Largest number is "<