#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 7_5a1_line.c 7_5a1_rect.c 7_5a2_line.c 7_5a2_rect.c 7_5a3_line.c 7_5bline.c 7_5brect.c line.h makefile rectangle.h tst.c # # 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:10:37 EDT 1990 # echo x - 7_5a1_line.c sed 's/^X//' > 7_5a1_line.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Exercise 7.5 // Rectangle derived from a line. // The data is in the public name space. class line : public shape { public: /* do not use this data unless you really have to */ point w, e; point north(); point east(); point south(); point west(); void move(int a, int b); void draw(); line(point a, point b); line(point a, int l); }; !EOF! ls -l 7_5a1_line.c echo x - 7_5a1_rect.c sed 's/^X//' > 7_5a1_rect.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Exercise 7.5 // rectangle derived from a line class rectangle : public line { public: point north() { return point((w.x+e.x)/2,e.y); } point east(); point south() { return point((w.x+e.x)/2,w.y); } point west(); point neast() { return e; } point seast(); point swest() { return w; } point nwest(); void draw(); rectangle(point a, point b); }; !EOF! ls -l 7_5a1_rect.c echo x - 7_5a2_line.c sed 's/^X//' > 7_5a2_line.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Exercise 7.5 // Rectangle derived from a line. // The data is private but available // to class rectangle. class line : public shape { point w, e; friend class rectangle; public: point north(); point east(); point south(); point west(); void move(int a, int b); void draw(); line(point a, point b); line(point a, int l); }; !EOF! ls -l 7_5a2_line.c echo x - 7_5a2_rect.c sed 's/^X//' > 7_5a2_rect.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Exercise 7.5 // rectangle derived from a line class rectangle : public line { point &sw() { return w; } point &ne() { return e; } public: point north() { return point((sw().x+ne().x)/2,ne().y); } point east(); point south() { return point((sw().x+ne().x)/2,sw().y); } point west(); point neast() { return ne(); } point seast(); point swest() { return sw(); } point nwest(); void draw(); rectangle(point a, point b); }; !EOF! ls -l 7_5a2_rect.c echo x - 7_5a3_line.c sed 's/^X//' > 7_5a3_line.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Exercise 7.5 // Rectangle derived from a line. // the data in available to derived classes, // but otherwise private. class line : public shape { protected: point w, e; public: point north(); point east(); point south(); point west(); void move(int a, int b); void draw(); line(point a, point b); line(point a, int l); }; !EOF! ls -l 7_5a3_line.c echo x - 7_5bline.c sed 's/^X//' > 7_5bline.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Exercise 7.5 // rectangle derived from a line class line : public rectangle { point &w() { return sw; } point &e() { return ne; } public: point north() { return point((w().x+e().x)/2, e().y 7_5brect.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // Exercise 7.5 // rectangle derived from a line class rectangle : public shape { point sw, ne; friend class line; public: point north() { return point((sw.x+ne.x)/2,ne.y); } point east(); point south() { return point((sw.x+ne.x)/2,sw.y); } point west(); point neast() { return ne; } point seast(); point swest() { return sw; } point nwest(); void draw(); void move(int a, int b) { sw.x+=a; sw.y+=b; ne.x+=a; ne.y+=b; } rectangle(point a, point b); }; !EOF! ls -l 7_5brect.c echo x - line.h sed 's/^X//' > line.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class line; class rectangle; #ifdef A1L #include "7_5a1_line.c" // class line : public shape #endif #ifdef A2L #include "7_5a2_line.c" // class line : public shape #endif #ifdef A3L #include "7_5a3_line.c" // class line : public shape #endif #ifdef BL #include "7_5bline.c" // class line : public shape #endif !EOF! ls -l line.h echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../shape -I../../CC CFLAGS= all: ta1l1r.o ta2l1r.o ta3l1r.o ta1l2r.o ta2l2r.o ta3l2r.o tbl.o ta1l1r.o: tst.c 7_5a1_line.c 7_5a1_rect.c $(CC) $(CFLAGS) -DA1L -DA1R -c tst.c mv tst.o ta1l1r.o ta2l1r.o: tst.c 7_5a2_line.c 7_5a1_rect.c $(CC) $(CFLAGS) -DA2L -DA1R -c tst.c mv tst.o ta2l1r.o ta3l1r.o: tst.c 7_5a3_line.c 7_5a1_rect.c $(CC) $(CFLAGS) -DA3L -DA1R -c tst.c mv tst.o ta3l1r.o ta1l2r.o: tst.c 7_5a1_line.c 7_5a2_rect.c $(CC) $(CFLAGS) -DA1L -DA2R -c tst.c mv tst.o ta1l2r.o ta2l2r.o: tst.c 7_5a2_line.c 7_5a2_rect.c $(CC) $(CFLAGS) -DA2L -DA2R -c tst.c mv tst.o ta2l2r.o ta3l2r.o: tst.c 7_5a3_line.c 7_5a2_rect.c $(CC) $(CFLAGS) -DA3L -DA2R -c tst.c mv tst.o ta3l2r.o tbl.o: tst.c 7_5brect.c 7_5bline.c $(CC) $(CFLAGS) -DBL -DRECTFIRST -c tst.c mv tst.o tbl.o test: all @echo test done !EOF! ls -l makefile echo x - rectangle.h sed 's/^X//' > rectangle.h << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ class line; class rectangle; #ifdef A1R #include "7_5a1_rect.c" // class rectangle : public line #endif #ifdef A2R #include "7_5a2_rect.c" // class rectangle : public line #endif #ifdef BL #include "7_5brect.c" // class rectangle : public line #endif !EOF! ls -l rectangle.h echo x - tst.c sed 's/^X//' > tst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ #include "shape.h" !EOF! ls -l tst.c # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0