Consider the testPIN function used in Program 7-21. For convenience, we have rep
ID: 3819914 • Letter: C
Question
Consider the testPIN function used in Program 7-21. For convenience, we have reproduced the code for you below. Modify this function as follows:
change its type to int
change its name to countMATCHES
make it return the number of corresponding parallel elements that are equal
bool testPIN(int custPIN[], int databasePIN[], int size) {
for (int index = 0; index < size; index++) {
if (custPIN[index] != databasePIN[index])
return false; // We've found two different values.
}
return true; // If we make it this far, the values are the same.
}
Explanation / Answer
/**
The modified method testPIN that returns the matched
count as integer type of the custPIN and databasePIN arrays of given size.
*/
int testPIN(int custPIN[], int databasePIN[], int size)
{
//set countMATCHES=0
int matched=0;
for (int index = 0; index < size; index++)
{
if (custPIN[index] == databasePIN[index])
//increment the matched by 1
countMATCHES=countMATCHES+1;
}
//return countMATCHES as return value
return countMATCHES;
}