home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / yamp / string.tex < prev    next >
LaTeX Document  |  1993-01-11  |  4.8 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Corel 10 Texture (image/corel10Texture) ext Unsupported
1% dexvert Croteam texture file (image/croteamTextureFile) ext Unsupported
1% dexvert Text File (text/txt) fallback Supported
100% file C++ source text default
99% file LaTeX document text default
98% file LaTeX document, ASCII text, with CRLF line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CRLF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 63 68 61 70 74 65 72 | 7b 41 20 53 74 72 69 6e |\chapter|{A Strin|
|00000010| 67 20 43 6c 61 73 73 7d | 0d 0a 41 20 73 69 6d 70 |g Class}|..A simp|
|00000020| 6c 65 20 73 74 72 69 6e | 67 20 63 6c 61 73 73 20 |le strin|g class |
|00000030| 77 61 73 20 64 65 76 65 | 6c 6f 70 65 64 20 74 6f |was deve|loped to|
|00000040| 20 6b 65 65 70 20 74 72 | 61 63 6b 20 6f 66 20 74 | keep tr|ack of t|
|00000050| 68 65 0d 0a 6f 70 65 72 | 61 74 69 6f 6e 73 20 6f |he..oper|ations o|
|00000060| 6e 20 61 20 6d 61 74 72 | 69 78 2e 20 54 68 65 20 |n a matr|ix. The |
|00000070| 6d 61 74 72 69 78 20 6e | 61 6d 65 20 69 73 20 70 |matrix n|ame is p|
|00000080| 72 69 76 61 74 65 20 6d | 65 6d 62 65 72 0d 0a 6f |rivate m|ember..o|
|00000090| 66 20 61 20 6d 61 74 72 | 69 78 2c 20 62 75 74 20 |f a matr|ix, but |
|000000a0| 61 64 65 71 75 61 74 65 | 20 61 63 63 65 73 73 20 |adequate| access |
|000000b0| 69 73 20 67 69 76 65 6e | 20 66 6f 72 20 6d 6f 64 |is given| for mod|
|000000c0| 69 66 79 69 6e 67 20 69 | 74 0d 0a 66 72 6f 6d 20 |ifying i|t..from |
|000000d0| 6d 61 74 72 69 78 20 6d | 65 6d 62 65 72 20 63 6c |matrix m|ember cl|
|000000e0| 61 73 73 20 66 75 6e 63 | 74 69 6f 6e 73 2e 20 49 |ass func|tions. I|
|000000f0| 6d 70 6c 65 6d 65 6e 74 | 69 6e 67 20 73 74 72 69 |mplement|ing stri|
|00000100| 6e 67 73 20 61 73 0d 0a | 61 20 63 6c 61 73 73 20 |ngs as..|a class |
|00000110| 61 76 6f 69 64 73 20 73 | 6f 6d 65 20 6f 66 20 74 |avoids s|ome of t|
|00000120| 68 65 20 6f 76 65 72 68 | 65 61 64 20 6e 6f 72 6d |he overh|ead norm|
|00000130| 61 6c 6c 79 20 61 73 73 | 6f 63 69 61 74 65 64 0d |ally ass|ociated.|
|00000140| 0a 77 69 74 68 20 63 68 | 61 72 61 63 74 65 72 20 |.with ch|aracter |
|00000150| 61 72 72 61 79 73 20 69 | 6e 20 43 2e 20 54 68 65 |arrays i|n C. The|
|00000160| 20 61 6c 6c 6f 63 61 74 | 69 6f 6e 20 61 6e 64 20 | allocat|ion and |
|00000170| 6c 65 6e 67 74 68 0d 0a | 63 6f 6e 74 72 6f 6c 20 |length..|control |
|00000180| 69 73 20 65 6e 63 61 70 | 73 75 6c 61 74 65 64 20 |is encap|sulated |
|00000190| 69 6e 20 74 68 65 20 73 | 74 72 69 6e 67 20 6d 65 |in the s|tring me|
|000001a0| 6d 62 65 72 20 66 75 6e | 63 74 69 6f 6e 73 2e 20 |mber fun|ctions. |
|000001b0| 54 68 65 0d 0a 73 74 72 | 69 6e 67 20 63 6c 61 73 |The..str|ing clas|
|000001c0| 73 20 69 73 20 6c 6f 6f | 73 65 6c 79 20 61 73 73 |s is loo|sely ass|
|000001d0| 6f 63 69 61 74 65 64 20 | 77 69 74 68 20 74 68 65 |ociated |with the|
|000001e0| 20 73 74 72 69 6e 67 20 | 63 6c 61 73 73 65 73 0d | string |classes.|
|000001f0| 0a 69 6e 20 53 63 68 69 | 6c 64 74 20 5c 63 69 74 |.in Schi|ldt \cit|
|00000200| 65 7b 73 68 3a 63 2b 2b | 7d 2e 20 0d 0a 0d 0a 5c |e{sh:c++|}. ....\|
|00000210| 73 65 63 74 69 6f 6e 7b | 54 68 65 20 53 74 72 69 |section{|The Stri|
|00000220| 6e 67 20 74 79 70 65 3a | 20 73 74 72 74 79 70 65 |ng type:| strtype|
|00000230| 7d 0d 0a 54 68 65 20 73 | 74 72 69 6e 67 5c 69 6e |}..The s|tring\in|
|00000240| 64 65 78 7b 73 74 72 74 | 79 70 65 20 7d 20 69 73 |dex{strt|ype } is|
|00000250| 20 64 65 63 6c 61 72 65 | 64 20 61 73 0d 0a 5c 62 | declare|d as..\b|
|00000260| 65 67 69 6e 7b 76 65 72 | 62 61 74 69 6d 7d 0d 0a |egin{ver|batim}..|
|00000270| 23 64 65 66 69 6e 65 20 | 4d 41 58 43 48 41 52 53 |#define |MAXCHARS|
|00000280| 20 38 30 0d 0a 63 6c 61 | 73 73 20 73 74 72 74 79 | 80..cla|ss strty|
|00000290| 70 65 20 7b 0d 0a 20 20 | 20 70 72 69 76 61 74 65 |pe {.. | private|
|000002a0| 3a 0d 0a 20 20 20 20 20 | 20 20 63 68 61 72 20 6e |:.. | char n|
|000002b0| 61 6d 65 5b 4d 41 58 43 | 48 41 52 53 5d 3b 0d 0a |ame[MAXC|HARS];..|
|000002c0| 20 20 20 70 75 62 6c 69 | 63 3a 0d 0a 20 20 20 20 | publi|c:.. |
|000002d0| 20 20 73 74 72 74 79 70 | 65 28 20 73 74 72 74 79 | strtyp|e( strty|
|000002e0| 70 65 20 26 73 74 72 20 | 29 3b 0d 0a 20 20 20 20 |pe &str |);.. |
|000002f0| 20 20 73 74 72 74 79 70 | 65 28 20 63 68 61 72 20 | strtyp|e( char |
|00000300| 2a 73 74 72 20 29 3b 0d | 0a 20 20 20 20 20 20 73 |*str );.|. s|
|00000310| 74 72 74 79 70 65 28 20 | 76 6f 69 64 20 29 3b 0d |trtype( |void );.|
|00000320| 0a 20 20 20 20 20 20 73 | 74 72 74 79 70 65 20 6f |. s|trtype o|
|00000330| 70 65 72 61 74 6f 72 2b | 28 73 74 72 74 79 70 65 |perator+|(strtype|
|00000340| 20 73 74 72 29 3b 0d 0a | 20 20 20 20 20 20 73 74 | str);..| st|
|00000350| 72 74 79 70 65 20 6f 70 | 65 72 61 74 6f 72 2b 28 |rtype op|erator+(|
|00000360| 63 6f 6e 73 74 20 63 68 | 61 72 20 2a 73 74 72 29 |const ch|ar *str)|
|00000370| 3b 0d 0a 20 20 20 20 20 | 20 73 74 72 74 79 70 65 |;.. | strtype|
|00000380| 20 6f 70 65 72 61 74 6f | 72 3d 28 73 74 72 74 79 | operato|r=(strty|
|00000390| 70 65 20 73 74 72 29 3b | 0d 0a 20 20 20 20 20 20 |pe str);|.. |
|000003a0| 73 74 72 74 79 70 65 20 | 6f 70 65 72 61 74 6f 72 |strtype |operator|
|000003b0| 3d 28 63 6f 6e 73 74 20 | 63 68 61 72 20 2a 73 74 |=(const |char *st|
|000003c0| 72 29 3b 0d 0a 20 20 20 | 20 20 20 76 6f 69 64 20 |r);.. | void |
|000003d0| 53 68 6f 77 6e 61 6d 65 | 28 20 76 6f 69 64 20 29 |Showname|( void )|
|000003e0| 20 7b 20 70 72 69 6e 74 | 66 28 22 25 73 22 2c 6e | { print|f("%s",n|
|000003f0| 61 6d 65 29 20 3b 7d 0d | 0a 20 20 20 20 20 20 63 |ame) ;}.|. c|
|00000400| 68 61 72 20 2a 53 74 72 | 69 6e 67 41 64 64 72 65 |har *Str|ingAddre|
|00000410| 73 73 28 20 76 6f 69 64 | 20 29 20 7b 20 72 65 74 |ss( void| ) { ret|
|00000420| 75 72 6e 20 6e 61 6d 65 | 3b 20 7d 0d 0a 7d 3b 0d |urn name|; }..};.|
|00000430| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 20 |.\end{ve|rbatim} |
|00000440| 0d 0a 53 74 72 69 6e 67 | 73 20 68 61 76 65 20 61 |..String|s have a|
|00000450| 20 6d 61 78 69 6d 75 6d | 20 6c 65 6e 67 74 68 20 | maximum| length |
|00000460| 74 68 61 74 20 63 61 6e | 20 62 65 20 73 70 65 63 |that can| be spec|
|00000470| 69 66 69 65 64 20 61 74 | 0d 0a 63 6f 6d 70 69 6c |ified at|..compil|
|00000480| 65 20 74 69 6d 65 20 75 | 73 69 6e 67 20 74 68 65 |e time u|sing the|
|00000490| 20 73 79 6d 62 6f 6c 20 | 4d 41 58 43 48 41 52 53 | symbol |MAXCHARS|
|000004a0| 5c 69 6e 64 65 78 7b 73 | 74 72 74 79 70 65 21 4d |\index{s|trtype!M|
|000004b0| 41 58 43 48 41 52 53 7d | 2e 20 54 68 65 0d 0a 65 |AXCHARS}|. The..e|
|000004c0| 6e 74 69 72 65 20 4d 41 | 58 43 48 41 52 53 20 6e |ntire MA|XCHARS n|
|000004d0| 75 6d 62 65 72 20 6f 66 | 20 62 79 74 65 73 20 69 |umber of| bytes i|
|000004e0| 73 20 61 6c 6c 6f 63 61 | 74 65 64 20 77 68 65 6e |s alloca|ted when|
|000004f0| 20 74 68 65 0d 0a 73 74 | 72 69 6e 67 20 69 73 20 | the..st|ring is |
|00000500| 63 72 65 61 74 65 64 2e | 20 20 54 68 69 73 20 77 |created.| This w|
|00000510| 61 73 74 65 73 20 73 6f | 6d 65 20 6d 65 6d 6f 72 |astes so|me memor|
|00000520| 79 2c 20 62 75 74 20 69 | 74 20 61 76 6f 69 64 73 |y, but i|t avoids|
|00000530| 0d 0a 73 6f 6d 65 20 6f | 66 20 74 68 65 20 6e 61 |..some o|f the na|
|00000540| 73 74 79 20 70 72 6f 62 | 6c 65 6d 73 20 61 73 73 |sty prob|lems ass|
|00000550| 6f 63 69 61 74 65 64 20 | 77 69 74 68 20 73 74 72 |ociated |with str|
|00000560| 69 6e 67 73 0d 0a 6f 76 | 65 72 2d 77 72 69 74 69 |ings..ov|er-writi|
|00000570| 6e 67 20 6f 74 68 65 72 | 20 73 74 72 75 63 74 75 |ng other| structu|
|00000580| 72 65 73 20 69 6e 20 74 | 68 65 20 68 65 61 70 2e |res in t|he heap.|
|00000590| 20 49 66 20 79 6f 75 20 | 6e 65 65 64 20 74 68 65 | If you |need the|
|000005a0| 20 72 61 6d 2c 0d 0a 74 | 68 65 6e 20 79 6f 75 20 | ram,..t|hen you |
|000005b0| 63 61 6e 20 72 65 64 75 | 63 65 20 4d 41 58 43 48 |can redu|ce MAXCH|
|000005c0| 41 52 53 20 74 6f 20 61 | 20 6d 69 6e 69 6d 75 6e |ARS to a| minimun|
|000005d0| 20 6f 66 20 35 2e 20 54 | 68 69 73 20 77 69 6c 6c | of 5. T|his will|
|000005e0| 20 61 6c 73 6f 0d 0a 73 | 70 65 65 64 20 75 70 20 | also..s|peed up |
|000005f0| 74 68 65 20 70 72 6f 67 | 72 61 6d 20 73 6f 6d 65 |the prog|ram some|
|00000600| 20 73 69 6e 63 65 20 69 | 74 20 77 69 6c 6c 20 73 | since i|t will s|
|00000610| 70 65 6e 64 20 6c 65 73 | 73 20 74 69 6d 65 20 69 |pend les|s time i|
|00000620| 6e 20 74 68 65 0d 0a 73 | 74 72 69 6e 67 20 66 75 |n the..s|tring fu|
|00000630| 6e 63 74 69 6f 6e 73 2e | 0d 0a 0d 0a 4e 6f 74 65 |nctions.|....Note|
|00000640| 20 74 68 61 74 20 74 68 | 65 20 63 6f 6e 73 74 72 | that th|e constr|
|00000650| 75 63 74 6f 72 20 66 75 | 6e 63 74 69 6f 6e 20 63 |uctor fu|nction c|
|00000660| 6f 70 69 65 73 20 61 74 | 20 6d 6f 73 74 20 4d 41 |opies at| most MA|
|00000670| 58 43 48 41 52 53 0d 0a | 63 68 61 72 61 63 74 65 |XCHARS..|characte|
|00000680| 72 73 20 69 6e 74 6f 20 | 74 68 65 20 73 74 72 69 |rs into |the stri|
|00000690| 6e 67 20 62 75 66 66 65 | 72 2e 20 49 74 20 61 6c |ng buffe|r. It al|
|000006a0| 73 6f 20 74 65 72 6d 69 | 6e 61 74 65 73 20 74 68 |so termi|nates th|
|000006b0| 65 0d 0a 73 74 72 69 6e | 67 20 77 69 74 68 20 61 |e..strin|g with a|
|000006c0| 20 6e 75 6c 6c 20 63 68 | 61 72 61 63 74 65 72 2e | null ch|aracter.|
|000006d0| 20 54 68 65 20 64 65 66 | 61 75 6c 74 20 73 74 72 | The def|ault str|
|000006e0| 69 6e 67 20 69 73 20 61 | 20 6e 75 6c 6c 0d 0a 63 |ing is a| null..c|
|000006f0| 68 61 72 61 63 74 65 72 | 20 69 6e 20 70 6f 73 69 |haracter| in posi|
|00000700| 74 69 6f 6e 20 30 2e 0d | 0a 0d 0a 54 68 65 20 73 |tion 0..|...The s|
|00000710| 74 72 69 6e 67 20 6f 62 | 6a 65 63 74 20 63 61 6e |tring ob|ject can|
|00000720| 20 62 65 20 63 6f 6e 63 | 61 74 65 6e 61 74 65 64 | be conc|atenated|
|00000730| 20 61 6e 64 20 61 73 73 | 69 67 6e 65 64 2e 20 54 | and ass|igned. T|
|00000740| 68 65 0d 0a 63 6f 6e 63 | 61 74 65 6e 61 74 69 6f |he..conc|atenatio|
|00000750| 6e 20 6f 70 65 72 61 74 | 6f 72 20 69 73 20 27 2b |n operat|or is '+|
|00000760| 27 5c 69 6e 64 65 78 7b | 73 74 72 74 79 70 65 21 |'\index{|strtype!|
|00000770| 2b 7d 2e 20 54 68 65 20 | 6c 65 66 74 0d 0a 6f 70 |+}. The |left..op|
|00000780| 65 72 61 6e 64 20 6f 66 | 20 74 68 65 20 70 6c 75 |erand of| the plu|
|00000790| 73 20 6f 70 65 72 61 74 | 6f 72 20 6d 75 73 74 20 |s operat|or must |
|000007a0| 62 65 20 61 20 73 74 72 | 74 79 70 65 2e 20 54 68 |be a str|type. Th|
|000007b0| 65 20 70 6c 75 73 20 69 | 73 0d 0a 6f 76 65 72 6c |e plus i|s..overl|
|000007c0| 6f 61 64 65 64 20 74 6f | 20 61 63 63 65 70 74 20 |oaded to| accept |
|000007d0| 64 69 66 66 65 72 65 6e | 74 20 6b 69 6e 64 73 20 |differen|t kinds |
|000007e0| 6f 66 20 72 69 67 68 74 | 20 6f 70 65 72 61 6e 64 |of right| operand|
|000007f0| 73 2e 20 54 68 65 0d 0a | 72 69 67 68 74 20 6f 70 |s. The..|right op|
|00000800| 65 72 61 6e 64 73 20 6d | 61 79 20 62 65 20 73 74 |erands m|ay be st|
|00000810| 72 69 6e 67 73 20 6f 72 | 20 63 6f 6e 73 74 61 6e |rings or| constan|
|00000820| 74 20 63 68 61 72 61 63 | 74 65 72 20 61 72 72 61 |t charac|ter arra|
|00000830| 79 73 2e 0d 0a 54 68 69 | 73 20 61 6c 6c 6f 77 73 |ys...Thi|s allows|
|00000840| 20 79 6f 75 20 74 6f 20 | 63 6f 6e 63 61 74 65 6e | you to |concaten|
|00000850| 61 74 65 20 73 74 72 69 | 6e 67 73 20 75 73 69 6e |ate stri|ngs usin|
|00000860| 67 20 73 74 61 74 65 6d | 65 6e 74 73 0d 0a 73 75 |g statem|ents..su|
|00000870| 63 68 20 61 73 20 5c 76 | 65 72 62 23 20 73 31 2b |ch as \v|erb# s1+|
|00000880| 22 63 6f 6e 73 74 22 2b | 22 20 63 68 61 72 22 2b |"const"+|" char"+|
|00000890| 73 32 20 23 20 77 68 65 | 72 65 20 73 31 20 61 6e |s2 # whe|re s1 an|
|000008a0| 64 20 73 32 20 61 72 65 | 0d 0a 73 74 72 69 6e 67 |d s2 are|..string|
|000008b0| 73 2e 20 20 54 68 65 20 | 6f 6e 6c 79 20 70 72 6f |s. The |only pro|
|000008c0| 62 6c 65 6d 20 69 73 20 | 72 65 6d 65 6d 62 65 72 |blem is |remember|
|000008d0| 69 6e 67 20 74 68 61 74 | 20 74 68 65 20 66 69 72 |ing that| the fir|
|000008e0| 73 74 0d 0a 74 65 72 6d | 20 69 6e 20 74 68 65 20 |st..term| in the |
|000008f0| 63 6f 6e 63 61 74 65 6e | 61 74 69 6f 6e 20 6d 75 |concaten|ation mu|
|00000900| 73 74 20 62 65 20 61 20 | 73 74 72 69 6e 67 2e 20 |st be a |string. |
|00000910| 28 49 20 64 69 64 20 6e | 6f 74 20 73 65 65 0d 0a |(I did n|ot see..|
|00000920| 74 68 65 20 6e 65 65 64 | 20 6f 66 20 61 6e 79 74 |the need| of anyt|
|00000930| 68 69 6e 67 20 66 61 6e | 63 69 65 72 20 74 68 61 |hing fan|cier tha|
|00000940| 6e 20 74 68 69 73 20 69 | 6e 20 74 68 69 73 20 63 |n this i|n this c|
|00000950| 6f 6e 74 65 78 74 2e 29 | 0d 0a 41 6c 73 6f 2c 20 |ontext.)|..Also, |
|00000960| 63 6f 6e 63 61 74 65 6e | 61 74 69 6f 6e 20 63 6f |concaten|ation co|
|00000970| 6e 74 72 6f 6c 73 20 74 | 68 65 20 6c 65 6e 67 74 |ntrols t|he lengt|
|00000980| 68 20 6f 66 20 74 68 65 | 20 69 6e 74 65 72 6d 65 |h of the| interme|
|00000990| 64 69 61 74 65 0d 0a 72 | 65 73 75 6c 74 73 20 74 |diate..r|esults t|
|000009a0| 6f 20 62 65 20 61 74 20 | 6d 6f 73 74 20 4d 41 58 |o be at |most MAX|
|000009b0| 43 48 41 52 53 2e 0d 0a | 0d 0a 41 73 73 69 67 6e |CHARS...|..Assign|
|000009c0| 6d 65 6e 74 5c 69 6e 64 | 65 78 7b 73 74 72 74 79 |ment\ind|ex{strty|
|000009d0| 70 65 21 3d 7d 20 69 73 | 20 6f 76 65 72 6c 6f 61 |pe!=} is| overloa|
|000009e0| 64 65 64 20 66 6f 72 20 | 73 74 72 69 6e 67 73 20 |ded for |strings |
|000009f0| 61 6e 64 0d 0a 63 6f 6e | 73 74 61 6e 74 20 63 68 |and..con|stant ch|
|00000a00| 61 72 61 63 74 65 72 20 | 61 72 72 61 79 73 2e 20 |aracter |arrays. |
|00000a10| 52 65 70 65 61 74 65 64 | 20 61 73 73 69 67 6e 6d |Repeated| assignm|
|00000a20| 65 6e 74 20 73 75 63 68 | 20 61 73 0d 0a 5c 76 65 |ent such| as..\ve|
|00000a30| 72 62 23 20 73 31 3d 73 | 32 3d 22 61 20 73 69 6c |rb# s1=s|2="a sil|
|00000a40| 6c 79 20 73 74 72 69 6e | 67 22 23 20 68 61 73 20 |ly strin|g"# has |
|00000a50| 6e 6f 74 20 62 65 65 6e | 20 74 65 73 74 65 64 2c |not been| tested,|
|00000a60| 20 62 75 74 20 49 0d 0a | 67 75 65 73 73 20 69 74 | but I..|guess it|
|00000a70| 20 77 69 6c 6c 20 77 6f | 72 6b 2c 20 70 72 6f 76 | will wo|rk, prov|
|00000a80| 69 64 69 6e 67 20 74 68 | 61 74 20 74 68 65 20 6c |iding th|at the l|
|00000a90| 65 66 74 6d 6f 73 74 20 | 61 73 73 69 67 6e 6d 65 |eftmost |assignme|
|00000aa0| 6e 74 73 20 6f 6e 6c 79 | 0d 0a 68 61 76 65 20 73 |nts only|..have s|
|00000ab0| 74 72 69 6e 67 73 20 61 | 73 20 74 68 65 20 72 69 |trings a|s the ri|
|00000ac0| 67 68 74 20 6f 70 65 72 | 61 6e 64 73 2e 20 41 67 |ght oper|ands. Ag|
|00000ad0| 61 69 6e 2c 20 73 74 72 | 69 6e 67 73 20 61 72 65 |ain, str|ings are|
|00000ae0| 0d 0a 74 72 75 6e 63 61 | 74 65 64 20 74 6f 20 4d |..trunca|ted to M|
|00000af0| 41 58 43 48 41 52 53 20 | 64 75 72 69 6e 67 20 61 |AXCHARS |during a|
|00000b00| 73 73 69 67 6e 6d 65 6e | 74 2e 20 0d 0a 0d 0a 54 |ssignmen|t. ....T|
|00000b10| 68 65 20 53 68 6f 77 6e | 61 6d 65 20 6d 65 6d 62 |he Shown|ame memb|
|00000b20| 65 72 20 66 75 6e 63 74 | 69 6f 6e 20 73 69 6d 70 |er funct|ion simp|
|00000b30| 6c 79 20 70 72 69 6e 74 | 73 20 74 68 65 20 6e 61 |ly print|s the na|
|00000b40| 6d 65 2e 20 49 20 68 61 | 76 65 0d 0a 75 73 65 64 |me. I ha|ve..used|
|00000b50| 20 74 68 65 20 43 20 66 | 75 6e 63 74 69 6f 6e 20 | the C f|unction |
|00000b60| 70 72 69 6e 74 66 28 29 | 20 69 6e 73 74 65 61 64 |printf()| instead|
|00000b70| 20 6f 66 20 63 6f 75 74 | 20 74 68 72 6f 75 67 68 | of cout| through|
|00000b80| 6f 75 74 20 74 68 65 0d | 0a 70 72 6f 67 72 61 6d |out the.|.program|
|00000b90| 20 62 65 63 61 75 73 65 | 20 63 6f 75 74 20 6a 75 | because| cout ju|
|00000ba0| 6d 62 6c 65 64 20 74 68 | 65 20 6f 75 74 70 75 74 |mbled th|e output|
|00000bb0| 20 77 68 65 6e 20 70 69 | 70 69 6e 67 20 6f 75 74 | when pi|ping out|
|00000bc0| 70 75 74 0d 0a 74 6f 20 | 61 20 66 69 6c 65 2e 20 |put..to |a file. |
|00000bd0| 28 4d 61 79 62 65 20 49 | 20 64 69 64 6e 27 74 20 |(Maybe I| didn't |
|00000be0| 64 6f 20 73 6f 6d 65 74 | 68 69 6e 67 20 72 69 67 |do somet|hing rig|
|00000bf0| 68 74 20 66 6f 72 20 63 | 6f 75 74 2c 20 62 75 74 |ht for c|out, but|
|00000c00| 0d 0a 70 72 69 6e 74 66 | 20 77 6f 72 6b 65 64 20 |..printf| worked |
|00000c10| 73 6f 20 49 20 6b 65 70 | 74 20 69 74 2e 20 59 6f |so I kep|t it. Yo|
|00000c20| 75 20 73 68 6f 75 6c 64 | 20 75 73 65 20 65 6e 64 |u should| use end|
|00000c30| 6c 20 6f 72 20 66 6c 75 | 73 68 20 74 6f 0d 0a 74 |l or flu|sh to..t|
|00000c40| 65 72 6d 69 6e 61 74 65 | 20 74 68 65 20 63 6f 75 |erminate| the cou|
|00000c50| 74 27 73 2e 20 54 68 69 | 73 20 68 65 6c 70 73 20 |t's. Thi|s helps |
|00000c60| 63 6f 6f 72 64 69 6e 61 | 74 65 20 70 72 69 6e 74 |coordina|te print|
|00000c70| 66 20 77 69 74 68 20 74 | 68 65 0d 0a 69 6f 73 74 |f with t|he..iost|
|00000c80| 72 65 61 6d 73 20 62 79 | 20 66 6c 75 73 68 69 6e |reams by| flushin|
|00000c90| 67 20 74 68 65 20 73 74 | 72 65 61 6d 2e 29 0d 0a |g the st|ream.)..|
|00000ca0| 0d 0a 54 68 65 20 6c 61 | 73 74 20 6d 65 6d 62 65 |..The la|st membe|
|00000cb0| 72 20 66 75 6e 63 74 69 | 6f 6e 20 69 73 20 2a 53 |r functi|on is *S|
|00000cc0| 74 72 69 6e 67 41 64 64 | 72 65 73 73 28 29 2e 20 |tringAdd|ress(). |
|00000cd0| 54 68 69 73 20 6d 65 72 | 65 6c 79 0d 0a 72 65 74 |This mer|ely..ret|
|00000ce0| 75 72 6e 73 20 74 68 65 | 20 61 64 64 72 65 73 73 |urns the| address|
|00000cf0| 20 6f 66 20 74 68 65 20 | 6e 61 6d 65 2e 20 54 68 | of the |name. Th|
|00000d00| 69 73 20 66 75 6e 63 74 | 69 6f 6e 20 69 73 20 75 |is funct|ion is u|
|00000d10| 73 65 64 20 62 79 0d 0a | 74 68 65 20 6d 61 74 72 |sed by..|the matr|
|00000d20| 69 78 20 66 75 6e 63 74 | 69 6f 6e 73 20 6c 61 74 |ix funct|ions lat|
|00000d30| 65 72 2e 20 57 68 65 6e | 20 69 74 20 69 73 20 75 |er. When| it is u|
|00000d40| 73 65 64 20 69 6e 20 74 | 68 65 20 6d 61 74 72 69 |sed in t|he matri|
|00000d50| 78 0d 0a 66 75 6e 63 74 | 69 6f 6e 73 2c 20 74 68 |x..funct|ions, th|
|00000d60| 65 20 73 74 72 74 79 70 | 65 20 69 73 20 70 72 69 |e strtyp|e is pri|
|00000d70| 76 61 74 65 2c 20 73 6f | 20 53 74 72 69 6e 67 41 |vate, so| StringA|
|00000d80| 64 64 72 65 73 73 20 69 | 73 20 61 6c 73 6f 0d 0a |ddress i|s also..|
|00000d90| 70 72 69 76 61 74 65 2e | 20 54 68 69 73 20 6b 65 |private.| This ke|
|00000da0| 65 70 73 20 79 6f 75 20 | 66 72 6f 6d 20 61 63 63 |eps you |from acc|
|00000db0| 69 64 65 6e 74 6c 79 20 | 63 6f 72 72 75 70 74 69 |idently |corrupti|
|00000dc0| 6e 67 20 74 68 65 20 6e | 61 6d 65 2e 0d 0a 0d 0a |ng the n|ame.....|
|00000dd0| 54 68 65 20 73 74 72 74 | 79 70 65 20 63 6c 61 73 |The strt|ype clas|
|00000de0| 73 20 63 6f 75 6c 64 20 | 62 65 20 72 65 70 6c 61 |s could |be repla|
|00000df0| 63 65 64 20 62 79 20 6d | 6f 72 65 20 73 6f 70 68 |ced by m|ore soph|
|00000e00| 69 73 74 69 63 61 74 65 | 64 0d 0a 73 74 72 69 6e |isticate|d..strin|
|00000e10| 67 20 66 75 6e 63 74 69 | 6f 6e 73 2e 20 59 6f 75 |g functi|ons. You|
|00000e20| 20 63 6f 75 6c 64 20 61 | 6c 6c 6f 77 20 74 68 65 | could a|llow the|
|00000e30| 6d 20 74 6f 20 68 61 76 | 65 20 76 61 72 69 61 62 |m to hav|e variab|
|00000e40| 6c 65 0d 0a 6c 65 6e 67 | 74 68 20 62 79 20 75 73 |le..leng|th by us|
|00000e50| 69 6e 67 20 70 6f 69 6e | 74 65 72 73 2e 20 59 6f |ing poin|ters. Yo|
|00000e60| 75 20 63 6f 75 6c 64 20 | 61 6c 73 6f 20 63 6f 6d |u could |also com|
|00000e70| 62 69 6e 65 20 72 65 70 | 65 61 74 65 64 0d 0a 72 |bine rep|eated..r|
|00000e80| 65 66 65 72 65 6e 63 65 | 73 20 74 6f 20 74 68 65 |eference|s to the|
|00000e90| 20 70 6f 69 6e 74 65 72 | 73 20 74 6f 20 74 68 65 | pointer|s to the|
|00000ea0| 20 6e 61 6d 65 20 73 6f | 20 74 68 61 74 20 64 75 | name so| that du|
|00000eb0| 70 6c 69 63 61 74 65 0d | 0a 6e 61 6d 65 73 20 77 |plicate.|.names w|
|00000ec0| 6f 75 6c 64 20 6f 63 63 | 75 70 79 20 74 68 65 20 |ould occ|upy the |
|00000ed0| 73 61 6d 65 20 73 70 61 | 63 65 20 69 6e 20 74 68 |same spa|ce in th|
|00000ee0| 65 20 68 65 61 70 2e 20 | 28 20 53 65 65 20 56 6f |e heap. |( See Vo|
|00000ef0| 73 73 0d 0a 61 6e 64 20 | 43 68 75 69 20 5c 63 69 |ss..and |Chui \ci|
|00000f00| 74 65 7b 76 63 3a 64 69 | 73 6b 7d 20 66 6f 72 20 |te{vc:di|sk} for |
|00000f10| 6d 6f 72 65 20 6f 6e 20 | 73 74 72 69 6e 67 73 2e |more on |strings.|
|00000f20| 29 20 0d 0a 0d 0a 5c 73 | 65 63 74 69 6f 6e 7b 45 |) ....\s|ection{E|
|00000f30| 78 61 6d 70 6c 65 3a 20 | 4d 61 6b 69 6e 67 20 61 |xample: |Making a|
|00000f40| 20 4d 61 74 72 69 78 20 | 4e 61 6d 65 7d 0d 0a 0d | Matrix |Name}...|
|00000f50| 0a 41 20 67 6f 6f 64 20 | 65 78 61 6d 70 6c 65 20 |.A good |example |
|00000f60| 6f 66 20 6d 61 6b 69 6e | 67 20 61 20 6d 61 74 72 |of makin|g a matr|
|00000f70| 69 78 20 6e 61 6d 65 20 | 69 73 20 66 6f 75 6e 64 |ix name |is found|
|00000f80| 20 69 6e 20 74 68 65 0d | 0a 72 6f 75 74 69 6e 65 | in the.|.routine|
|00000f90| 20 66 6f 72 20 69 6e 76 | 65 72 74 69 6e 67 20 61 | for inv|erting a|
|00000fa0| 20 6d 61 74 72 69 78 2e | 20 54 68 65 20 73 65 63 | matrix.| The sec|
|00000fb0| 74 69 6f 6e 20 6f 66 20 | 63 6f 64 65 20 69 73 20 |tion of |code is |
|00000fc0| 0d 0a 0d 0a 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |....\beg|in{verba|
|00000fd0| 74 69 6d 7d 0d 0a 20 20 | 20 20 20 73 74 72 74 79 |tim}.. | strty|
|00000fe0| 70 65 20 6e 65 77 6e 61 | 6d 65 20 3d 20 22 69 6e |pe newna|me = "in|
|00000ff0| 76 73 28 22 3b 0d 0a 20 | 20 20 20 20 6e 65 77 6e |vs(";.. | newn|
|00001000| 61 6d 65 20 3d 20 6e 65 | 77 6e 61 6d 65 20 2b 20 |ame = ne|wname + |
|00001010| 52 4f 70 2e 47 65 74 6e | 61 6d 65 28 52 4f 70 29 |ROp.Getn|ame(ROp)|
|00001020| 20 2b 20 22 29 22 3b 0d | 0a 20 20 20 20 20 2e 0d | + ")";.|. ..|
|00001030| 0a 20 20 20 20 20 2e 0d | 0a 20 20 20 20 20 2e 0d |. ..|. ..|
|00001040| 0a 20 20 20 20 20 74 65 | 6d 70 2d 3e 4e 61 6d 65 |. te|mp->Name|
|00001050| 69 74 28 20 6e 65 77 6e | 61 6d 65 20 29 3b 20 0d |it( newn|ame ); .|
|00001060| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 0d |.\end{ve|rbatim}.|
|00001070| 0a 0d 0a 54 68 65 20 69 | 64 65 61 20 69 73 20 74 |...The i|dea is t|
|00001080| 6f 20 63 6f 6e 73 74 72 | 75 63 74 20 74 68 65 20 |o constr|uct the |
|00001090| 69 6e 76 65 72 73 65 20 | 6f 66 20 74 68 65 20 6d |inverse |of the m|
|000010a0| 61 74 72 69 78 20 6f 62 | 6a 65 63 74 0d 0a 52 4f |atrix ob|ject..RO|
|000010b0| 70 2e 20 54 68 65 20 6e | 61 6d 65 20 6f 66 20 74 |p. The n|ame of t|
|000010c0| 68 65 20 6d 61 74 72 69 | 78 20 6f 62 6a 65 63 74 |he matri|x object|
|000010d0| 20 69 73 20 70 72 69 76 | 61 74 65 2c 20 73 6f 20 | is priv|ate, so |
|000010e0| 69 74 20 6d 75 73 74 0d | 0a 62 65 20 61 63 63 65 |it must.|.be acce|
|000010f0| 73 73 65 64 20 74 68 72 | 6f 75 67 68 20 74 68 65 |ssed thr|ough the|
|00001100| 20 6d 65 6d 62 65 72 20 | 66 75 6e 63 74 69 6f 6e | member |function|
|00001110| 0d 0a 47 65 74 6e 61 6d | 65 28 29 5c 69 6e 64 65 |..Getnam|e()\inde|
|00001120| 78 7b 73 74 72 74 79 70 | 65 21 47 65 74 6e 61 6d |x{strtyp|e!Getnam|
|00001130| 65 28 29 7d 2e 20 54 68 | 65 20 6e 61 6d 65 20 6f |e()}. Th|e name o|
|00001140| 66 20 74 68 65 20 69 6e | 76 65 72 73 65 20 73 68 |f the in|verse sh|
|00001150| 6f 75 6c 64 0d 0a 62 65 | 20 7b 5c 65 6d 20 69 6e |ould..be| {\em in|
|00001160| 76 73 28 72 6f 70 29 7d | 20 73 75 70 70 6f 73 69 |vs(rop)}| supposi|
|00001170| 6e 67 20 74 68 65 20 6e | 61 6d 65 20 6f 66 20 52 |ng the n|ame of R|
|00001180| 4f 70 20 69 73 20 72 6f | 70 2e 20 41 20 6e 65 77 |Op is ro|p. A new|
|00001190| 0d 0a 73 74 72 69 6e 67 | 20 69 73 20 63 72 65 61 |..string| is crea|
|000011a0| 74 65 64 20 75 73 69 6e | 67 20 74 68 65 20 63 6f |ted usin|g the co|
|000011b0| 6e 73 74 61 6e 74 20 73 | 74 72 69 6e 67 20 22 69 |nstant s|tring "i|
|000011c0| 6e 76 73 28 22 2c 20 74 | 68 65 6e 0d 0a 27 72 6f |nvs(", t|hen..'ro|
|000011d0| 70 27 20 69 73 20 65 78 | 74 72 61 63 74 65 64 20 |p' is ex|tracted |
|000011e0| 66 72 6f 6d 20 74 68 65 | 20 6d 61 74 72 69 78 2c |from the| matrix,|
|000011f0| 20 61 6e 64 20 61 20 70 | 61 72 65 6e 74 68 65 73 | and a p|arenthes|
|00001200| 69 73 20 69 73 0d 0a 61 | 70 70 65 6e 64 65 64 2e |is is..a|ppended.|
|00001210| 20 41 20 74 65 6d 70 6f | 72 61 72 79 20 6d 61 74 | A tempo|rary mat|
|00001220| 72 69 78 20 70 6f 69 6e | 74 65 72 20 77 61 73 20 |rix poin|ter was |
|00001230| 63 72 65 61 74 65 64 20 | 64 75 72 69 6e 67 20 74 |created |during t|
|00001240| 68 65 0d 0a 6d 61 74 72 | 69 78 20 69 6e 76 65 72 |he..matr|ix inver|
|00001250| 73 69 6f 6e 2e 20 20 54 | 68 65 20 6d 61 74 72 69 |sion. T|he matri|
|00001260| 78 20 6d 65 6d 62 65 72 | 20 66 75 6e 63 74 69 6f |x member| functio|
|00001270| 6e 0d 0a 4e 61 6d 65 69 | 74 28 29 5c 69 6e 64 65 |n..Namei|t()\inde|
|00001280| 78 7b 73 74 72 74 79 70 | 65 21 4e 61 6d 65 69 74 |x{strtyp|e!Nameit|
|00001290| 28 29 7d 20 73 74 6f 72 | 65 73 20 74 68 65 20 73 |()} stor|es the s|
|000012a0| 74 72 69 6e 67 20 69 6e | 20 74 68 65 20 6d 61 74 |tring in| the mat|
|000012b0| 72 69 78 0d 0a 6e 61 6d | 65 2e 20 53 6f 2c 20 74 |rix..nam|e. So, t|
|000012c0| 77 6f 20 6d 65 6d 62 65 | 72 20 66 75 6e 63 74 69 |wo membe|r functi|
|000012d0| 6f 6e 73 20 6f 66 20 74 | 68 65 20 6d 61 74 72 69 |ons of t|he matri|
|000012e0| 78 20 63 6c 61 73 73 20 | 61 72 65 20 75 73 65 64 |x class |are used|
|000012f0| 0d 0a 66 6f 72 20 6d 61 | 6e 69 70 75 6c 61 74 69 |..for ma|nipulati|
|00001300| 6e 67 20 74 68 65 20 6e | 61 6d 65 20 6f 66 20 74 |ng the n|ame of t|
|00001310| 68 65 20 6d 61 74 72 69 | 78 2e 0d 0a 0d 0a |he matri|x..... |
+--------+-------------------------+-------------------------+--------+--------+