Grading Log for CS113 -- HW1 Name: Perng, Tiffany SCRIPT FILES ====== ===== h1p1.scr =================================================== > Script started on Sat Jan 16 18:26:08 1999 > %cat h1p1.c > /*********************** > * File name: h1p1.c * > * Name: Tiffany Perng * > * Assignment: 1 * > * Problem: 1 * > * Date: Jan 14, 1999 * > ***********************/ > > /********************************************************************* > * This C program takes as input some number of seconds and converts * > * this input to the number of hours, minutes and seconds. * > *********************************************************************/ > > #include > #define SENTINEL -1 /* program stops when user input equals sentinel */ > > int main (void) > { > int input, hours, minutes, seconds, temp; > > printf("\nThis program converts the number of seconds to the\n"); > printf("corresponding number of hours, minutes, and seconds.\n"); > > /* The do-while loop will continue to run until the user enters a -1 */ > > do > { > printf("\nEnter -1 to stop program...\n"); > printf("Please input the number of seconds: "); > scanf("%d", &input); > > if (input != SENTINEL) > { > /* This next section is for converting the input into hours, > minutes and seconds without losing the input value. */ > > temp = input; > hours = temp / 3600; > temp = temp - (3600 * hours); > minutes = temp / 60; > temp = temp - (60 * minutes); > seconds = temp; > > /* This section of the program prints out the original input as > well as the appropriate output. For example, if a value is 0, > like 0 hours, then it's not printed. */ > > printf("\nThe input %d seconds is equivalent to\n", input); > > if (hours > 1) > printf("%d hours ", hours); > else if (hours == 1) > printf("%d hour ", hours); > > if (minutes > 1) > printf("%d minutes ", minutes); > else if (minutes == 1) > printf("%d minute ", minutes); > > if (seconds > 1) > printf("%d seconds", seconds); > else if (seconds == 1) > printf("%d second", seconds); > > if (input == 0) > printf("%d seconds", seconds); > printf("\n"); > } > > else > printf("\nYou've exited the program.\n"); > } while (input != SENTINEL); > > return 0; > } > %gcc -ansi -pedantic -Wall h1p1.c > %a.out < data1 > > This program converts the number of seconds to the > corresponding number of hours, minutes, and seconds. > > Enter -1 to stop program... > Please input the number of seconds: > The input 4250 seconds is equivalent to > 1 hour 10 minutes 50 seconds > > Enter -1 to stop program... > Please input the number of seconds: > The input 17567 seconds is equivalent to > 4 hours 52 minutes 47 seconds > > Enter -1 to stop program... > Please input the number of seconds: > The input 89 seconds is equivalent to > 1 minute 29 seconds > > Enter -1 to stop program... > Please input the number of seconds: > The input 0 seconds is equivalent to > 0 seconds > > Enter -1 to stop program... > Please input the number of seconds: > The input 1920 seconds is equivalent to > 32 minutes > > Enter -1 to stop program... > Please input the number of seconds: > The input 1 seconds is equivalent to > 1 second > > Enter -1 to stop program... > Please input the number of seconds: > You've exited the program. > %exit > exit > > script done on Sat Jan 16 18:27:12 1999 h1p2.scr =================================================== > Script started on Sun Jan 24 00:53:39 1999 > %cat h1p2.c > /*********************** > * File name: h1p2.c * > * Name: Tiffany Perng * > * Assignment: 1 * > * Problem: 2 * > * Date: Jan 24, 1999 * > ***********************/ > > /************************************************************************ > * This C program takes as input the account balance of a bank customer * > * and determines if the balance is overdrawn. * > ************************************************************************/ > > #include > #define SENTINEL -1 /* Program ends when input equals SENTINEL */ > > int main() > { > int account_number, old_balance, debits, credits, final_balance; > > printf("\nThis program determines if a bank balance if overdrawn.\n"); > > /* This do-while loop countinues to take inputs and process the account > balance until the user inputs a value equal to SENTINEL */ > do > { > printf("\nPlease enter %d to stop program.\n", SENTINEL); > > printf("Enter Account Number: \n"); > scanf("%d", &account_number); > > if (account_number != SENTINEL) > { > printf("Balance at beginning of month: $\n"); > scanf("%d", &old_balance); > printf("Total of all debits this month: $\n"); > scanf("%d", &debits); > printf("Total of all credits this month: $\n"); > scanf("%d", &credits); > > /* Calculates the account balance at the end of the month */ > final_balance = old_balance - debits + credits; > > printf("\nAccount number %d ", account_number); > printf("has a final balance of %d.\n", final_balance); > > /* This if-statement notifies the customer when account is > overdrawn */ > if (final_balance < 0) > printf("YOUR ACCOUNT IS OVERDRAWN!\n"); > } > } while (account_number != SENTINEL); > > printf("\nYou've exited the program.\n"); > > return 0; > } > %cg h1p2.c > %a.out < data2 > > This program determines if a bank balance if overdrawn. > > Please enter -1 to stop program. > Enter Account Number: > Balance at beginning of month: $ > Total of all debits this month: $ > Total of all credits this month: $ > > Account number 19836 has a final balance of 940. > > Please enter -1 to stop program. > Enter Account Number: > Balance at beginning of month: $ > Total of all debits this month: $ > Total of all credits this month: $ > > Account number 94738 has a final balance of -100. > YOUR ACCOUNT IS OVERDRAWN! > > Please enter -1 to stop program. > Enter Account Number: > Balance at beginning of month: $ > Total of all debits this month: $ > Total of all credits this month: $ > > Account number 938261 has a final balance of 1400. > > Please enter -1 to stop program. > Enter Account Number: > Balance at beginning of month: $ > Total of all debits this month: $ > Total of all credits this month: $ > > Account number 111938 has a final balance of 11223. > > Please enter -1 to stop program. > Enter Account Number: > Balance at beginning of month: $ > Total of all debits this month: $ > Total of all credits this month: $ > > Account number 382983 has a final balance of -2627. > YOUR ACCOUNT IS OVERDRAWN! > > Please enter -1 to stop program. > Enter Account Number: > Balance at beginning of month: $ > Total of all debits this month: $ > Total of all credits this month: $ > > Account number 48493839 has a final balance of 1121. > > Please enter -1 to stop program. > Enter Account Number: > > You've exited the program. > %exit > exit > > script done on Sun Jan 24 00:53:55 1999 h1p3.scr =================================================== > Script started on Sun Jan 24 00:11:29 1999 > %cat h1p3.c > /*********************** > * File name: h1p3.c * > * Name: Tiffany Perng * > * Assignment: 1 * > * Problem: 3 * > * Date: Jan 15, 1999 * > ***********************/ > > /********************************************************************* > * This C program reads a binary real number and outputs its decimal * > * value in base-ten. * > *********************************************************************/ > > #include > #include > #define ARRAY_SIZE 80 > > int main (void) > { > int whole, digit, power, i; > char fract[ARRAY_SIZE]; > float base_ten; /* Output after conversion of input to > base ten */ > > /* Initialize all variables, not including arrays */ > whole = 0; > digit = 0; > power = 0; > base_ten = 0.0; > > printf("\nThis program reads in a binary real number and outputs"); > printf("\nits equivalent value in base 10.\n"); > printf("\nInput the binary real number: "); > scanf("%d.%s", &whole, fract); > > /* This loop converts the whole number part of the binary input > to base-ten */ > > while (whole != 0) > { > digit = whole % 10; /* Extract digit from whole number */ > whole = whole - digit; /* These two lines modify the whole # so */ > whole = whole / 10; /* that the next digit can be extracted */ > > /* Convert binary digit to its equivalent value in base-ten and > add it to the answer */ > base_ten = base_ten + digit * pow(2,power); > power++; > } > > /* Converts fraction part of binary number to base-ten and add it to > the answer */ > power = -1; > for (i = 0; fract[i] != '\0'; i++) > { > digit = fract[i] - '0'; > base_ten = base_ten + digit * pow(2,power); > power--; > } > > printf("\nThe number in base ten is %.4f.\n", base_ten); > > return 0; > } > %g h1p3.c -lm > %a.out > > This program reads in a binary real number and outputs > its equivalent value in base 10. > > Input the binary real number: 1011.001 > > The number in base ten is 11.1250. > %a.out > > This program reads in a binary real number and outputs > its equivalent value in base 10. > > Input the binary real number: 110110.0 > > The number in base ten is 54.0000. > %a.out > > This program reads in a binary real number and outputs > its equivalent value in base 10. > > Input the binary real number: 11010.11111 > > The number in base ten is 26.9688. > %a.out > > This program reads in a binary real number and outputs > its equivalent value in base 10. > > Input the binary real number: 100.101 > > The number in base ten is 4.6250. > %a.out > > This program reads in a binary real number and outputs > its equivalent value in base 10. > > Input the binary real number: 11011010.001101 ^H    > > The number in base ten is 218.2031. > %exit > exit > > script done on Sun Jan 24 00:12:41 1999