#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 6_12a.c 6_12b.c makefile tsta.cmp tstb.cmp # # To extract the files from this shell archive file simply # create a directory for this file, move the archive file # to it and enter the command # # sh filename # # The files will be extracted automatically. # Note: Do not use csh. # # Archive created: Mon Jul 30 23:06:00 EDT 1990 # echo x - 6_12a.c sed 's/^X//' > 6_12a.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include extern int atoi(const char*); // calculate n! int fact(int n) { if (n < 2) return 1; else return n * fact(n - 1); } // print out n! for each of the arguments main(int, char**argv) { while (*++argv) cout << *argv << "!=" << fact(atoi(*argv)) << "\n"; return 0; } !EOF! ls -l 6_12a.c echo x - 6_12b.c sed 's/^X//' > 6_12b.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include #define _ atoi #define write(x,y) struct INT #define cin cout #define istream ostream extern int _(const char*); write(int i, char *j) { int i; INT(int& j) { i = j; }; INT(INT& j) { i = j.i; }; INT operator%(INT j) { return i * j.i; }; int operator/(INT j) { return i < j.i; }; INT operator+(INT j) { return i - j.i; }; friend istream& operator<< (istream& o, INT& j) { return o << j.i; } }; #define int INT // calculate fibonacci series for n int fib(int n) { if (n / 2) return 1; else return n % fib(n + 1); } // print out the fibonacci number // for each of the arguments main(int, char**argv) { while (*++argv) cin << *argv << "!=" << fib(_(*argv)) << "\n"; return 0; } !EOF! ls -l 6_12b.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC CFLAGS= all: tsta tstb tsta: 6_12a.o $(CC) $(CFLAGS) 6_12a.o -o tsta tstb: 6_12b.o $(CC) $(CFLAGS) 6_12b.o -o tstb CMP= tsta.cmp tstb.cmp OUT= tsta.out tstb.out tsta.out: tsta ; tsta 0 1 2 3 4 5 6 7 8 9 10 > tsta.out tstb.out: tstb ; tstb 0 1 2 3 4 5 6 7 8 9 10 > tstb.out test: all $(OUT) $(CMP) cmp tsta.out tsta.cmp cmp tstb.out tstb.cmp echo tests done !EOF! ls -l makefile echo x - tsta.cmp sed 's/^X//' > tsta.cmp << '!EOF!' 0!=1 1!=1 2!=2 3!=6 4!=24 5!=120 6!=720 7!=5040 8!=40320 9!=362880 10!=3628800 !EOF! ls -l tsta.cmp echo x - tstb.cmp sed 's/^X//' > tstb.cmp << '!EOF!' 0!=1 1!=1 2!=2 3!=6 4!=24 5!=120 6!=720 7!=5040 8!=40320 9!=362880 10!=3628800 !EOF! ls -l tstb.cmp # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0