Key for Homework 4B on I/O and Selection in C++ Q A Reason ----------------------------------------------------------------------------------- For questions 1 through 5, we start with the input stream (separated by tabs): 1.2 49A -46.32 1 1 cin >> anInt // reads the value 1 into anInt >> aChar; // reads the char '.' into aChar 2 4 See analysis for question 1. 3 9 cin >> anInt // reads the value 1 into anInt >> aDble; // reads the value .2 into aDble 4 2 cin >> aDble // reads the value 1.2 into aDble >> aChar; // discards the tab, reads the value '4' into aChar 5 2 cin >> anInt; // reads the value 1 into anInt cin.get(aChar); // reads the value '.' into aChar cin >> anInt; // reads the value 2 into anInt 6 3 1 would print 78 two columns too far to the right 2 would print 78 two columns too far to the left 3 is just right 7 3 If Enter == 1, the switch would execute case 1, setting Enter to -4, then fall through into case 2 since there's no break in case 1. That would set Enter to -6, but then fall through into case 4 since there's no break in case 2 either. That would set Enter to -8 and the break would cause us to exit the switch. 8 4 If Enter == 10, there's no case for that specific value, so the default case would be executed, setting Enter to -1. 9 4 Apply DeMorgan's Law: !(A || !B && C) == !( A || ( !B && C ) == !A && !( !B && C ) == !A && (!!B || !C) == !A && (B || !C) Note: the parentheses DO matter because && has higher precedence than ||.