|
|
|
|
|
|
|
for (index = 0; index << length; index++)
// Invariant (prior to test):
// For all i, where 0 <= i <= index-1,
// IF score[i] > grade, THEN passing[i] == TRUE
// && 0 <= index <= length
if (score[index] > grade)
passing[index] = TRUE;
} |
|
|
|
|
|
|
|
|
Chapter 11
Case Study Follow-Up |
|
|
|
|
|
|
|
|
2. No. If charList were declared to be a const formal parameter, the compiler would not allow the function body to modify the array. Specifically, the statement |
|
|
|
 |
|
|
|
|
charList[counter] = ch; |
|
|
|
 |
|
|
|
|
would generate a compile-time error. |
|
|
|
|
|
|
|
|
Chapter 12
Exam Preparation Exercises |
|
|
|
|
|
|
|
|
6. a. typedef char NameType[41];
b. NameType oneName;
c. NameType employeeMame[100]; |
|
|
|
|
|
|
|
|
7. a. valid b. valid c. invalid d. valid e. valid f. invalid g. invalid h. valid |
|
|
|
|
|
|
|
|
9. a. valid b. invalid c. valid d. invalid e. valid f. invalid g. valid |
|
|
|
|
|
|
|
|
Chapter 12
Programming Warm-Up Exercises |
|
|
|
|
|
|
|
|
2. int Count ( /* in */ const ItemType numList[],
/* in */ ItemType item,
/* in */ int length )
// Precondition:
// length <= MAX_LENGTH
// && numList[0..length-1] are assigned && item is assigned
// Postcondition:
// Function value == number of occurrences of value item
// in numList[0..length-1]
{
int index; // Loop control and index variable
int counter =0; // Number of occurrences of item
|
|
|
|
|
|