Test 1 CSCI 130
Summer 2011
- 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.
- Identifiers
- (2 points) What is an identifier?
- (6 points) Give the rules for constructing an identifier and an example which violates each rule. State how your example violates the rule.
- Constants
- (2 points) Give the syntax for declaring a named constant.
- (2 points) Give an example of how a constant is declared.
- (6 points) List the conventions for creating a named constant.
- Variables
- (2 points) How is a variable different from a constant?
- (2 points) Give the syntax for declaring a variable.
- Data Types
- (2 points) What is a data type?
- (3 points) List the basic floating point data types
- (2 points) What is the relationship between the floating point data types listed above.
- (3 points) Describe the floating point data types.
- Variable Initialization
- (2 points) What does it mean to initialized a variable?
- (2 points) Why is it important that variables be initialized?
- (2 points) Show how to initialize a variable when it is declared.
- (4 points) Justify why it is better to use the constant
SALES_TAX
than the floating point literal 0.06 in a program.
- (10 points) Write a complete C++ program which will prompt the user for two integers a and b and print a/b as a mixed number. If the numbers are
4
and 3
, the output would be 4/3 = 1 and 1/3
, while the input 6
and 2
will output 6/2 = 3 and 0/2
. You may assume that b will not be 0.