Computer Science 157 – Fall 1999

10/04/99                 Mid Term Test # 1                        Test Form A

 

Name:

 

Instructions:

                Answer ALL questions on the answer sheet provided.

                Hand in TEST, Answer Sheet, and Help Sheet, each with your name on it.

                Remember to put the letter of your test form on your answer sheet.

                Please ask any clarifying questions you have (come up).

 

Completion (3 points each)

 

1. The solution to any problem involves performing an ordered series of actions. The planned step-by-step sequence of actions is called a(n) ________. Such ordered procedures may be found in everyday life as well as in computer problem-solving.

 

2. The _______ in a computer is temporary storage; programs are loaded into here when they are run, and data is stored here while a program is running. When the computer is turned off, anything in here is forgotten.

 

 

Short Answer (points as shown)

 

(4 points)

3. List the 4 main levels of programming languages.

 

 

Valid/Invalid (4 points each)

For each, tell whether valid or invalid. If invalid, tell why!

 

Variable names:

 

4.

   win%

 

Statements: 

 

5.

  int x = 3;

  x = x + 3;

 

6.

  int z = 2;

  int x = 6;

  z + 4 = x;

 

7.

  int price = 10;

  PRICE++;

 

8.

  int x = 11;

  int j;

  if x < 13 {

     j = x + 1;

    }

 

 

9.

int m;

int sq;

int numb = 7;

for (m = 0; m < numb; m++) {

   sq = m * m;

   printf(“%2d \n”,sq);

}

 

 

Doing and Understanding: (points as shown)

 

(6 points)

10. What is the value for each of the following expressions?

a)

  17 % 5

b)

  (( 5 - 2) * ((6 - 3) + 2))

 

 

(6 points)

11. What is displayed by the following code fragment:

 

  int b = 5;

  int c = b;

  b++;

  printf("%2d  %2d  \n",b,c);

 

 

 (6 points)

12. What is displayed by the following code fragment:

 

  int x = 5;

  int y = 7;

  x += y;

  printf("%2d  %2d  \n",x,y);

 

 

 

(6 points)

13. What is displayed by the following code fragment:

 

  int a = 8;

  int b = 7;

  if (a > b) {

     a--;

     b++;

    }

  else {

     a++;

     b--;

    }

  printf("a: %2d  b: %2d \n",a,b);

 


 

(6 points)

14. What is displayed by the following code fragment:

 

  int x = 5;

  if (x > 3) {

     if (x < 10) {

        x++;

      }

     else {

        x += 2;

      }

    }

  else {

     x += 3;

    }

  printf(“x: %2d \n”,x);

 

 

(8 points)

  15. What is displayed by the following code fragment?

 

int a = 0;

int b = 5;

while (a < b) {

   a += 3;

   b++;

   printf(“%3d %3d \n”,a,b);

 }

 

 

Writing Code (points as shown)

 

(8 points)

16. Write C statement(s) that check the value of the variable payRate (which we assume has been declared and given a value), and if the payRate is between $10-15 per hour then, increase the pay rate by 10%; otherwise, increase the pay rate by 20%.

 

(20 points)

17. An amusement park charges admission based on the following criteria: A base charge of $5 for every person admitted; An additional charge of  $2 for every year of age, up to a maximum of $20; Plus, an additional $10 if the  person is taller than 48 inches tall. Assuming that the variables (age, height) have been declared and given values (through printf/scanf combinations), write statements that will calculate an admission price, and display the price.