Test 1 CSCI 130 Summer 2010


  1. (10 points) Identifiers
    1. What is an identifier?
    2. Give the rules for constructing an identifier and an example which violates each rule. State how your example violates the rule.
    3. Give the conventions for naming variables and constants in a C++ program and give a meaningful example of each.
  2. (2 points) Give C++ code to declare a string variable.
  3. (2 points) What happens when a variable is declared?
  4. (6 points) Variable Initialization
    1. What does it mean to initialized a variable?
    2. Why is it important that variables be initialized?
    3. Show how to initialize a variable when it is declared.
  5. (2 points) Give the C++ code which will declare a floating point constant SALES_TAX and set the value of this constant to be 0.06.
  6. (4 points) Justify why it is better to use the constant SALES_TAX than the floating point literal 0.06 in a program.
  7. (4 points) Name and describe the four basic data types discussed in class.
  8. (8 points) Integers
    1. Name the basic integer data types.
    2. What is the relationship between these types.
    3. What properties do all of these types have in common?
  9. (4 points) Describe what happens when the following code is executed.
    string word;
    cin >> word;
       
  10. (8 points) Describe the operation of the following functions.
    1. cin.ignore(25,'x');
    2. getline(cin, myString);
  11. (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.