📄 programs.shar
字号:
fiif test -f 'programs/02-Learning-by-Example/inchtocm.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/02-Learning-by-Example/inchtocm.c'\"elseecho shar: Extracting \"'programs/02-Learning-by-Example/inchtocm.c'\" \(432 characters\)sed "s/^X//" >'programs/02-Learning-by-Example/inchtocm.c' <<'END_OF_FILE'X/*X * File: inchtocm.cX * ----------------X * This program reads in a length given in inches and converts itX * to its metric equivalent in centimeters.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X double inch, cm;XX printf("This program converts inches to centimeters.\n");X printf("Length in inches? ");X inch = GetReal();X cm = inch * 2.54;X printf("%g in = %g cm\n", inch, cm);X}END_OF_FILEif test 432 -ne `wc -c <'programs/02-Learning-by-Example/inchtocm.c'`; then echo shar: \"'programs/02-Learning-by-Example/inchtocm.c'\" unpacked with wrong size!fi# end of 'programs/02-Learning-by-Example/inchtocm.c'fiif test -f 'programs/03-Problem-Solving/Makefile' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/Makefile'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/Makefile'\" \(1866 characters\)sed "s/^X//" >'programs/03-Problem-Solving/Makefile' <<'END_OF_FILE'X# Makefile for cbook/03-Problem-Solving/programsX# Created by the ExportAll facilityX# ***************************************************************XXPROGRAMS = \X count10 \X add10 \X addlist \X balance1 \X balance2 \X balance3 \X balance4 \X roses XX# ***************************************************************X# Parameters to control Makefile operationX# Note that the gccx command script must be definedXXCC = gccxXCFLAGS = XX# ***************************************************************X# Entry to bring the package up to dateXXall: $(PROGRAMS)XX# ***************************************************************X# Standard entries to remove files from the directoriesX# tidy -- eliminate unwanted filesX# scratch -- delete derived files in preparation for rebuildXXtidy:X rm -f ,* .,* *~ core a.out graphics.psXXscratch: tidyX rm -f *.o *.a $(PROGRAMS)XX# ***************************************************************X# C compilationsXXcount10.o: count10.cX $(CC) $(CFLAGS) -c count10.cXXadd10.o: add10.cX $(CC) $(CFLAGS) -c add10.cXXaddlist.o: addlist.cX $(CC) $(CFLAGS) -c addlist.cXXbalance1.o: balance1.cX $(CC) $(CFLAGS) -c balance1.cXXbalance2.o: balance2.cX $(CC) $(CFLAGS) -c balance2.cXXbalance3.o: balance3.cX $(CC) $(CFLAGS) -c balance3.cXXbalance4.o: balance4.cX $(CC) $(CFLAGS) -c balance4.cXXroses.o: roses.cX $(CC) $(CFLAGS) -c roses.cXXXcount10: count10.oX $(CC) $(CFLAGS) -o count10 count10.oXXadd10: add10.oX $(CC) $(CFLAGS) -o add10 add10.oXXaddlist: addlist.oX $(CC) $(CFLAGS) -o addlist addlist.oXXbalance1: balance1.oX $(CC) $(CFLAGS) -o balance1 balance1.oXXbalance2: balance2.oX $(CC) $(CFLAGS) -o balance2 balance2.oXXbalance3: balance3.oX $(CC) $(CFLAGS) -o balance3 balance3.oXXbalance4: balance4.oX $(CC) $(CFLAGS) -o balance4 balance4.oXXroses: roses.oX $(CC) $(CFLAGS) -o roses roses.oEND_OF_FILEif test 1866 -ne `wc -c <'programs/03-Problem-Solving/Makefile'`; then echo shar: \"'programs/03-Problem-Solving/Makefile'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/Makefile'fiif test -f 'programs/03-Problem-Solving/add10.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/add10.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/add10.c'\" \(573 characters\)sed "s/^X//" >'programs/03-Problem-Solving/add10.c' <<'END_OF_FILE'X/*X * File: add10.cX * -------------X * This program adds a list of ten numbers, printingX * the total at the end. Instead of reading the numbersX * into separate variables, this program reads in eachX * number and adds it to a running total.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X int i, value, total;XX printf("This program adds a list of ten numbers.\n");X total = 0;X for (i = 0; i < 10; i++) {X printf(" ? ");X value = GetInteger();X total += value;X }X printf("The total is %d\n", total);X}END_OF_FILEif test 573 -ne `wc -c <'programs/03-Problem-Solving/add10.c'`; then echo shar: \"'programs/03-Problem-Solving/add10.c'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/add10.c'fiif test -f 'programs/03-Problem-Solving/addlist.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/addlist.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/addlist.c'\" \(541 characters\)sed "s/^X//" >'programs/03-Problem-Solving/addlist.c' <<'END_OF_FILE'X/*X * File: addlist.cX * ---------------X * This program adds a list of numbers. The end of theX * input is indicated by entering 0 as a sentinel value.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X int value, total;XX printf("This program adds a list of numbers.\n");X printf("Signal end of list with a 0.\n");X total = 0;X while (TRUE) {X printf(" ? ");X value = GetInteger();X if (value == 0) break;X total += value;X }X printf("The total is %d\n", total);X}END_OF_FILEif test 541 -ne `wc -c <'programs/03-Problem-Solving/addlist.c'`; then echo shar: \"'programs/03-Problem-Solving/addlist.c'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/addlist.c'fiif test -f 'programs/03-Problem-Solving/balance1.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/balance1.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/balance1.c'\" \(972 characters\)sed "s/^X//" >'programs/03-Problem-Solving/balance1.c' <<'END_OF_FILE'X/*X * File: balance1.cX * ----------------X * This file contains the first version of a program toX * balance a checkbook. The user enters checks and depositsX * throughout the month (checks are entered as negativeX * numbers). The end of the input is indicated by enteringX * 0 as a sentinel value.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X double entry, balance;XX printf("This program helps you balance your checkbook.\n");X printf("Enter each check and deposit during the month.\n");X printf("To indicate a check, use a minus sign.\n");X printf("Signal the end of the month with a 0 value.\n");X printf("Enter the initial balance: ");X balance = GetReal();X while (TRUE) {X printf("Enter check (-) or deposit: ");X entry = GetReal();X if (entry == 0) break;X balance += entry;X printf("Current balance = %g\n", balance);X }X printf("Final balance = %g\n", balance);X}END_OF_FILEif test 972 -ne `wc -c <'programs/03-Problem-Solving/balance1.c'`; then echo shar: \"'programs/03-Problem-Solving/balance1.c'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/balance1.c'fiif test -f 'programs/03-Problem-Solving/balance2.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/balance2.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/balance2.c'\" \(926 characters\)sed "s/^X//" >'programs/03-Problem-Solving/balance2.c' <<'END_OF_FILE'X/*X * File: balance2.cX * ----------------X * This file contains a buggy second attempt at a program toX * balance a checkbook.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X double entry, balance;XX printf("This program helps you balance your checkbook.\n");X printf("Enter each check and deposit during the month.\n");X printf("To indicate a check, use a minus sign.\n");X printf("Signal the end of the month with a 0 value.\n");X printf("Enter the initial balance: ");X balance = GetReal();X while (TRUE) {X printf("Enter check (-) or deposit: ");X entry = GetReal();X if (entry == 0) break;X balance += entry;X if (balance < 0) {X printf("This check bounces. $10 fee deducted.\n");X balance -= 10;X }X printf("Current balance = %g\n", balance);X }X printf("Final balance = %g\n", balance);X}END_OF_FILEif test 926 -ne `wc -c <'programs/03-Problem-Solving/balance2.c'`; then echo shar: \"'programs/03-Problem-Solving/balance2.c'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/balance2.c'fiif test -f 'programs/03-Problem-Solving/balance3.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/balance3.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/balance3.c'\" \(982 characters\)sed "s/^X//" >'programs/03-Problem-Solving/balance3.c' <<'END_OF_FILE'X/*X * File: balance3.cX * ----------------X * This file contains a corrected version of a program toX * balance a checkbook, including a working bounced-checkX * feature.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XXmain()X{X double entry, balance;XX printf("This program helps you balance your checkbook.\n");X printf("Enter each check and deposit during the month.\n");X printf("To indicate a check, use a minus sign.\n");X printf("Signal the end of the month with a 0 value.\n");X printf("Enter the initial balance: ");X balance = GetReal();X while (TRUE) {X printf("Enter check (-) or deposit: ");X entry = GetReal();X if (entry == 0) break;X balance += entry;X if (balance < 0 && entry < 0) {X printf("This check bounces. $10 fee deducted.\n");X balance -= 10;X }X printf("Current balance = %g\n", balance);X }X printf("Final balance = %g\n", balance);X}END_OF_FILEif test 982 -ne `wc -c <'programs/03-Problem-Solving/balance3.c'`; then echo shar: \"'programs/03-Problem-Solving/balance3.c'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/balance3.c'fiif test -f 'programs/03-Problem-Solving/balance4.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/balance4.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/balance4.c'\" \(1288 characters\)sed "s/^X//" >'programs/03-Problem-Solving/balance4.c' <<'END_OF_FILE'X/*X * File: balance4.cX * ----------------X * This file contains the final version of a program toX * balance a checkbook.X */XX#include <stdio.h>X#include "genlib.h"X#include "simpio.h"XX/*X * Constant: BouncedCheckFeeX * -------------------------X * To change the charge assessed for bounced checks, changeX * the definition of this constant. The constant must be aX * floating-point value (i.e., must contain a decimal point).X */XX#define BouncedCheckFee 10.00XX/* Main program */XXmain()X{X double entry, balance;XX printf("This program helps you balance your checkbook.\n");X printf("Enter each check and deposit during the month.\n");X printf("To indicate a check, use a minus sign.\n");X printf("Signal the end of the month with a 0 value.\n");X printf("Enter the initial balance: ");X balance = GetReal();X while (TRUE) {X printf("Enter check (-) or deposit: ");X entry = GetReal();X if (entry == 0) break;X balance += entry;X if (entry < 0 && balance < 0) {X printf("This check bounces. $%.2f fee deducted.\n",X BouncedCheckFee);X balance -= BouncedCheckFee;X }X printf("Current balance = %.2f\n", balance);X }X printf("Final balance = %.2f\n", balance);X}END_OF_FILEif test 1288 -ne `wc -c <'programs/03-Problem-Solving/balance4.c'`; then echo shar: \"'programs/03-Problem-Solving/balance4.c'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/balance4.c'fiif test -f 'programs/03-Problem-Solving/count10.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/count10.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/count10.c'\" \(252 characters\)sed "s/^X//" >'programs/03-Problem-Solving/count10.c' <<'END_OF_FILE'X/*X * File: count10.cX * ---------------X * This program counts from 1 to 10, displaying each numberX * on the screen.X */XX#include <stdio.h>X#include "genlib.h"XXmain()X{X int i;XX for (i = 1; i <= 10; i++) {X printf("%d\n", i);X }X}END_OF_FILEif test 252 -ne `wc -c <'programs/03-Problem-Solving/count10.c'`; then echo shar: \"'programs/03-Problem-Solving/count10.c'\" unpacked with wrong size!fi# end of 'programs/03-Problem-Solving/count10.c'fiif test -f 'programs/03-Problem-Solving/roses.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'programs/03-Problem-Solving/roses.c'\"elseecho shar: Extracting \"'programs/03-Problem-Solving/roses.c'\" \(285 characters\)sed "s/^X//" >'programs/03-Problem-Solving/roses.c' <<'END_OF_FILE'X/*X * File: roses.cX * -------------X * This program prints out the Gertrude Stein quotationX * "a rose is a rose is a rose".X */XX#include <stdio.h>X#include "genlib.h"XXmain()X{X int i;XX for (i = 0; i < 2; i++) {X printf("a rose is ");X }X printf("a rose.\n");X}END_OF_FILEif test 285 -ne `wc -c <'programs/03-Problem-Solving/roses.c'`; then echo shar: \"'programs/03-Problem-Solving/roses.c'\" unpacked with wrong size!fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -