Homework 6 Due October 22, 2002 Solutions 6c) Three has 4 parameters and is of type char (character). 6d) Function test needs 4 actual parameters when called. They are of type int, character, double, and int, and should be ordered int,char,double,int. 6e) cout << test(5, 'z', 7.3, 5); 7a) 14 7b) 15 7c) 30 8ai) 125 8aii) 432 8b) The function secret cubes the value passed to it. A. Here is one solution: bool is_leap_year(int year) { if (year % 4 != 0) return false; if (year % 400 == 0) return true; if (year % 100 == 0) return false; return true; } B. float min_of_three(float num1, float num2, float num3) { float min = num1; if(num2 < min) min = num2; if(num3 < min) min = num3; return min; } C. // assume we have done a #include bool is_vowel(char c) { char lowercase = tolower(c); if(lowercase == 'a' || lowercase == 'e' || lowercase == 'i' || lowercase == 'o' || lowercase == 'u') return true; else return false; } D. // assume we have already done a #include float distance(float x1, float y1, float x2, float y2) { return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); } E. The program prints out all numbers between 1 and the inputted number which are divisble by 6 #include using namespace std; bool divisible_by_six(int num); // prototype for division function int main() { int pos; // positive integer to be inputted by user int i; // loop iterator // prompt user for input for variable pos cout << "Please type a positive integer: "; cin >> pos; if(!cin || pos < 0) { // if no input or number is not positive cout << "Silly, user! You did not follow directions!\n"; return 1; // end program with error condition } for (i = 1; i <= pos; i++) { // repeat the following for integers 1 to pos if(divisible_by_six(i)) // if i is a multiple of 6, cout << i << " "; // then output it } return 0; // end program without error condition } /* Purpose: This function takes a number and determines if it is divisible by 6 It does this by checking that it's divisible by both 2 and 3. If the number is divisible (with no remainder) by both 2 and 3, then we return true, otherwise we return false. Note that this is an inefficient way to do this! */ bool divisible_by_six(int num) { if(num % 3 || num % 2) // if num has a remainder of other than zero // when we divide by either 2 or 3 return false; // then it's not divisible by 6 else return true; // it's divisible by 6 }