Assessment Tool

Lecture 11:  Complex Conditions

Content Tested:  Tracing variable values and evaluating complex conditions

Lecture Content:

Goals:

Assessment Technique:  Documented Problem Solutions

Purpose:

Instructors can find out how students trace code and evaluate complex conditions.

Activity:

In your group please state the values of the variables a, b, and c after executing the following code.  Also, please document how you are tracing the code and keeping track of the variables.  A possible way to keep track of this information is to use a table that lists the values of each variable for each iteration through the loop.  Remember:  getting an answer in this activity is not as important as showing your work to arrive at your solution.

#define TRUE 1
#define FALSE 0
.
.
.
/* in a function */
int a, b, c;
a = TRUE;
b = 6;
c = 8;
while ((!a) || ((b > 2) && (c <= 12))){
    if (a){
        c = b * 2;
    }
    else{
        b = c - 7;
    }
    a = (!a);
}
 

Possible Solution

 
Loop Iteration a b c
before loop 1 6 8
1st 0 6 12
2nd 1 5 12
3rd 0 5 10
4th 1 3 10
5th 0 3 6
6th 1 -1 6

The values of a, b, and c are the following:
a: 1
b: -1
c: 6

Possible Uses of Activity: