// Lab Test #1 Version #2 #include "stdstuff.h" // Write the two functions indicated. It is not necessary to write any // function prototypes. Just write the complete functions at the top // of the file as indicated. // Your functions must work for *any* input, not just for the examples // given in this main program. You are welcome to add additional test // cases. // Note that program comments are required for full marks. // This function (numberFacts) has three parameters and returns nothing (void). // The first parameter is "return"ed by the function. // It is set to true if the third parameter is between 10 and 20 (inclusive) and false otherwise. // The second parameter is "return"ed by the function. // It is set to true if the third parameter is less than 17, and false otherwise. // The third parameter is an integer. // This function (arrayInfo) has three parameters and returns an integer. // The first parameter an integer. // The second parameter is an array of integers. // The third parameter is an integer indicating the length of the array. // If the third parameter (length of the array) is invalid (i.e. doesn't // make sense), the function returns -1. // Otherwise, this function returns the number of elements of the array // that are exactly divisible by the first parameter, i.e. there is no remainder // when dividing the array element by the first parameter. int main() // some tests of the functions above { bool bool1, bool2; int answer; int array[6] = { 15, 100, -5, 4, 45, 789}; // Testing numberFacts // set the bools incorrectly to make sure the function is really working bool1 = false; bool2 = false; numberFacts(bool1, bool2, 10); // first test of numberFacts if (bool1) cout << "CORRECT: 10 is between 10 and 20, inclusive.\n"; else cout << "INCORRECT: 10 is not between 10 and 20, inclusive.\n"; if (bool2) cout << "CORRECT: 10 is less than 17.\n\n"; else cout << "INCORRECT: 10 is not less than 17.\n\n"; // set the bools incorrectly to make sure the function is really working bool1 = true; bool2 = false; numberFacts(bool2, bool1, -33); // second test of numberFacts if (bool2) cout << "INCORRECT: -33 is between 10 and 20, inclusive.\n"; else cout << "CORRECT: -33 is not between 10 and 20, inclusive.\n"; if (bool1) cout << "CORRECT: -33 is less than 17.\n\n"; else cout << "INCORRECT: -33 is not less than 17.\n\n"; // Testing arrayInfo answer = arrayInfo(5,array,6); // first test of arrayInfo if (answer == -1) cout << "INCORRECT: 6 is an invalid array length.\n\n"; else cout << "The number of the first 6 elements in the array that are divisible by 5 is:\n" << " " << answer << ". (Should be 4.)\n\n"; answer = arrayInfo(2,array,3); // second test of arrayInfo if (answer == -1) cout << "INCORRECT: 3 is an invalid array length.\n\n"; else cout << "The number of the first 3 elements in the array that are divisible by 2 is:\n" << " " << answer << ". (Should be 1.)\n\n"; answer = arrayInfo(10,array,-5); // third test of arrayInfo if (answer == -1) cout << "CORRECT: -5 is an invalid array length.\n\n"; else cout << "The number of the first -5 elements in the array that are divisibly by 10 is:\n" << " " << answer << ". (0 or anything else here is INCORRECT.)\n\n"; pause(); return 0; }