Test 1 CSCI 130 Summer 2004


  1. (12 points) We have discussed 4 different data types:
  2. (10 points) Give the rules for constructing an identifier. Give an example of a good identifier. Give an example of an identifier that violates each of the rules. State how each bad identifier violates a rule.
  3. (5 points) What is the difference between a constant and a variable? Describe each. Show how to declare each.
  4. (4 points) Describe what happens when a variable is defined.
  5. (4 points) Define type conversion and coercion. Give an example of each.
  6. (2 points) What is the result of the following computation? Why?
       float x;
       x = 1/4;
       
  7. (2 poitns) What does it mean to initialize a variable? Why must this be done?
  8. (4 points) Describe two different methods that can be used to make programs easier to understand. Give an example of each.
  9. (10 points) Write a program that will read a telephone number in the form (aaa) bbb-cccc and print out the area code aaa, local exchange bbb and local number ccccc each on a different line. Your output should look like this:
    Enter a phone number: (814) 723-1177
    Your area code:814, Exchange: 732, Number: 1177
       
  10. (7 pts) Trace the execution of the following code:
    int main () {
       int x, y;
       float z;
    
       x = 4;
       y = float(x)+2;
       z = y/x;
    
       cout << "x = " << x << "y" + " = " << y;
       cout << "z = " << z << endl;
    }
       
  11. (5 points) Trace the following code segment using the given input:
    int a;
    float b;
    char c;
    string d;
    
    cin >> a >> d >> c >> b;
    
    INPUT:          54.246        942  a Hello 3.14159 to be or not to be