Homework 2
Due Monday, September 23, 2002
Solutions

a.  int task_count;
b.  string mom_maiden_name;
c.  char letter;
d.  float distance;
e.  long US_deficit;
f.  int prime_number
g.  string login_name;
h.  float area;
i.  int num_toilets;

1a) False
1b) False
1c) False
1d) True
1e) True
1f) False
1g) True
1h) True

2a) Legal
2b) Not legal
2c) Not legal
2d) Legal
2e) Legal
2f) Not legal
2g) Not legal
2h) Not legal
2i) Legal
2j) Legal

8) Line 1 is missing a type specification
   Line 2 is missing an initial value after the "="
   Line 3 is fine
   Line 4 is fine

10a) int x, y;
10b) int x=10;
     char ch = 'B';
10c) x = x + 5;
     or x += 5;
10d) if the variable z has not yet been declared:
         double z = 25.3;
     if the variable z has already been declared:
         z = 25.3;
10e) z = y;
10f) First declare a third variable z for temporary storage, then do the swap:
     int z;  // temporary storage
     z = y;  // store the value of y before wiping it out with x's value
     y = x;  // put x's value into y
     x = z;  // store the original value of y in x 
10g) Assuming x and y have already been declared and initialized:
     cout << x << " " << 2*x+5-y << endl;
10h) char grade = 'A';
10i) int a, b, c, d;
10j) x = z + 0.5;
     or even better:
     x = static_cast  (z + 0.5);
   
11a) -10*a;
11b) '8'
11c) (b*b - 4*a*c)/(2*a)
11d) (-b + (b*b-4*a*c))/(2*a)

14a) x = 2, y = 5, z = 6
14b) x + y = 7
14c) Sum of 2 and 6 is 8
14d) z / x = 3
14d)  2 times 2 = 4

15a) 0.5
15b) 24.5
15d) 8.3
15f) 38.75

23) a = 25
    Enter two integers: 20 15

    The numbers you entered are 20 and 15 
    z = 45.5
    Your grade is A
    The value of a = 65