#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 2_11a.c 2_11a.cmp 2_11a1.c 2_11atst.c 2_11b.c 2_11b.cmp 2_11b1.c 2_11btst.c makefile # # 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 22:55:18 EDT 1990 # echo x - 2_11a.c sed 's/^X//' > 2_11a.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // swap two integers // version 1 void swapints(int *a, int *b) { int t = *a; *a = *b; *b = t; } !EOF! ls -l 2_11a.c echo x - 2_11a.cmp sed 's/^X//' > 2_11a.cmp << '!EOF!' a = 1, b = 2 a = 2, b = 1 a = 1, b = 1 a = 1, b = 1 a = 0, b = 1 a = 1, b = 0 !EOF! ls -l 2_11a.cmp echo x - 2_11a1.c sed 's/^X//' > 2_11a1.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ swapints(&s, &t); !EOF! ls -l 2_11a1.c echo x - 2_11atst.c sed 's/^X//' > 2_11atst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include #include "2_11a.c" main() { int a = 1, b = 2; cout << "a = " << a << ", b = " << b << "\n"; swapints(&a, &b); cout << "a = " << a << ", b = " << b << "\n"; a = 1, b = 1; cout << "a = " << a << ", b = " << b << "\n"; swapints(&a, &b); cout << "a = " << a << ", b = " << b << "\n"; a = 0, b = 1; cout << "a = " << a << ", b = " << b << "\n"; swapints(&a, &b); cout << "a = " << a << ", b = " << b << "\n"; return 0; } !EOF! ls -l 2_11atst.c echo x - 2_11b.c sed 's/^X//' > 2_11b.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // swap two integers // version 2 void swapints(int &a, int &b) { int t = a; a = b; b = t; } !EOF! ls -l 2_11b.c echo x - 2_11b.cmp sed 's/^X//' > 2_11b.cmp << '!EOF!' a = 1, b = 2 a = 2, b = 1 a = 1, b = 1 a = 1, b = 1 a = 0, b = 1 a = 1, b = 0 !EOF! ls -l 2_11b.cmp echo x - 2_11b1.c sed 's/^X//' > 2_11b1.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ swapints(s, t); !EOF! ls -l 2_11b1.c echo x - 2_11btst.c sed 's/^X//' > 2_11btst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include #include "2_11b.c" main() { int a = 1, b = 2; cout << "a = " << a << ", b = " << b << "\n"; swapints(a, b); cout << "a = " << a << ", b = " << b << "\n"; a = 1, b = 1; cout << "a = " << a << ", b = " << b << "\n"; swapints(a, b); cout << "a = " << a << ", b = " << b << "\n"; a = 0, b = 1; cout << "a = " << a << ", b = " << b << "\n"; swapints(a, b); cout << "a = " << a << ", b = " << b << "\n"; return 0; } !EOF! ls -l 2_11btst.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC all: 2_11atst 2_11btst 2_11atst: 2_11atst.c 2_11a.c $(CC) 2_11atst.c -o 2_11atst 2_11btst: 2_11btst.c 2_11b.c $(CC) 2_11btst.c -o 2_11btst test: all 2_11a.cmp 2_11b.cmp 2_11atst > 2_11a.out cmp 2_11a.out 2_11a.cmp 2_11btst > 2_11b.out cmp 2_11b.out 2_11b.cmp echo tests done !EOF! ls -l makefile # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0