// Lab Test #1 Version #1 #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 an integer. // The second parameter is "return"ed by the function. // It is set to true if the first parameter is less than 0, and false otherwise. // The third parameter is "return"ed by the function. // It is set to true if the first parameter is an exact multiple of 4 // (e.g. -4, 0, 4, 8, ...), and false otherwise. // This function (arrayInfo) has three parameters and returns an integer. // The first parameter is an integer indicating the length of the array. // The second parameter an integer. // The third parameter is an array of integers. // If the first 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 within 10 of the the second parameter (i.e. the difference // between the array element and the second parameter is less than or // equal to 10). int main() // some tests of the functions above { bool bool1, bool2; int answer; int array[6] = { 15, 0, -5, 10, 45, 789}; // Testing numberFacts // set the bools incorrectly to make sure the function is working properly bool1 = true; bool2 = false; numberFacts(8, bool1, bool2); // first test of numberFacts if (bool1) cout << "INCORRECT: 8 is less than 0.\n"; else cout << "CORRECT: 8 is not less than 0.\n"; if (bool2) cout << "CORRECT: 8 is a multiple of 4.\n\n"; else cout << "INCORRECT: 8 is not a multiple of 4.\n\n"; // set the bools incorrectly to make sure the function is working properly bool1 = false; bool2 = true; numberFacts(-10, bool2, bool1); // second test of numberFacts if (bool2) cout << "CORRECT: -10 is less than 0.\n"; else cout << "INCORRECT: -10 is not less than 0.\n"; if (bool1) cout << "INCORRECT: -10 is a multiple of 4.\n\n"; else cout << "CORRECT: -10 is not a multiple of 4.\n\n"; // Testing arrayInfo answer = arrayInfo(6,15,array); // 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 within 10 of 15 is:\n" << " " << answer << ". (Should be 2.)\n\n"; answer = arrayInfo(4,0,array); // second test of arrayInfo if (answer == -1) cout << "INCORRECT: 4 is an invalid array length.\n\n"; else cout << "The number of the first 4 elements in the array that are within 10 of 0 is:\n" << " " << answer << ". (Should be 3.)\n\n"; answer = arrayInfo(-5,10,array); // 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 within 10 of 10 is:\n" << " " << answer << ". (0 or anything else here is INCORRECT.)\n\n"; pause(); return 0; }