Test 2 CSCI 130
Fall 2015
- Please answer each question fully, carefully and thoughtfully.
- No credit will be given for unreadable answers, please write neatly.
- Answer the questions in any order, but please number each answer.
- Make sure that your name is on your test.
- When ask to give code segments, you need not write an entire program.
- Integers
- [3 points] Name three different integer types. What is the relationship between these types?
- [1 point] Under normal circumstances which integer type should be used?
- [2 points] What does the unsigned reserved word do when used with an integer type? Why would this be used?
- [1 point] What does the modulus operator do?
- [2 points] Describe integer division. Give a code example where integer division produces unexpected results.
- [3 points] Describe the operation of the postfix increment operator. Give a small code example using the postfix increment operator and explain what your example does.
- Input/Output
- [2 points] Describe how the stream extraction operator works with a floating point variable as the destination.
- [2 points] Give an example of input for which using the stream extraction operator with a floating point variable as the destination will fail. Explain why this input will cause a failure.
- [2 points] What happens when a stream failure occurs?
- Floating Point
- [2 points] Discuss the types of values that are represented as floating point numbers. Give examples.
- Coercion and Type Casting
- [2 points] Define coercion and type casting.
- [3 points] Why should a program perform type casting over coercion?
- [3 points] Give a small code segment, including variable declarations, which illustrates how to perform type casting.
- I/O Manipulators
- [2 points] Describe the syntax of the setw operator.
- [2 points] Describe the semantics of the setw operator.
- [2 points] Give a short example using the setw operator, expalin what your example does.
- [1 point] Why would a programmer use the setw operator?
- Flow of control
- [2 points] What is the flow of control in a program?
- [2 points] What is a control structure?
- Boolean Datatype
- [4 points] Describe the boolean datatype.
- [2 points] Discuss the difference between the = operator (1 = sign) and the == operator (2 = signs).
- [5 points] Program: Write a complete program which reads in the temperature in Fahrenheit and prints the result in Celsius. C = 5/9(F-32)