Automated Grading Log for CS113 -- HW2 userid: jberke Name: Berke, Joshua Log created: Mon Sep 23 07:34:56 EDT 1996 SUBMISSIONS =========== jberke Submitted hw2-oldman.c at Thu Sep 19 16:11:51 1996 jberke Submitted hw2-fib.c at Thu Sep 19 16:11:37 1996 jberke Submitted hw2-weight.c at Thu Sep 19 17:54:20 1996 jberke Submitted hw2-exp.c at Thu Sep 19 21:43:42 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 Please enter the greatest value of the Fibonacci sequence that you wish to find. The value must betwen 0 and 10,000 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 Please enter the greatest value of the Fibonacci sequence that you wish to find. The value must betwen 0 and 10,000 f(0) = 0 ============================================================ hw2-fib < fib.in3 Please enter the greatest value of the Fibonacci sequence that you wish to find. The value must betwen 0 and 10,000 There are no Fibonnaci numbers less than 0 ============================================================ hw2-weight < weight.in1 Please input weight in kilograms or 0 to exit: 1 kilograms is 2 pounds and 3.2 ounces Please input weight in kilograms or 0 to exit: 10 kilograms is 22 pounds and 0 ounces Please input weight in kilograms or 0 to exit: ============================================================ hw2-weight < weight.in2 Please input weight in kilograms or 0 to exit: 167.25 kilograms is 367 pounds and 15.2002 ounces Please input weight in kilograms or 0 to exit: 2.5 kilograms is 5 pounds and 8 ounces Please input weight in kilograms or 0 to exit: Weights can't be negative numbers ============================================================ hw2-exp 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 * Author: Joshua Berke * Class: CS 113 * Assignment: Chapter 4, Exercise 2 * Due Date: September 19 * Last modified: September 17 * ----------------------------------------------------- * * USAGE: * ====== * No commands * * OVERVIEW: * ========= * This program displays all 10 verses of the song "This Old Man" * * Algorithm Notes: * ================ * I used a for loop to loop through the verses and to determine the number at * the end of line 1. I used a switch function and a string to determine the * rhyming word. * * Known Bugs: * =========== * none * * Other Comments: * =============== * This is a simple little program. But could be enhanced to let the user pick * which verse he wanted outputed. */ #include #include "simpio.h" #include "genlib.h" int main() { int verse; /* Lets the program know which verse it is on */ string rhyme; /* The rhyming word at the end of line 2 is here */ /* For loop will loop through the verses */ for(verse = 1; verse <= 10; verse++){ /* Assings the correct word to the string rhyme */ switch (verse){ case 1: rhyme = "thumb"; break; case 2: rhyme = "shoe"; break; case 3: rhyme = "knee"; break; case 4: rhyme = "door"; break; case 5: rhyme = "hive"; break; case 6: rhyme = "sticks"; break; case 7: rhyme = "heaven"; break; case 8: rhyme = "pate"; break; case 9: rhyme = "spine"; break; case 10: rhyme = "shin"; break; } /* Displays the verse 10 times, but each time the verse contains * diffrent number and rhyming word. */ printf("\nThis old man, he played %d\nHe played knick-knack on my %s" "\nWith a knick-knack, paddy-whack,\nGive your dog a bone" "\nThis old man came rolling home.\n", verse, rhyme); } return 0; } /* * File: hw2-fib.c * Author: Joshua Berke * Class: cs 113 * Assignment: Chapter 4, Exercise 9 * Due Date: September 20 * Last modified: September 19 * ----------------------------------------------------- * * USAGE: * ====== * User must enter an integer between 0 and 10,000. * * OVERVIEW: * ========= * The program will display all The Fibonacci numbers less than a user set * limit. * * Algorithm Notes: * ================ * I used a cascading if in main to detemrine if the number inputed by the * user is an acceptable number. Then I transfered the integer finalTerm to * the function Calculations. There I used a switch to output the first two * terms of the sequence. The default of the switch is where any term * greater than 1 or 0 are calculated and printed. I used a for loop to * find all the numbers. I had one problem where the program printed one * two many terms. To correct this I added an if statemnt in front of the * print statment. After it is done it returns to main and quits. * * Known Bugs: * =========== * none * * Error Handling: * =============== * If the user inputs a negative number it lets them know that there are no * Fibonacci numbers which are negative. Also if the user inputs a number * greater than 10,000 it lets them know that the program is not designed * to handle an upper limit which is greater than 10,000. * * Other Comments: * =============== * none */ #include #include "genlib.h" #include "simpio.h" void Calculations(int); int main() { int finalTerm; /* Upper limit */ printf("Please enter the greatest value of the Fibonacci sequence" "\nthat you wish to find. The value must betwen 0 and 10,000 "); finalTerm = GetInteger(); /* If determines if the number inputed by user is acceptable and if so * it passes the limit to Calculations. If it is not the program ends, * but with a message why */ if(finalTerm < 0) printf("There are no Fibonnaci numbers less than 0\n"); else if(finalTerm > 10000) printf("The program does not work for any Integer over 10,000\n"); else Calculations(finalTerm); return 0; } /* * Function: Calculations * Usage: Calculate and output the series of numbers * ------------------------------------------------- * This function contains the heart of the program. In it is a for loop * which will aid in calculating the correct amount of numbers. * The function does recieve the variable finalTerm form the main function, * but it does not return any value. */ void Calculations(int finalTerm) { /* The integer number is used to count the number of terms. Value is the * total of value1 + value2, which is what the function finds. */ int number, value, value1, value2; /* Must clear previous memory inorder to get correct answers */ value1 = 0; value2 = 1; /* This is to reset the counter to 2 since the loop it is in starts at 2 */ number = 2; /* Switch if f(0) or f(1) should be displayed or more */ switch(finalTerm){ case 0: printf("\nf(0) = 0\n"); break; case 1: printf("f(0) = 0\nf(1) = 1\n"); break; default: printf("f(0) = 0\nf(1) = 1\n"); for(value = 0; value < finalTerm;){ value = value1 + value2; /* Determines actual value of f(number) */ if(value < finalTerm) /* Will print numbers to high if not here */ printf("f(%d) = %d\n", number, value); value1 = value2; /* Holds previous values for use in next loop */ value2 = value; number++; /* Counts the number of terms */ } break; } } /* * File: hw2-weight.c * Author: Joshua Berke * Class: cs113, Fall 96 * Assignment: Modify HW1 #2 (Chapter 2, Exercise 9) * Due Date: Friday, September 20 * Last modified: Thursday, September 19 * ----------------------------------------------------- * * USAGE: * ====== * The user may enter any real positive number. The number will be * converted to pounds and ounces and the user will be prompted to * input another number. If the user wants to quit he enters 0. * Entering a negative number will also exit the program. * * OVERVIEW: * ========= * This is designed to convert a user inputed weight of kilograms * into Pounds and ounces. * * Algorithm Notes: * ================ * There is a while loop in the main function which will loop the program. * I also added a cascading if statement which has an safety measure so * that no negative numbers can be entered. If the number is not equall to * then main will pass kilogram to Calculations where it is converted to * pounds and ounces and displayed. If kilogram is equall to zero the * program continues and ends. * * Known Bugs: none * =============== * * Error Handling: * =============== * If the user inputs a negative the program will display a message that * weights can not be negative numbers and the program will quit. */ #include #include "genlib.h" #include "simpio.h" void Calculations(float); int main() { float kilogram; /* User inputed weight */ while(kilogram != 0.0){ /* Loops to the calculations untill o is entered */ printf("\nPlease input weight in kilograms or 0 to exit: "); kilogram = GetReal(); /* User inputs weight */ if(kilogram < 0){ printf("Weights can't be negative numbers\n"); break; } else if(kilogram != 0) Calculations(kilogram); } return 0; /* Program ended sucesfully */ } /* * Function: Calculations * Usage: Convert old weights and output new ones * ---------------------------------------------- * This function returns no values but receives a float which is the user * inputed weight in kilograms. After the weight in kilograms is converted * to pounds and ounces, the program displays them and then will return to * main where the program will loop again. */ void Calculations(float kilogram) { float ounce, totalOunces; /* Variables are weight measurments */ int pound; pound = kilogram * 2.2; /* The next three lines convert the weight */ totalOunces = kilogram * 35.2; ounce = totalOunces - (float)pound * 16; printf("\n%g kilograms is %d pounds and %g ounces\n", kilogram, pound, ounce); } /* * File: hw2-exp.c * Author: Joshua Berke * Class: cs 113 * Assignment: Chapter 5 exercise 6 * Due Date: September, 20 * Last modified: September, 19 * ----------------------------------------------------- * * USAGE: * ====== * The user has to do nothing. * * OVERVIEW: * ========= * This program will print out a chart of 10 raised to the powers between * -4 and 4. * * Algorithm Notes: * ================ * In main I decided to use to for loops to print the chart out. I did this * in order to make the cleanest looking chart. The main algorithim is in * the function RaiseRealToPower. There I decided to raise all the negative * powers seperately from the positive ones. I then used a for loop to * multiply x by its self. Then I divided 1 by the product. This finds any * number which is raised to a negative. I continued with a cascading if to * see if the number was to be raised to 0. If that is the case then it is * automaticly one. I used another for loop to find the positive integers * * Known Bugs: * =========== * none * * Enhancements: * ============= * One thing that would add to the program is let the user decide what * numbers he would like raised. * * Other Comments: * =============== * none */ #include #include "genlib.h" #include "simpio.h" float RaiseRealToPower(float, int); int main() { int k; /* i is a looping varible. is the power x is being raised to */ float x, power; /* is the number being raised */ x = 10; /* Sets x = to 10 */ printf(" k"); /* The start of the graph */ printf("\n k 10"); printf("\n--------------"); /* First for loop to print the powers less than 0 */ for(k = -4; k < 0; k++){ power = RaiseRealToPower(x,k); printf("\n%2d %g", k, power); } /* Second for loop to print powers from 0-4 */ for(k = 0; k <= 4; k++){ power = RaiseRealToPower(x,k); printf("\n%2d%10.1f", k, power); } return 0; /* End of program */ } /* Function: RaiseRealToPower * Usage: Raises any float to any integer power * -------------------------------------------- * This function receives a float x and an integer k from a previous function. * The function then raises the x to the k power and returns it in the form * of a float. It uses a cascading if to seprate the negative powers, 0, and * positive powers. While the for loops multiply x by itself. Quotient is * used to help find the answer to a negative power. Since x to the -1 is 1/x * quotient represents the x. Finally the last part of the if will set * power to 1 if k is 0. */ float RaiseRealToPower(float x, int k) { /* The answer of x raised to the k power */ /* Quotient is used for figuring a negative power, i is a help with loops*/ int i; float quotient, power; /* Clearing previous memory and getting variables ready for use */ power = x; quotient = x; if(k < 0){ /* If power is negative */ k = k * -1; for(i = 1; i < k; i++) quotient = quotient * x; power = 1 / quotient; } else if(k > 0){ /* If power is positive */ for(i = 1; i < k; i++) power = power * x; } else if(k == 0) /* If power is 0 */ power = 1; return power; /* Returns power to wherever it was called from */ } -- END OF LOG FILE FOR jberke --