<< Demo017 >> << Chapter 12: Generic Components >> << Section 12.1: A Generic Stack Component >> << and >> << Section 12.2: Use Directives >> use Stacks( BookStack, Book); type Book = text; S = BookStack(5); S? Push(S,"Peter Pan"); S? Push(S,"Alice in Wonderland"); S? Pull(S)? S? Pull(S)? S? << Stacks of geometric elememts >> type Numeric = real; use Points, Triangles, Circles; use Stacks( Stack_of_Triangles, Triangle); use Stacks( Stack_of_Circles, Circle); ST1 = Stack_of_Triangles(10); ST2 = Stack_of_Triangles(20); ST1? ST2? SC1 = Stack_of_Circles(5); SC2 = Stack_of_Circles(7); SC1? SC2? P1 = Point(3.0, 4.0); P2 = Point(-23.0, 12.0); P3 = Point(12.0, -13.0); Push( ST1, Triangle(P1,P2,P3) ); Push( ST1, Triangle(P3,P2,P1) ); ST1? T2 = Pull( ST1 ); T1 = Pull( ST1 ); ST1? Push( SC1, Circle(P1,15.0) ); C1 = Pull( SC1 ); SC1? << Section 12.3: A Generic Matrix Component >> use Matrices( IntegerMatrix, integer, 0); M1 = IntegerMatrix( 3, 4); M1? IntegerValues = { { 11, 12, 13, 14 }, { 21, 22, 23, 24 }, { 31, 32, 33, 34 }, { 41, 42, 43, 44 }}; Fill( M1, IntegerValues); M1? M2 = M1; M3 = M1 + M2; M3? M4 = IntegerMatrix(4,4); Fill( M4, IntegerValues); M4? M5 = M1 * M4; M5? RealZero := 0.0; use Matrices( RealMatrix, real, 0.0); MR1 = RealMatrix(3,4); MR1? RealValues = { { 11., 12., 13., 14. }, { 21., 22., 23., 24. }, { 31., 32., 33., 34. }, { 41., 42., 43., 44. }}; Fill(MR1,RealValues); MR1? MR2 = MR1; MR3 = MR1 + MR2; MR3? MR4 = RealMatrix(4,4); Fill(MR4,RealValues); MR4? MR5 = MR1 * MR4; MR5?