- (12 points) We have discussed 4 different data types:
- Name each
- Describe the type of data each can hold
- Given an example of a litteral of each data type.
- (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.
- (5 points) What is the difference between a constant and a variable? Describe each. Show how to declare each.
- (4 points) Describe what happens when a variable is defined.
- (4 points) Define type conversion and coercion. Give an example
of each.
- (2 points) What is the result of the following computation? Why?
float x;
x = 1/4;
- (2 poitns) What does it mean to initialize a variable? Why must this be done?
- (4 points) Describe two different methods that can be used to make programs easier to understand. Give an example of each.
- (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
- (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;
}
- (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