Grading Log for CS113 -- HW1 Name: Lieberthal, Robert SCRIPT FILES ====== ===== h1p1.scr =================================================== > Script started on Mon Jan 25 21:02:20 1999 > %cat h1p1.c > /* > * File name: h1p1.c > * Name: Robert Lieberthal > * Assignment: 1 > * Problem: 1 > * Date: January 25, 1999 > */ > > #include > > int main(void) > > { > int seconds, storesec, minutes, hours; > printf("Enter the number of seconds:\n"); > scanf("%d", &seconds); > while (seconds >= 0) > { > storesec = seconds; > /* Store the number of seconds entered for the print statement at the end */ > hours = seconds / 3600; > seconds = seconds % 3600; > minutes = seconds / 60; > seconds = seconds % 60; > if (storesec > 1) > printf("%d seconds is equivalent to ", storesec); > else > { > if (storesec == 1) > printf("1 second is equivalent to "); > /* With 1 second there is a special case where the word "second" is used twice" */ > else printf("0 seconds is equivalent to 0 seconds"); > } > /* For hours, minutes, and seconds, determine if singular or plural is needed */ > if (hours > 0) > { > if (hours > 1) > printf("%d hours ", hours); > else printf ("%d hour ", hours); > } > if (minutes > 0) > { > if (minutes > 1) > printf("%d minutes ", minutes); > else printf ("%d minute ", minutes); > } > if (seconds > 0) > { > if (seconds > 1) > printf("%d seconds", seconds); > else printf ("%d second", seconds); > } > printf("\n"); > printf("Enter the number of seconds:\n"); > scanf("%d", &seconds); > } > return 0; > } > %gcc -ansi -pedantic -Wall h1p1.c > %a.out < data1 > Enter the number of seconds: > 4250 seconds is equivalent to 1 hour 10 minutes 50 seconds > Enter the number of seconds: > 17567 seconds is equivalent to 4 hours 52 minutes 47 seconds > Enter the number of seconds: > 89 seconds is equivalent to 1 minute 29 seconds > Enter the number of seconds: > 0 seconds is equivalent to 0 seconds > Enter the number of seconds: > 1920 seconds is equivalent to 32 minutes > Enter the number of seconds: > 1 second is equivalent to 1 second > Enter the number of seconds: > %exit > exit > > script done on Mon Jan 25 21:03:01 1999 h1p2.scr =================================================== > Script started on Mon Jan 25 21:06:32 1999 > %cat h1p2.c > /* > * File name: h1p2.c > * Name: Robert Lieberthal > * Assignment: 1 > * Problem: 2 > * Date: January 25, 1999 > */ > > #include > int main(void) > { > int accnum, balance, debits, credits; > /* Variables for account number, opening balance, the month's debits, and the month's credits */ > printf("Enter the account number, balance, debits, and credits.\n"); > scanf("%d", &accnum); > /* Test account number before trying to scan in other variables */ > while (accnum != -1) > /* End of file test */ > { > scanf("%d%d%d", &balance, &debits, &credits); > balance = balance - debits; > balance = balance + credits; > printf("Account number %d has a balance of %d.\n", accnum, balance); > if (balance < 0) > printf("Your account is overdrawn.\n"); > printf("Enter the account number, balance, debits, and credits.\n"); > scanf("%d", &accnum); > } > return 0; > } > %gcc -ansi -pedantic -Wall h1p2.c > %a.out < data2 > Enter the account number, balance, debits, and credits. > Account number 19836 has a balance of 940. > Enter the account number, balance, debits, and credits. > Account number 94738 has a balance of -100. > Your account is overdrawn. > Enter the account number, balance, debits, and credits. > Account number 938261 has a balance of 1400. > Enter the account number, balance, debits, and credits. > Account number 111938 has a balance of 11223. > Enter the account number, balance, debits, and credits. > Account number 382983 has a balance of -2627. > Your account is overdrawn. > Enter the account number, balance, debits, and credits. > Account number 48493839 has a balance of 1121. > Enter the account number, balance, debits, and credits. > %exit > exit > > script done on Mon Jan 25 21:07:16 1999 h1p3.scr =================================================== > Script started on Mon Jan 25 21:16:28 1999 > %cat h1p3.c > /* > * File name: h1p3.c > * Name: Robert Lieberthal > * Assignment: 1 > * Problem: 3 > * Date: January 25, 1999 > */ > > #include > int main(void) > { > int wholepart, endigit, i; > float result = 0, exponent = 1; > /* Use the variable "exponent" instead of the power function */ > char stringpart[80]; > printf("Enter a binary number.\n"); > scanf("%d.%s", &wholepart, stringpart); > /* The code until the next comment is due to the CS113 web page */ > for (i = 0; stringpart[i] != '\0'; i++) > { > int digit; > exponent = exponent / 2; > digit = stringpart[i] - '0'; > /* End of code from Web Page */ > result = result + (digit * exponent); > } > exponent = 1; > while (wholepart > 0) > { > endigit = wholepart % 10; > /* "endigit represents the rightmost digit of the whole part of the binary number */ > result = result + (endigit * exponent); > wholepart = wholepart / 10; > exponent = exponent * 2; > } > printf("%f\n", result); > return 0; > } > > > > > > > > %gcc -ansi -pedantic -Wall h1p3.c > %a.out > Enter a binary number. > 1011.001 > 11.125000 > %a.out > Enter a binary number. > 110110.0 > 54.000000 > %a.out > Enter a binary number. > 11010.11111 > 26.968750 > %a.out > Enter a binary number. > 100.101 > 4.625000 > %a.out > Enter a binary number. > 11011010.001101 > 218.203125 > %exit > exit > > script done on Mon Jan 25 21:17:41 1999