/* HOMEWORK 2, LAB EXERCISES. Student Name ID Number */ #include #define TRUE 1 #define FALSE 0 #define FEET_PER_METER 3.2808 #define INCHES_PER_FOOT 12 /* Instructions: Complete each of the following six incomplete short functions. For all but the last one, you are given a stub consisting of a header (prototype) and a body containing only a return statement. The header should not be changed. You may find it necessary to change the return statement. For the last incomplete function, orderCheck, you are not given any code at all. This will result in a warning and a linker error until you write some appropriate code for it. (If this bothers you, do it first.) The code for main is a test harness. It should not be changed. Once you have completed the functions, run the program and compare your output with the program's "should be" output. Your version should give the exact same results. Of course, your functions should operate correctly on all inputs, not just the ones that happen to be tested in main! */ /* Return true if at least one argument is greater than zero */ int onePositive(int a, int b, int c){ /* YOUR CODE GOES HERE */ return FALSE; } /* Return true if at least two arguments are greater than zero */ int twoPositive(int a, int b, int c){ /* YOUR CODE GOES HERE */ return FALSE; } /* Round a double value to the nearest integer, .5 is rounded away from zero, so round(1.5) => 2, round(-1.5) => -2 */ int round(double d){ /* YOUR CODE GOES HERE */ return 0; } /* Return the middle of three double values */ double middle(double u, double v, double w){ /* YOUR CODE GOES HERE */ return 0.0; } /* Convert meters to feet and inches, discard fractional inches, print the result */ void printInFeetAndInches(double meters){ /* YOUR CODE GOES HERE */ } /*Define a function orderCheck which takes three values and determines whether the three are in non-decreasing order, printing one or the other of the following messages, as appropriate, on a line preceded and followed by a newline: The three numbers ARE in order The three numbers are NOT in order The function does not return any value. For more hints, look at the calls in main, and see what the answers should be (given in the comments). */ /* YOUR CODE GOES HERE */ /* Display a message "Hit any key to continue", read in one character, and return. Do not modify this function (it is used in main) */ void anyKeyToContinue (void) { char c1; printf("\nHit any key to continue\n"); scanf("%c", &c1); } /* Test harness - main tests the functions on a range of inputs, and print the results so that you can see if your functions are working. DO NOT MODIFY THE CODE IN MAIN */ int main(void){ printf("Testing onePositive, \nshould be 0 1 1 1 1 1 1 1\n"); printf("> %d %d %d %d %d %d %d %d\n", onePositive(0, 0, 0), onePositive(0, 0, 1), onePositive(0, 1, 0), onePositive(0, 1, 1), onePositive(1, 0, 0), onePositive(1, 0, 1), onePositive(1, 1, 0), onePositive(1, 1, 1)); printf("Testing twoPositive, \nshould be 0 0 0 1 0 1 1 1\n"); printf("> %d %d %d %d %d %d %d %d\n", twoPositive(0, 0, 0), twoPositive(0, 0, 1), twoPositive(0, 1, 0), twoPositive(0, 1, 1), twoPositive(1, 0, 0), twoPositive(1, 0, 1), twoPositive(1, 1, 0), twoPositive(1, 1, 1)); anyKeyToContinue(); printf("Testing round, \nshould be 1 1 1 2 -1 -2 -1\n"); printf("> %d %d %d %d %d %d %d\n", round(1.0), round(0.9), round(1.4), round(1.5), round(-1.1), round(-1.6), round(-0.5)); anyKeyToContinue(); printf("Testing middle, \nshould be 2.0 2.1 2.2 2.3 2.4 2.5\n"); printf("> %.1f %.1f %.1f %.1f %.1f %.1f\n", middle(1.0, 2.0, 3.0), middle(1.0, 3.0, 2.1), middle(2.2, 1.0, 3.0), middle(2.3, 3.0, 1.0), middle(3.0, 2.4, 1.0), middle(3.0, 1.0, 2.5)); anyKeyToContinue(); printf("Testing printInFeetAndInches, "); printf("\nShould be 0 feet 0 inches\n> "); printInFeetAndInches(0.01); printf("\nShould be 0 feet 3 inches\n> "); printInFeetAndInches(0.1); printf("\nShould be 3 feet 3 inches\n> "); printInFeetAndInches(1.0); printf("\nShould be 32 feet 9 inches\n> "); printInFeetAndInches(10.0); anyKeyToContinue(); orderCheck (4.1, 4.2, -0.78); /* NOT in order */ orderCheck (3.0, 2.7, 55.1); /* NOT in order */ orderCheck (-11.9, -11.9, -11.9); /* in order */ orderCheck (-12.0, -2.4, 0.99); /* in order */ orderCheck (90.11, 90.12, 90.12); /* in order */ anyKeyToContinue(); return 0; }