Automated Grading Log for CS113 -- HW2 userid: tworster Name: Worster, Thomas Log created: Mon Sep 23 07:45:52 EDT 1996 SUBMISSIONS =========== tworster Submitted hw2-oldman.c at Fri Sep 20 16:49:04 1996 tworster Submitted hw2-fib.c at Fri Sep 20 16:49:04 1996 tworster Submitted hw2-weight.c at Fri Sep 20 16:49:03 1996 tworster Submitted hw2-exp.c at Fri Sep 20 16:49:05 1996 COMPILATION =========== gccx -Wall -c hw2-oldman.c gccx -Wall -o hw2-oldman hw2-oldman.o gccx -Wall -c hw2-fib.c gccx -Wall -o hw2-fib hw2-fib.o gccx -Wall -c hw2-weight.c gccx -Wall -o hw2-weight hw2-weight.o gccx -Wall -c hw2-exp.c gccx -Wall -o hw2-exp hw2-exp.o EXECUTION TESTS ========= ===== hw2-oldman This old man, he played 1. He played knick-knack on my thumb. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 2. He played knick-knack on my shoe. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 3. He played knick-knack on my knee. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 4. He played knick-knack on my door. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 5. He played knick-knack on my hive. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 6. He played knick-knack on my sticks. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 7. He played knick-knack on my heaven. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 8. He played knick-knack on my pate. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 9. He played knick-knack on my spine. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. This old man, he played 10. He played knick-knack on my shin. With a knick-knack paddy-whack, Give your dog a bone. This old man came rolling home. ============================================================ hw2-fib < fib.in1 This program will list all numbers in the Fibonachi sequence that are less than or equal to a number. Enter that number: F(0) = 0 F(1) = 1 F(2) = 1 F(3) = 2 F(4) = 3 F(5) = 5 F(6) = 8 F(7) = 13 F(8) = 21 ============================================================ hw2-fib < fib.in2 This program will list all numbers in the Fibonachi sequence that are less than or equal to a number. Enter that number: You must show at least the numbers up to one. ============================================================ hw2-fib < fib.in3 This program will list all numbers in the Fibonachi sequence that are less than or equal to a number. Enter that number: All Fibonacci numbers are positive numbers. ============================================================ hw2-weight < weight.in1 This program converts kilograms to pounds and ounces. It will continually do this until a value of 0 or less is entered. To quit now, immediately enter a value of 0 or less. Enter kilograms: 1.00 kg is 2 lb and 3 oz. Enter another kilogram weight, or a value of 0 or less to quit Enter kilograms: 10.00 kg is 22 lb and 0 oz. Enter another kilogram weight, or a value of 0 or less to quit Enter kilograms: ============================================================ hw2-weight < weight.in2 This program converts kilograms to pounds and ounces. It will continually do this until a value of 0 or less is entered. To quit now, immediately enter a value of 0 or less. Enter kilograms: 167.25 kg is 367 lb and 15 oz. Enter another kilogram weight, or a value of 0 or less to quit Enter kilograms: 2.50 kg is 5 lb and 8 oz. Enter another kilogram weight, or a value of 0 or less to quit Enter kilograms: ============================================================ hw2-exp This program implements a raise a number to a power function(x^k) and returns the results of 10^k, where -4 < k < 4. k k 10 --------------- -4 0.0001 -3 0.001 -2 0.01 -1 0.1 0 1.0 1 10.0 2 100.0 3 1000.0 4 10000.0 ============================================================ Data files: ==========: ==> /home/course/cs113/GradesF96/HW2/input/fib.in1 <== 25 ==> /home/course/cs113/GradesF96/HW2/input/fib.in2 <== 0 ==> /home/course/cs113/GradesF96/HW2/input/fib.in3 <== -4 ==> /home/course/cs113/GradesF96/HW2/input/weight.in1 <== 1 10 0 -1 ==> /home/course/cs113/GradesF96/HW2/input/weight.in2 <== 167.25 2.5 -17.5 ============================================================ SOURCE FILES ====== ===== /* File: hw2-oldman.c * Written by Tom Worster * For CS113 Fall '96 * Assignment 2, Problem 1(Based on Roberts: Chap. 4, Exer. 2) * Due on Sept. 20, 1996 * Last modified on Sept. 20, 1996 * * Usage: hw2-oldman (no arguements) * * * Overview: This program displays the first 10 verses of the children's * song, This Oldman * * * Algorithm Notes: A function with a simple loop is used to display the * text, with another function holding the rhyming words. * * * Known Bugs: There are no known bugs. * * * Error Handling: There are no error messages. However, if any number * besides 1 thru 10 are sent to VerseRhyme, it will not * return anything. The program as written now never * will, but if it is edited, this must be handled. */ #include #include "genlib.h" #include "simpio.h" /* Function: PrintVerse * Usage: PrintVerse(verseNum) * ------------------------------------- * Prints the correct verse, as per verseNum. This contains the text of the * verses, not the rhyming words themselves. */ void PrintVerse(int verseNum); /* Function: VerseRhyme * Usage: s = VerseRhyme(verseNum) * ------------------------------------- * Returns as a string the correct "rhyme word", as per verseNum. */ string VerseRhyme(int verseNum); int main() { int verse; /* For Loop prints 10 verses */ for (verse = 1; verse <= 10; verse++) { PrintVerse(verse); printf("\n"); } /* End For Loop */ return 0; } void PrintVerse(int verseNum) { printf("This old man, he played %d.\n", verseNum); printf("He played knick-knack on my %s.\n", VerseRhyme(verseNum)); printf("With a knick-knack paddy-whack,\n"); printf("Give your dog a bone.\n"); printf("This old man came rolling home.\n"); } string VerseRhyme(int verseNum) { switch (verseNum) { case 1: return "thumb"; case 2: return "shoe"; case 3: return "knee"; case 4: return "door"; case 5: return "hive"; case 6: return "sticks"; case 7: return "heaven"; case 8: return "pate"; case 9: return "spine"; case 10: return "shin"; } return ""; /* Needed to to avoid a warning. This point should never be * reached. */ } /* File: hw2-fib.c * Written by Tom Worster * For CS113 Fall '96 * Assignment 2, Problem 2(Based on Roberts: Chap. 4, Exer. 9) * Due on Sept. 20, 1996 * Last modified on Sept. 20, 1996 * * Usage: hw2-fib (no arguements) * * * Overview: This program prints a list of Fibonacci numbers. The upper * bound is decided by asking the user what the highest number * can be, and giving the highest Fibonacci number less than or * equal to that number. * * * Algorithm Notes: The algorithm used here is a sequence, where the next * number in the sequence is the sum of the last two, * such that S(n) = S(n-1) + S(n-2), where n is the term. * The sequence starts out so that S(0) = 0, and S(1) = 1. * * * Known Bugs: There are no known bugs. * * * Error Handling: This program handles two errors. If the user enters a 0 * as the highest number, the user is told that the highest * number must be one, and the program terminates. This * error message is for two reasons. One, it is pointless * to show the 0th term in the sequence, and two, to make * the algorithm easier to write. The second error handles * a case where a negative number is entered. This is due to * the fact that all Fibonacci numbers are positive or 0. */ #include #include "genlib.h" #include "simpio.h" /* Function: PrintFibonacciUpTo * Usage: PrintFibonacciUpTp(highest) * ------------------------------------- * This function prints all the Fibonacci numbers less than or equal to a * top number, highest. */ void PrintFibonacciUpTo(int highest); int main() { int highest; printf("This program will list all numbers in the Fibonachi sequence\n"); printf("that are less than or equal to a number.\n"); printf("Enter that number: "); highest = GetInteger(); /* Checks if a 0 was entered, as per error handling described above */ if (highest == 0) { printf("You must show at least the numbers up to one.\n"); /* Checks if a negative number was entered, as per error handling */ } else if (highest < 0) { printf("All Fibonacci numbers are positive numbers.\n"); /* If no errors, prints the list of numbers */ } else { PrintFibonacciUpTo(highest); } return 0; } void PrintFibonacciUpTo(int highest) { int trailingNum, leadingNum, term; /* Initializes sequence terms */ trailingNum = 0; leadingNum = 1; printf("F(0) = %6d\n", trailingNum); /* Begin For loop */ for (term = 1; leadingNum <= highest; term++) { printf("F(%d) = %6d\n", term, leadingNum); leadingNum += trailingNum; trailingNum = (leadingNum - trailingNum); } /* End For Loop */ } /* End Function */ /* File: hw2-weight.c * Written by Tom Worster * For CS113 Fall '96 * Assignment 2, Problem 3(Based on Assignment 1, Problem 2) * Due on Sept. 20, 1996 * Last modified on Sept. 20, 1996 * * Usage: hw2-weight (no arguements) * * * Overview: This program will take a weight in kilograms from the user and * and change it to the pound and ounce equivalent. This will * continue until the user enters a number less than zero, and * the program ends. * * * Algorithm Notes: The formulas used here are (2.2)(16)K = O, where K is * weight in kilograms and O is weight in ounces. This * formula is used in the function KilogramsToOunces. * This is derived from (2.2)K = P, where P is weight in * pounds, and O = (16)P, where O is weight in ounces. * * * Known Bugs: There are no known bugs. * * * Error Handling: This program has no error messages, as none are needed. * The only reason there would be a need for error messages * is if a negative number is entered. However, because * whenever a negative number is entered, the entering of * kilogram weights ends, and because this is explained to * the user, there is no need for error messages. */ #include #include "genlib.h" #include "simpio.h" /* * Function: KilogramsToOunces * Usage: oz = KilogramsToOunces(kg) * ------------------------------------- * This function converts KilogramsToOunces, using the algorithm mentioned * above. */ int KilogramsToOunces(double kilograms); int main() { int pounds; double kilograms; printf("This program converts kilograms to pounds and ounces.\n"); printf("It will continually do this until a value of 0 or less is entered.\n"); printf("To quit now, immediately enter a value of 0 or less.\n\n"); while (TRUE) { /* Begin Repeat..Until Sentinel Loop. * Converts kilograms to pounds and ounces, until sentinel of any * number less or equal to 0 is reached. */ printf("Enter kilograms: "); kilograms = GetReal(); /* Sentinel */ if (kilograms <= 0) { break; } /* Finds whole number pounds */ pounds = (KilogramsToOunces(kilograms) / 16); /* Begin printf */ printf("%.2f kg is %d lb and %d oz.\n", kilograms, pounds, /* This finds the number of ounces in the whole number * pounds, and is subtracted from the total ounces, in * order to find the remaining ounces. */ KilogramsToOunces(kilograms) - (pounds * 16)); /* End printf /\ */ printf("Enter another kilogram weight, or a value of 0 or less to quit\n\n"); /* End Repeat..Until Sentinel Loop */ } return 0; } int KilogramsToOunces(double kilograms) { return (kilograms * 2.2) * 16; } /* File: hw2-exp.c * Written by Tom Worster * For CS113 Fall '96 * Assignment 2, Problem 4(Based on Roberts: Chap. 5, Exer. 6) * Due on Sept. 20, 1996 * Last modified on Sept. 20, 1996 * * Usage: hw2-exp (no arguements) * * * Overview: This program utilizes an exponential function, which raises * a real to an integer, and displays a table of 10.0 up to * powers of -4 to 4. * * * Algorithm Notes: The formulas used here are the obvious power equation * x^k. This is done by multiplying x by itself k times, * by using a loop. * * * Known Bugs: There are no known bugs. * * * Error Handling: Nothing is asked, there can be no errors that aren't * bugs as well. */ #include #include "genlib.h" #include "simpio.h" /* Function: RaiseRealToPower * Usage: r = RaiseRealToPower(x,k); * ------------------------------------- * Performs the operation x^k, where x is a real, k is an integer, and r * is a real number total. */ double RaiseRealToPower(double x, int k); int main() { int power; printf("This program implements a raise a number to a power function(x^k) and\n"); printf("returns the results of 10^k, where -4 < k < 4.\n\n"); printf(" k\n"); printf(" k 10\n"); printf("---------------\n"); /* Prints the negative k values */ for (power = -4; power < 0; power++) { printf("%d %.*f\n", power, (power * -1), RaiseRealToPower(10,power)); } /* Prints the 0 and positive k values. */ for (power = 0; power <= 4; power++) { printf(" %d %8.1f\n", power, RaiseRealToPower(10, power)); } return 0; } double RaiseRealToPower(double x, int k) { double total; bool negative; negative = FALSE; /* If k is negative, that is flagged and dealt with later */ if (k < 0) { negative = TRUE; k *= -1; } /* Loop to compute the equation */ for (total = 1.0; k > 0; k--) { total *= x; } /* Checks flag, if true, the total is actually one over the total. * The program adjusts for this. */ if (negative) { total = 1 / total;} return total; } -- END OF LOG FILE FOR tworster --