home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 792 / vc_help.SIS < prev   
EPOC Installation Package  |  1999-08-02  |  498.2 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: EPOC Installation Package (archive/epocInstallationPackage).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert EPOC Installation Package (archive/epocInstallationPackage) magic Supported
1% dexvert Symbian Series 3 Installation file (other/symbianSeries3InstallationFile) ext Unsupported
100% file Symbian installation file (EPOC release 3/4/5) default
99% file data default
100% TrID EPOC Installation package (rel. 2,3,5) default
100% xdgMime application/vnd.symbian.install default



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 19 67 00 01 6d 00 00 10 | 19 04 00 10 d9 8b 9e a0 |.g..m...|........|
|00000010| 62 23 01 00 05 00 00 00 | 00 00 00 00 00 00 00 00 |b#......|........|
|00000020| 64 00 00 00 00 00 00 00 | 01 00 00 00 00 00 00 00 |d.......|........|
|00000030| 44 00 00 00 46 00 00 00 | fa 00 00 00 00 00 00 00 |D...F...|........|
|00000040| fa 00 00 00 01 00 00 00 | 00 00 04 00 00 00 00 00 |........|........|
|00000050| 00 00 00 00 00 00 02 01 | 00 00 22 00 00 00 02 01 |........|..".....|
|00000060| 00 00 00 00 00 00 35 02 | 00 00 00 00 00 00 00 00 |......5.|........|
|00000070| 00 00 00 00 00 00 22 00 | 00 00 24 01 00 00 22 00 |......".|..$...".|
|00000080| 00 00 46 01 00 00 5e ab | 07 00 35 02 00 00 00 00 |..F...^.|..5.....|
|00000090| 00 00 00 00 00 00 00 00 | 00 00 18 00 00 00 68 01 |........|......h.|
|000000a0| 00 00 22 00 00 00 80 01 | 00 00 5c 03 00 00 93 ad |..".....|..\.....|
|000000b0| 07 00 00 00 00 00 00 00 | 00 00 00 00 00 00 24 00 |........|......$.|
|000000c0| 00 00 a2 01 00 00 22 00 | 00 00 c6 01 00 00 ee 01 |......".|........|
|000000d0| 00 00 ef b0 07 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000000e0| 00 00 24 00 00 00 e8 01 | 00 00 22 00 00 00 0c 02 |..$.....|..".....|
|000000f0| 00 00 20 16 00 00 dd b2 | 07 00 07 00 00 00 2e 02 |.. .....|........|
|00000100| 00 00 21 3a 5c 73 79 73 | 74 65 6d 5c 61 70 70 73 |..!:\sys|tem\apps|
|00000110| 5c 56 63 5f 68 65 6c 70 | 5c 56 63 5f 68 65 6c 70 |\Vc_help|\Vc_help|
|00000120| 2e 69 6e 69 5c 76 63 5f | 68 65 6c 70 5c 68 65 6c |.ini\vc_|help\hel|
|00000130| 70 5c 72 65 6c 65 61 73 | 65 73 5c 56 63 5f 68 65 |p\releas|es\Vc_he|
|00000140| 6c 70 2e 68 6c 70 21 3a | 5c 73 79 73 74 65 6d 5c |lp.hlp!:|\system\|
|00000150| 61 70 70 73 5c 56 63 5f | 68 65 6c 70 5c 56 63 5f |apps\Vc_|help\Vc_|
|00000160| 68 65 6c 70 2e 68 6c 70 | 5c 76 63 5f 68 65 6c 70 |help.hlp|\vc_help|
|00000170| 5c 61 69 66 5c 56 63 5f | 68 65 6c 70 2e 61 69 66 |\aif\Vc_|help.aif|
|00000180| 21 3a 5c 73 79 73 74 65 | 6d 5c 61 70 70 73 5c 56 |!:\syste|m\apps\V|
|00000190| 63 5f 68 65 6c 70 5c 56 | 63 5f 68 65 6c 70 2e 61 |c_help\V|c_help.a|
|000001a0| 69 66 5c 45 70 6f 63 33 | 32 5c 52 65 6c 65 61 73 |if\Epoc3|2\Releas|
|000001b0| 65 5c 4d 61 72 6d 5c 52 | 65 6c 5c 56 63 5f 68 65 |e\Marm\R|el\Vc_he|
|000001c0| 6c 70 2e 72 73 63 21 3a | 5c 73 79 73 74 65 6d 5c |lp.rsc!:|\system\|
|000001d0| 61 70 70 73 5c 56 63 5f | 68 65 6c 70 5c 56 63 5f |apps\Vc_|help\Vc_|
|000001e0| 68 65 6c 70 2e 72 73 63 | 5c 45 70 6f 63 33 32 5c |help.rsc|\Epoc32\|
|000001f0| 52 65 6c 65 61 73 65 5c | 4d 61 72 6d 5c 52 65 6c |Release\|Marm\Rel|
|00000200| 5c 56 63 5f 68 65 6c 70 | 2e 61 70 70 21 3a 5c 73 |\Vc_help|.app!:\s|
|00000210| 79 73 74 65 6d 5c 61 70 | 70 73 5c 56 63 5f 68 65 |ystem\ap|ps\Vc_he|
|00000220| 6c 70 5c 56 63 5f 68 65 | 6c 70 2e 61 70 70 76 63 |lp\Vc_he|lp.appvc|
|00000230| 5f 68 65 6c 70 50 00 00 | 10 6d 00 00 10 86 00 00 |_helpP..|.m......|
|00000240| 10 fe a1 08 55 d4 6b 0f | 00 00 00 00 00 3f aa 07 |....U.k.|.....?..|
|00000250| 00 f5 99 09 40 00 00 00 | 00 00 00 00 00 00 0d 40 |....@...|.......@|
|00000260| 03 00 00 00 3f 00 00 00 | 1e 00 00 00 00 5b 40 69 |....?...|.....[@i|
|00000270| 00 00 10 00 01 00 00 00 | 02 1a 54 61 62 6c 65 31 |........|..Table1|
|00000280| 10 16 43 6f 6c 41 31 0b | 00 78 16 43 6f 6c 42 31 |..ColA1.|.x.ColB1|
|00000290| 10 00 16 43 6f 6c 41 32 | 0e 00 16 43 6f 6c 42 32 |...ColA2|...ColB2|
|000002a0| 10 00 16 43 6f 6c 41 33 | 0b 00 78 16 43 6f 6c 42 |...ColA3|..x.ColB|
|000002b0| 33 10 00 16 43 6f 6c 41 | 34 0b 00 78 16 43 6f 6c |3...ColA|4..x.Col|
|000002c0| 42 34 10 00 20 04 00 00 | 00 00 0d 40 86 00 00 10 |B4.. ...|...@....|
|000002d0| 22 44 41 54 41 2e 41 50 | 50 06 40 01 37 02 03 03 |"DATA.AP|P.@.7...|
|000002e0| 00 21 40 08 2e 01 00 10 | 23 00 00 00 89 00 00 10 |.!@.....|#.......|
|000002f0| 24 00 00 00 31 01 00 10 | 25 00 00 00 37 01 00 10 |$...1...|%...7...|
|00000300| 26 00 00 00 02 00 00 00 | 00 40 57 68 69 6c 65 20 |&.......|.@While |
|00000310| 63 6f 6d 70 75 74 65 72 | 20 68 61 72 64 77 61 72 |computer| hardwar|
|00000320| 65 20 68 61 73 20 6d 61 | 64 65 20 74 72 65 6d 65 |e has ma|de treme|
|00000330| 6e 64 6f 75 73 20 70 72 | 6f 67 72 65 73 73 2c 20 |ndous pr|ogress, |
|00000340| 73 6f 66 74 77 61 72 65 | 20 68 61 73 20 61 20 6c |software| has a l|
|00000350| 6f 6e 67 20 77 61 79 20 | 74 6f 20 67 6f 20 74 6f |ong way |to go to|
|00000360| 20 63 61 74 63 68 20 75 | 70 2e 20 57 69 74 68 20 | catch u|p. With |
|00000370| 74 68 65 20 77 69 64 65 | 6e 69 6e 67 20 67 61 70 |the wide|ning gap|
|00000380| 20 62 65 74 77 65 65 6e | 20 74 68 65 20 61 64 76 | between| the adv|
|00000390| 61 6e 63 65 6d 65 6e 74 | 20 69 6e 20 68 61 72 64 |ancement| in hard|
|000003a0| 77 61 72 65 20 61 6e 64 | 20 73 6f 66 74 77 61 72 |ware and| softwar|
|000003b0| 65 2c 20 69 73 20 74 68 | 65 20 72 65 73 75 6c 74 |e, is th|e result|
|000003c0| 20 74 68 61 74 20 6d 61 | 6e 79 20 6f 66 20 74 68 | that ma|ny of th|
|000003d0| 65 20 61 64 76 61 6e 63 | 65 73 20 69 6e 20 63 6f |e advanc|es in co|
|000003e0| 6d 70 75 74 65 72 20 68 | 61 72 64 77 61 72 65 20 |mputer h|ardware |
|000003f0| 67 6f 20 75 6e 74 61 70 | 70 65 64 2e 06 49 74 20 |go untap|ped..It |
|00000400| 69 73 20 62 65 69 6e 67 | 20 70 72 65 64 69 63 74 |is being| predict|
|00000410| 65 64 20 74 68 61 74 20 | 4f 62 6a 65 63 74 2d 6f |ed that |Object-o|
|00000420| 72 69 65 6e 74 65 64 20 | 50 72 6f 67 72 61 6d 6d |riented |Programm|
|00000430| 69 6e 67 20 28 4f 4f 50 | 29 20 77 69 6c 6c 20 64 |ing (OOP|) will d|
|00000440| 6f 20 66 6f 72 20 73 6f | 66 74 77 61 72 65 20 77 |o for so|ftware w|
|00000450| 68 61 74 20 74 68 65 20 | 6d 69 63 72 6f 63 68 69 |hat the |microchi|
|00000460| 70 20 68 61 73 20 64 6f | 6e 65 20 66 6f 72 20 68 |p has do|ne for h|
|00000470| 61 72 64 77 61 72 65 2e | 20 49 6e 73 74 65 61 64 |ardware.| Instead|
|00000480| 20 6f 66 20 74 68 65 20 | 6d 69 63 72 6f 63 68 69 | of the |microchi|
|00000490| 70 2c 20 73 6f 66 74 77 | 61 72 65 20 72 65 73 6f |p, softw|are reso|
|000004a0| 6c 75 74 69 6f 6e 20 77 | 69 6c 6c 20 62 65 20 62 |lution w|ill be b|
|000004b0| 75 69 6c 74 20 61 72 6f | 75 6e 64 20 27 73 6f 66 |uilt aro|und 'sof|
|000004c0| 74 77 61 72 65 27 20 49 | 43 27 73 20 6f 72 20 6f |tware' I|C's or o|
|000004d0| 62 6a 65 63 74 73 20 74 | 68 61 74 20 77 69 6c 6c |bjects t|hat will|
|000004e0| 20 62 65 20 73 69 6d 70 | 6c 65 2c 20 73 65 6c 66 | be simp|le, self|
|000004f0| 2d 63 6f 6e 74 61 69 6e | 65 64 20 61 6e 64 20 72 |-contain|ed and r|
|00000500| 65 6c 69 61 62 6c 65 20 | 73 6f 66 74 77 61 72 65 |eliable |software|
|00000510| 20 63 6f 6d 70 6f 6e 65 | 6e 74 73 2e 20 4f 4f 50 | compone|nts. OOP|
|00000520| 20 68 61 73 20 72 65 76 | 6f 6c 75 74 69 6f 6e 69 | has rev|olutioni|
|00000530| 7a 65 64 20 74 68 65 20 | 70 72 6f 67 72 61 6d 6d |zed the |programm|
|00000540| 69 6e 67 20 77 6f 72 6c | 64 20 74 6f 64 61 79 be |ing worl|d today.|
|00000550| 77 68 61 74 20 73 74 72 | 75 63 74 75 72 65 64 20 |what str|uctured |
|00000560| 70 72 6f 67 72 61 6d 6d | 69 6e 67 20 64 69 64 20 |programm|ing did |
|00000570| 32 30 20 79 65 61 72 73 | 20 61 67 6f 2e 20 49 74 |20 years| ago. It|
|00000580| 20 69 73 20 61 6c 72 65 | 61 64 79 20 68 65 6c 70 | is alre|ady help|
|00000590| 69 6e 67 20 74 68 65 20 | 63 6f 6d 70 75 74 65 72 |ing the |computer|
|000005a0| 20 69 6e 64 75 73 74 72 | 79 20 63 68 75 72 6e 20 | industr|y churn |
|000005b0| 6f 75 74 20 6d 6f 72 65 | 20 72 65 6c 69 61 62 6c |out more| reliabl|
|000005c0| 65 2c 20 75 6e 64 65 72 | 73 74 61 6e 64 61 62 6c |e, under|standabl|
|000005d0| 65 2c 20 6d 61 6e 61 67 | 65 61 62 6c 65 20 61 6e |e, manag|eable an|
|000005e0| 64 20 72 65 75 73 61 62 | 6c 65 20 73 6f 66 74 77 |d reusab|le softw|
|000005f0| 61 72 65 2e 06 57 48 41 | 54 20 49 53 20 4f 42 4a |are..WHA|T IS OBJ|
|00000600| 45 43 54 2d 4f 52 49 45 | 4e 54 45 44 20 50 52 4f |ECT-ORIE|NTED PRO|
|00000610| 47 52 41 4d 4d 49 4e 47 | 06 54 68 6f 75 67 68 20 |GRAMMING|.Though |
|00000620| 74 68 65 20 74 65 72 6d | 20 6f 62 6a 65 63 74 2d |the term| object-|
|00000630| 6f 72 69 65 6e 74 65 64 | 20 70 72 6f 67 72 61 6d |oriented| program|
|00000640| 6d 69 6e 67 20 28 4f 4f | 50 29 20 69 73 20 77 69 |ming (OO|P) is wi|
|00000650| 64 65 6c 79 20 75 73 65 | 64 20 65 78 70 65 72 74 |dely use|d expert|
|00000660| 73 20 63 61 6e 6e 6f 74 | 20 73 65 65 6d 20 74 6f |s cannot| seem to|
|00000670| 20 61 67 72 65 65 20 6f | 6e 20 61 6e 20 65 78 61 | agree o|n an exa|
|00000680| 63 74 20 64 65 66 69 6e | 69 74 69 6f 6e 2e 20 48 |ct defin|ition. H|
|00000690| 6f 77 65 76 65 72 2c 20 | 74 68 65 20 67 65 6e 65 |owever, |the gene|
|000006a0| 72 61 6c 20 63 6f 6e 73 | 65 6e 73 75 73 20 69 73 |ral cons|ensus is|
|000006b0| 20 74 68 61 74 20 4f 4f | 50 20 69 6e 76 6f 6c 76 | that OO|P involv|
|000006c0| 65 73 20 64 65 66 69 6e | 69 6e 67 20 41 62 73 74 |es defin|ing Abst|
|000006d0| 72 61 63 74 20 44 61 74 | 61 20 54 79 70 65 73 20 |ract Dat|a Types |
|000006e0| 28 41 44 54 29 20 72 65 | 70 72 65 73 65 6e 74 69 |(ADT) re|presenti|
|000006f0| 6e 67 20 63 6f 6d 70 6c | 65 78 20 72 65 61 6c 2d |ng compl|ex real-|
|00000700| 77 6f 72 6c 64 20 6f 72 | 20 61 62 73 74 72 61 63 |world or| abstrac|
|00000710| 74 20 6f 62 6a 65 63 74 | 73 20 61 6e 64 20 6f 72 |t object|s and or|
|00000720| 67 61 6e 69 7a 69 6e 67 | 20 70 72 6f 67 72 61 6d |ganizing| program|
|00000730| 73 20 61 72 6f 75 6e 64 | 20 61 20 63 6f 6c 6c 65 |s around| a colle|
|00000740| 63 74 69 6f 6e 20 6f 66 | 20 41 44 54 73 20 77 69 |ction of| ADTs wi|
|00000750| 74 68 20 61 6e 20 65 79 | 65 20 74 6f 77 61 72 64 |th an ey|e toward|
|00000760| 73 20 65 78 70 6c 6f 69 | 74 69 6e 67 20 74 68 65 |s exploi|ting the|
|00000770| 69 72 20 63 6f 6d 6d 6f | 6e 20 66 65 61 74 75 72 |ir commo|n featur|
|00000780| 65 73 2e 20 54 68 65 20 | 74 65 72 6d 20 61 62 73 |es. The |term abs|
|00000790| 74 72 61 63 74 20 64 61 | 74 61 20 74 79 70 65 20 |tract da|ta type |
|000007a0| 72 65 66 65 72 73 20 74 | 6f 20 75 73 65 72 2d 64 |refers t|o user-d|
|000007b0| 65 66 69 6e 65 64 20 64 | 61 74 61 20 74 79 70 65 |efined d|ata type|
|000007c0| 73 20 74 68 61 74 20 74 | 6f 67 65 74 68 65 72 20 |s that t|ogether |
|000007d0| 77 69 74 68 20 61 20 73 | 65 74 20 6f 66 20 6f 70 |with a s|et of op|
|000007e0| 65 72 61 74 69 6f 6e 73 | 20 63 61 6e 20 62 65 20 |erations| can be |
|000007f0| 70 65 72 66 6f 72 6d 65 | 64 20 6f 6e 20 74 68 61 |performe|d on tha|
|00000800| 74 20 64 61 74 61 2e 20 | 49 74 20 69 73 20 63 61 |t data. |It is ca|
|00000810| 6c 6c 65 64 20 61 62 73 | 74 72 61 63 74 20 74 6f |lled abs|tract to|
|00000820| 20 64 69 73 74 69 6e 67 | 75 69 73 68 20 69 74 20 | disting|uish it |
|00000830| 66 72 6f 6d 20 74 68 65 | 20 66 75 6e 64 61 6d 65 |from the| fundame|
|00000840| 6e 74 61 6c 20 62 75 69 | 6c 74 2d 69 6e 20 64 61 |ntal bui|lt-in da|
|00000850| 74 61 20 74 79 70 65 73 | 2c 20 73 75 63 68 20 61 |ta types|, such a|
|00000860| 73 2c 20 69 6e 74 2c 20 | 63 68 61 72 2c 20 66 6c |s, int, |char, fl|
|00000870| 6f 61 74 2c 20 77 68 69 | 63 68 20 61 72 65 20 70 |oat, whi|ch are p|
|00000880| 72 6f 76 69 64 65 64 20 | 62 79 20 65 76 65 72 79 |rovided |by every|
|00000890| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 6c 61 6e | program|ming lan|
|000008a0| 67 75 61 67 65 2e 06 57 | 48 59 20 44 4f 20 57 45 |guage..W|HY DO WE|
|000008b0| 20 4e 45 45 44 20 4f 42 | 4a 45 43 54 2d 4f 52 49 | NEED OB|JECT-ORI|
|000008c0| 45 4e 54 45 44 20 50 52 | 4f 47 52 41 4d 4d 49 4e |ENTED PR|OGRAMMIN|
|000008d0| 47 06 4f 62 6a 65 63 74 | 2d 6f 72 69 65 6e 74 65 |G.Object|-oriente|
|000008e0| 64 20 70 72 6f 67 72 61 | 6d 6d 69 6e 67 20 77 61 |d progra|mming wa|
|000008f0| 73 20 64 65 76 65 6c 6f | 70 65 64 20 62 65 63 61 |s develo|ped beca|
|00000900| 75 73 65 20 73 65 76 65 | 72 61 6c 20 6c 69 6d 69 |use seve|ral limi|
|00000910| 74 61 74 69 6f 6e 73 20 | 77 65 72 65 20 64 69 73 |tations |were dis|
|00000920| 63 6f 76 65 72 65 64 20 | 69 6e 20 70 72 6f 63 65 |covered |in proce|
|00000930| 64 75 72 61 6c 20 70 72 | 6f 67 72 61 6d 6d 69 6e |dural pr|ogrammin|
|00000940| 67 20 61 70 70 72 6f 61 | 63 68 65 73 2c 20 77 68 |g approa|ches, wh|
|00000950| 69 63 68 20 77 65 72 65 | 20 66 6f 6c 6c 6f 77 65 |ich were| followe|
|00000960| 64 20 62 79 20 6c 61 6e | 67 75 61 67 65 73 20 73 |d by lan|guages s|
|00000970| 75 63 68 20 61 73 20 43 | 2c 20 50 61 73 63 61 6c |uch as C|, Pascal|
|00000980| 2c 20 46 6f 72 74 72 61 | 6e 20 65 74 63 2e 20 53 |, Fortra|n etc. S|
|00000990| 6f 6d 65 20 6f 66 20 74 | 68 65 20 6c 69 6d 69 74 |ome of t|he limit|
|000009a0| 61 74 69 6f 6e 73 20 66 | 6f 75 6e 64 20 69 6e 20 |ations f|ound in |
|000009b0| 70 72 6f 63 65 64 75 72 | 61 6c 20 6c 61 6e 67 75 |procedur|al langu|
|000009c0| 61 67 65 73 20 77 65 72 | 65 20 61 73 20 66 6f 6c |ages wer|e as fol|
|000009d0| 6c 6f 77 73 3a 06 50 72 | 6f 63 65 64 75 72 61 6c |lows:.Pr|ocedural|
|000009e0| 20 70 72 6f 67 72 61 6d | 6d 69 6e 67 20 6c 61 6e | program|ming lan|
|000009f0| 67 75 61 67 65 73 20 66 | 6f 6c 6c 6f 77 20 74 68 |guages f|ollow th|
|00000a00| 65 20 61 70 70 72 6f 61 | 63 68 20 6f 66 20 62 72 |e approa|ch of br|
|00000a10| 65 61 6b 69 6e 67 20 61 | 20 70 72 6f 62 6c 65 6d |eaking a| problem|
|00000a20| 20 69 6e 74 6f 20 73 6d | 61 6c 6c 65 72 20 75 6e | into sm|aller un|
|00000a30| 69 74 73 20 63 61 6c 6c | 65 64 20 66 75 6e 63 74 |its call|ed funct|
|00000a40| 69 6f 6e 73 20 6f 72 20 | 70 72 6f 63 65 64 75 72 |ions or |procedur|
|00000a50| 65 73 2e 20 41 73 20 61 | 20 70 72 6f 62 6c 65 6d |es. As a| problem|
|00000a60| 20 62 65 63 6f 6d 65 73 | 20 70 72 6f 67 72 65 73 | becomes| progres|
|00000a70| 73 69 76 65 6c 79 20 63 | 6f 6d 70 6c 65 78 2c 20 |sively c|omplex, |
|00000a80| 74 68 65 20 6e 75 6d 62 | 65 72 20 6f 66 20 70 72 |the numb|er of pr|
|00000a90| 6f 63 65 64 75 72 65 73 | 20 6e 6f 74 20 6f 6e 6c |ocedures| not onl|
|00000aa0| 79 20 69 6e 63 72 65 61 | 73 65 73 20 62 75 74 20 |y increa|ses but |
|00000ab0| 74 68 65 79 20 62 65 63 | 6f 6d 65 20 6d 6f 72 65 |they bec|ome more|
|00000ac0| 20 64 69 66 66 69 63 75 | 6c 74 20 74 6f 20 6d 61 | difficu|lt to ma|
|00000ad0| 6e 61 67 65 2c 20 75 6e | 64 65 72 73 74 61 6e 64 |nage, un|derstand|
|00000ae0| 20 61 6e 64 20 6d 6f 64 | 69 66 79 2e 06 49 6e 20 | and mod|ify..In |
|00000af0| 63 6f 6e 76 65 6e 74 69 | 6f 6e 61 6c 20 70 72 6f |conventi|onal pro|
|00000b00| 63 65 64 75 72 61 6c 20 | 70 72 6f 67 72 61 6d 6d |cedural |programm|
|00000b10| 69 6e 67 20 73 65 76 65 | 72 61 6c 20 66 75 6e 63 |ing seve|ral func|
|00000b20| 74 69 6f 6e 73 20 75 73 | 65 20 63 6f 6d 6d 6f 6e |tions us|e common|
|00000b30| 20 64 61 74 61 2e 20 41 | 6e 79 20 66 75 6e 63 74 | data. A|ny funct|
|00000b40| 69 6f 6e 20 6f 72 20 70 | 72 6f 63 65 64 75 72 65 |ion or p|rocedure|
|00000b50| 20 69 6e 20 74 68 65 20 | 70 72 6f 67 72 61 6d 20 | in the |program |
|00000b60| 63 61 6e 20 65 61 73 69 | 6c 79 20 61 63 63 65 73 |can easi|ly acces|
|00000b70| 73 20 61 6e 64 20 6d 6f | 64 69 66 79 20 74 68 61 |s and mo|dify tha|
|00000b80| 74 20 64 61 74 61 2e 20 | 54 68 69 73 20 63 61 6e |t data. |This can|
|00000b90| 20 65 61 73 69 6c 79 20 | 68 61 6d 70 65 72 20 74 | easily |hamper t|
|00000ba0| 68 65 20 73 65 63 75 72 | 69 74 79 20 61 6e 64 20 |he secur|ity and |
|00000bb0| 69 6e 74 65 67 72 69 74 | 79 20 6f 66 20 74 68 65 |integrit|y of the|
|00000bc0| 20 64 61 74 61 2e 20 54 | 68 69 73 20 69 73 20 61 | data. T|his is a|
|00000bd0| 20 73 65 72 69 6f 75 73 | 20 64 72 61 77 62 61 63 | serious| drawbac|
|00000be0| 6b 20 77 69 74 68 20 70 | 72 6f 63 65 64 75 72 61 |k with p|rocedura|
|00000bf0| 6c 20 70 72 6f 67 72 61 | 6d 6d 69 6e 67 20 6c 61 |l progra|mming la|
|00000c00| 6e 67 75 61 67 65 73 2e | 06 41 6e 6f 74 68 65 72 |nguages.|.Another|
|00000c10| 20 70 72 6f 62 6c 65 6d | 20 77 69 74 68 20 70 72 | problem| with pr|
|00000c20| 6f 63 65 64 75 72 61 6c | 20 6c 61 6e 67 75 61 67 |ocedural| languag|
|00000c30| 65 73 20 69 73 20 74 68 | 61 74 20 73 69 6e 63 65 |es is th|at since|
|00000c40| 20 6d 61 6e 79 20 66 75 | 6e 63 74 69 6f 6e 73 20 | many fu|nctions |
|00000c50| 61 63 63 65 73 73 20 74 | 68 65 20 73 61 6d 65 20 |access t|he same |
|00000c60| 64 61 74 61 2c 20 74 68 | 65 20 77 61 79 20 64 61 |data, th|e way da|
|00000c70| 74 61 20 69 73 20 6f 72 | 67 61 6e 69 7a 65 64 20 |ta is or|ganized |
|00000c80| 28 73 74 72 75 63 74 75 | 72 65 29 20 62 65 63 6f |(structu|re) beco|
|00000c90| 6d 65 73 20 63 72 69 74 | 69 63 61 6c 2e 20 52 65 |mes crit|ical. Re|
|00000ca0| 6f 72 67 61 6e 69 7a 61 | 74 69 6f 6e 20 6f 66 20 |organiza|tion of |
|00000cb0| 64 61 74 61 20 72 65 71 | 75 69 72 65 73 20 72 65 |data req|uires re|
|00000cc0| 77 72 69 74 69 6e 67 20 | 6f 66 20 61 6c 6c 20 74 |writing |of all t|
|00000cd0| 68 65 20 66 75 6e 63 74 | 69 6f 6e 73 2c 20 77 68 |he funct|ions, wh|
|00000ce0| 69 63 68 20 61 63 63 65 | 73 73 20 74 6f 20 63 6f |ich acce|ss to co|
|00000cf0| 6d 6d 6f 6e 20 64 61 74 | 61 2e 20 54 68 69 73 20 |mmon dat|a. This |
|00000d00| 69 73 20 61 6e 20 65 78 | 74 72 61 20 62 75 72 64 |is an ex|tra burd|
|00000d10| 65 6e 20 6f 6e 20 61 20 | 70 72 6f 67 72 61 6d 6d |en on a |programm|
|00000d20| 65 72 2e 06 47 4f 41 4c | 53 20 4f 46 20 4f 4f 50 |er..GOAL|S OF OOP|
|00000d30| 20 50 41 52 41 44 49 47 | 4d 06 4e 65 77 20 61 70 | PARADIG|M.New ap|
|00000d40| 70 72 6f 61 63 68 20 74 | 6f 20 70 72 6f 67 72 61 |proach t|o progra|
|00000d50| 6d 6d 69 6e 67 3a 20 4f | 4f 50 73 20 69 73 20 61 |mming: O|OPs is a|
|00000d60| 6e 20 65 6e 74 69 72 65 | 6c 79 20 6e 65 77 20 77 |n entire|ly new w|
|00000d70| 61 79 20 6f 66 20 6f 72 | 67 61 6e 69 7a 69 6e 67 |ay of or|ganizing|
|00000d80| 20 61 20 70 72 6f 67 72 | 61 6d 2e 20 55 73 69 6e | a progr|am. Usin|
|00000d90| 67 20 74 68 69 73 20 61 | 70 70 72 6f 61 63 68 2c |g this a|pproach,|
|00000da0| 20 61 20 70 72 6f 67 72 | 61 6d 20 77 69 6c 6c 20 | a progr|am will |
|00000db0| 6e 6f 74 20 62 65 20 6f | 72 67 61 6e 69 7a 65 64 |not be o|rganized|
|00000dc0| 20 69 6e 20 74 65 72 6d | 73 20 6f 66 20 74 68 65 | in term|s of the|
|00000dd0| 20 6e 75 6d 62 65 72 20 | 6f 66 20 66 75 6e 63 74 | number |of funct|
|00000de0| 69 6f 6e 73 2c 20 70 72 | 6f 63 65 64 75 72 65 73 |ions, pr|ocedures|
|00000df0| 20 6f 72 20 67 6c 6f 62 | 61 6c 20 64 61 74 61 20 | or glob|al data |
|00000e00| 28 64 61 74 61 20 61 76 | 61 69 6c 61 62 6c 65 20 |(data av|ailable |
|00000e10| 74 6f 20 61 6c 6c 29 2e | 20 52 61 74 68 65 72 2c |to all).| Rather,|
|00000e20| 20 69 74 20 77 69 6c 6c | 20 63 6f 6d 62 69 6e 65 | it will| combine|
|00000e30| 20 64 61 74 61 20 61 6e | 64 20 66 75 6e 63 74 69 | data an|d functi|
|00000e40| 6f 6e 73 20 69 6e 74 6f | 20 61 20 73 69 6e 67 6c |ons into| a singl|
|00000e50| 65 20 75 6e 69 74 20 63 | 61 6c 6c 65 64 20 61 6e |e unit c|alled an|
|00000e60| 20 6f 62 6a 65 63 74 2e | 20 41 73 20 61 20 72 65 | object.| As a re|
|00000e70| 73 75 6c 74 2c 20 64 61 | 74 61 20 77 69 6c 6c 20 |sult, da|ta will |
|00000e80| 62 65 20 73 65 63 75 72 | 65 20 66 72 6f 6d 20 61 |be secur|e from a|
|00000e90| 63 63 69 64 65 6e 74 61 | 6c 20 6f 72 20 69 6e 74 |ccidenta|l or int|
|00000ea0| 65 6e 74 69 6f 6e 61 6c | 20 63 6f 72 72 75 70 74 |entional| corrupt|
|00000eb0| 69 6f 6e 2e 06 52 65 2d | 75 73 69 6e 67 20 73 6f |ion..Re-|using so|
|00000ec0| 66 74 77 61 72 65 20 63 | 6f 6d 70 6f 6e 65 6e 74 |ftware c|omponent|
|00000ed0| 73 3a 20 52 61 74 68 65 | 72 20 74 68 61 6e 20 6d |s: Rathe|r than m|
|00000ee0| 61 6e 75 66 61 63 74 75 | 72 69 6e 67 20 73 6f 66 |anufactu|ring sof|
|00000ef0| 74 77 61 72 65 20 63 6f | 6d 70 6f 6e 65 6e 74 73 |tware co|mponents|
|00000f00| 20 61 6c 6c 20 74 68 65 | 20 74 69 6d 65 20 74 68 | all the| time th|
|00000f10| 65 20 63 6f 6e 63 65 70 | 74 20 6f 66 20 72 65 75 |e concep|t of reu|
|00000f20| 73 61 62 69 6c 69 74 79 | 20 77 69 6c 6c 20 72 65 |sability| will re|
|00000f30| 73 75 6c 74 20 69 6e 20 | 6c 6f 77 65 72 20 64 65 |sult in |lower de|
|00000f40| 76 65 6c 6f 70 6d 65 6e | 74 20 63 6f 73 74 73 20 |velopmen|t costs |
|00000f50| 61 6e 64 06 73 6f 66 74 | 77 61 72 65 20 6d 61 69 |and.soft|ware mai|
|00000f60| 6e 74 65 6e 61 6e 63 65 | 2c 20 61 73 20 77 65 6c |ntenance|, as wel|
|00000f70| 6c 20 61 73 20 73 61 76 | 65 20 74 69 6d 65 2e 06 |l as sav|e time..|
|00000f80| 4d 6f 64 65 6c 69 6e 67 | 20 74 68 65 20 72 65 61 |Modeling| the rea|
|00000f90| 6c 20 77 6f 72 6c 64 20 | 61 73 20 63 6c 6f 73 65 |l world |as close|
|00000fa0| 20 74 6f 20 74 68 65 20 | 75 73 65 72 27 73 20 70 | to the |user's p|
|00000fb0| 65 72 73 70 65 63 74 69 | 76 65 20 61 73 20 70 6f |erspecti|ve as po|
|00000fc0| 73 73 69 62 6c 65 2e 06 | 42 65 73 69 64 65 73 20 |ssible..|Besides |
|00000fd0| 74 68 65 20 61 62 6f 76 | 65 20 6d 65 6e 74 69 6f |the abov|e mentio|
|00000fe0| 6e 65 64 20 61 64 76 61 | 6e 74 61 67 65 73 2c 20 |ned adva|ntages, |
|00000ff0| 6f 62 6a 65 63 74 20 6f | 72 69 65 6e 74 61 74 69 |object o|rientati|
|00001000| 6f 6e 20 61 6c 73 6f 20 | 68 61 73 20 61 20 6e 75 |on also |has a nu|
|00001010| 6d 62 65 72 20 6f 66 20 | 6f 74 68 65 72 20 66 65 |mber of |other fe|
|00001020| 61 74 75 72 65 73 2c 20 | 77 68 69 63 68 20 77 69 |atures, |which wi|
|00001030| 6c 6c 20 62 65 20 64 69 | 73 63 75 73 73 65 64 20 |ll be di|scussed |
|00001040| 69 6e 20 64 65 74 61 69 | 6c 20 69 6e 20 74 68 65 |in detai|l in the|
|00001050| 20 73 65 63 6f 6e 64 20 | 73 65 73 73 69 6f 6e 2e | second |session.|
|00001060| 20 54 68 65 73 65 20 66 | 65 61 74 75 72 65 73 20 | These f|eatures |
|00001070| 61 72 65 06 41 62 73 74 | 72 61 63 74 69 6f 6e 06 |are.Abst|raction.|
|00001080| 45 6e 63 61 70 73 75 6c | 61 74 69 6f 6e 06 44 61 |Encapsul|ation.Da|
|00001090| 74 61 20 68 69 64 69 6e | 67 06 50 6f 6c 79 6d 6f |ta hidin|g.Polymo|
|000010a0| 72 70 68 69 73 6d 06 49 | 6e 68 65 72 69 74 61 6e |rphism.I|nheritan|
|000010b0| 63 65 06 43 2b 2b 20 69 | 73 20 61 20 70 72 6f 67 |ce.C++ i|s a prog|
|000010c0| 72 61 6d 6d 69 6e 67 20 | 6c 61 6e 67 75 61 67 65 |ramming |language|
|000010d0| 20 77 68 69 63 68 20 73 | 75 70 70 6f 72 74 73 20 | which s|upports |
|000010e0| 61 6c 6c 20 74 68 65 20 | 61 62 6f 76 65 20 6d 65 |all the |above me|
|000010f0| 6e 74 69 6f 6e 65 64 20 | 66 65 61 74 75 72 65 73 |ntioned |features|
|00001100| 20 6f 66 20 4f 4f 50 2e | 06 48 49 53 54 4f 52 59 | of OOP.|.HISTORY|
|00001110| 20 4f 46 20 43 2b 2b 06 | 43 2b 2b 20 70 72 6f 67 | OF C++.|C++ prog|
|00001120| 72 61 6d 6d 69 6e 67 20 | 6c 61 6e 67 75 61 67 65 |ramming |language|
|00001130| 20 77 61 73 20 64 65 73 | 69 67 6e 65 64 20 61 6e | was des|igned an|
|00001140| 64 20 64 65 76 65 6c 6f | 70 65 64 20 62 79 20 42 |d develo|ped by B|
|00001150| 6a 61 72 6e 65 20 53 74 | 72 6f 75 73 74 72 75 70 |jarne St|roustrup|
|00001160| 20 61 74 20 74 68 65 20 | 43 6f 6d 70 75 74 65 72 | at the |Computer|
|00001170| 20 53 63 69 65 6e 63 65 | 20 52 65 73 65 61 72 63 | Science| Researc|
|00001180| 68 20 43 65 6e 74 65 72 | 2c 20 41 54 26 54 20 42 |h Center|, AT&T B|
|00001190| 65 6c 6c 20 4c 61 62 73 | 2c 20 4e 65 77 20 4a 65 |ell Labs|, New Je|
|000011a0| 72 73 65 79 20 69 6e 20 | 74 68 65 20 65 61 72 6c |rsey in |the earl|
|000011b0| 79 20 45 69 67 68 74 69 | 65 73 2e 20 44 72 2e 20 |y Eighti|es. Dr. |
|000011c0| 53 74 72 6f 75 73 74 72 | 75 70 20 64 65 76 65 6c |Stroustr|up devel|
|000011d0| 6f 70 65 64 20 43 2b 2b | 20 74 6f 20 73 75 70 70 |oped C++| to supp|
|000011e0| 6f 72 74 20 74 68 65 20 | 77 72 69 74 69 6e 67 20 |ort the |writing |
|000011f0| 6f 66 20 63 6f 6d 70 6c | 65 78 20 73 69 6d 75 6c |of compl|ex simul|
|00001200| 61 74 69 6f 6e 20 70 72 | 6f 67 72 61 6d 73 2e 20 |ation pr|ograms. |
|00001210| 54 6f 74 61 6c 6c 79 20 | 63 6f 6d 70 61 74 69 62 |Totally |compatib|
|00001220| 6c 65 20 77 69 74 68 20 | 61 6e 64 20 62 61 73 65 |le with |and base|
|00001230| 64 20 6f 6e 20 74 68 65 | 20 43 20 6c 61 6e 67 75 |d on the| C langu|
|00001240| 61 67 65 2c 20 43 2b 2b | 20 69 73 20 61 20 73 75 |age, C++| is a su|
|00001250| 70 65 72 73 65 74 20 6f | 66 20 69 74 2e 20 43 2b |perset o|f it. C+|
|00001260| 2b 20 72 65 74 61 69 6e | 73 20 43 27 73 20 70 6f |+ retain|s C's po|
|00001270| 77 65 72 20 61 6e 64 20 | 66 6c 65 78 69 62 69 6c |wer and |flexibil|
|00001280| 69 74 79 20 74 6f 20 64 | 65 61 6c 20 77 69 74 68 |ity to d|eal with|
|00001290| 20 68 61 72 64 77 61 72 | 65 2d 73 6f 66 74 77 61 | hardwar|e-softwa|
|000012a0| 72 65 20 69 6e 74 65 72 | 66 61 63 65 20 61 6e 64 |re inter|face and|
|000012b0| 20 6c 6f 77 2d 6c 65 76 | 65 6c 20 73 79 73 74 65 | low-lev|el syste|
|000012c0| 6d 20 70 72 6f 67 72 61 | 6d 6d 69 6e 67 2e 20 54 |m progra|mming. T|
|000012d0| 68 65 20 65 66 66 69 63 | 69 65 6e 63 79 2c 20 63 |he effic|iency, c|
|000012e0| 6f 6d 70 61 63 74 6e 65 | 73 73 20 61 6e 64 20 70 |ompactne|ss and p|
|000012f0| 6f 77 65 72 20 6f 66 20 | 65 78 70 72 65 73 73 69 |ower of |expressi|
|00001300| 6f 6e 20 6f 66 20 43 20 | 61 72 65 20 72 65 74 61 |on of C |are reta|
|00001310| 69 6e 65 64 20 69 6e 20 | 43 2b 2b 2e 20 4c 69 6b |ined in |C++. Lik|
|00001320| 65 20 43 2c 20 43 2b 2b | 20 69 73 20 61 6c 73 6f |e C, C++| is also|
|00001330| 20 63 61 73 65 20 73 65 | 6e 73 69 74 69 76 65 2e | case se|nsitive.|
|00001340| 06 43 2b 2b 20 69 73 20 | 61 20 68 79 62 72 69 64 |.C++ is |a hybrid|
|00001350| 20 6c 61 6e 67 75 61 67 | 65 2e 20 54 68 65 20 6f | languag|e. The o|
|00001360| 62 6a 65 63 74 2d 6f 72 | 69 65 6e 74 65 64 20 70 |bject-or|iented p|
|00001370| 61 72 61 64 69 67 6d 20 | 63 61 6e 20 62 65 20 66 |aradigm |can be f|
|00001380| 75 6c 6c 79 20 65 78 70 | 6c 6f 69 74 65 64 20 74 |ully exp|loited t|
|00001390| 6f 20 70 72 6f 64 75 63 | 65 06 61 20 70 75 72 65 |o produc|e.a pure|
|000013a0| 6c 79 20 6f 62 6a 65 63 | 74 2d 6f 72 69 65 6e 74 |ly objec|t-orient|
|000013b0| 65 64 20 73 6f 6c 75 74 | 69 6f 6e 20 74 6f 20 61 |ed solut|ion to a|
|000013c0| 20 70 72 6f 62 6c 65 6d | 2e 20 43 2b 2b 20 63 61 | problem|. C++ ca|
|000013d0| 6e 20 62 65 20 74 72 65 | 61 74 65 64 20 61 73 20 |n be tre|ated as |
|000013e0| 61 20 70 72 6f 63 65 64 | 75 72 61 6c 20 6c 61 6e |a proced|ural lan|
|000013f0| 67 75 61 67 65 20 74 68 | 61 74 20 63 6f 6e 74 61 |guage th|at conta|
|00001400| 69 6e 73 20 73 6f 6d 65 | 20 61 64 64 69 74 69 6f |ins some| additio|
|00001410| 6e 61 6c 20 63 6f 6e 73 | 74 72 75 63 74 69 6f 6e |nal cons|truction|
|00001420| 20 62 65 79 6f 6e 64 20 | 43 2e 20 43 2b 2b 20 72 | beyond |C. C++ r|
|00001430| 65 66 6c 65 63 74 73 20 | 62 6f 74 68 20 74 68 65 |eflects |both the|
|00001440| 20 70 72 6f 63 65 64 75 | 72 61 6c 20 70 72 6f 67 | procedu|ral prog|
|00001450| 72 61 6d 6d 69 6e 67 20 | 70 61 72 61 64 69 67 6d |ramming |paradigm|
|00001460| 20 61 73 20 77 65 6c 6c | 20 61 73 20 61 20 6e 65 | as well| as a ne|
|00001470| 77 65 72 20 6f 62 6a 65 | 63 74 2d 6f 72 69 65 6e |wer obje|ct-orien|
|00001480| 74 65 64 20 70 61 72 61 | 64 69 67 6d 2e 06 43 2b |ted para|digm..C+|
|00001490| 2b 20 69 73 20 64 65 73 | 69 67 6e 65 64 20 74 6f |+ is des|igned to|
|000014a0| 20 73 75 70 70 6f 72 74 | 20 73 6f 66 74 77 61 72 | support| softwar|
|000014b0| 65 20 64 65 76 65 6c 6f | 70 65 64 20 6f 6e 20 61 |e develo|ped on a|
|000014c0| 20 6c 61 6e 67 75 61 67 | 65 20 73 63 61 6c 65 2e | languag|e scale.|
|000014d0| 20 54 68 65 20 69 6e 63 | 72 65 61 73 65 64 20 74 | The inc|reased t|
|000014e0| 79 70 65 2d 63 68 65 63 | 6b 69 6e 67 20 70 72 65 |ype-chec|king pre|
|000014f0| 73 65 6e 74 20 69 6e 20 | 69 74 2c 20 63 6f 6d 70 |sent in |it, comp|
|00001500| 61 72 65 64 20 74 6f 20 | 43 2c 20 72 65 64 75 63 |ared to |C, reduc|
|00001510| 65 73 20 65 72 72 6f 72 | 73 20 69 6e 20 74 68 65 |es error|s in the|
|00001520| 20 43 2b 2b 20 73 6f 66 | 74 77 61 72 65 20 73 79 | C++ sof|tware sy|
|00001530| 73 74 65 6d 20 61 6e 64 | 20 70 72 6f 76 69 64 65 |stem and| provide|
|00001540| 73 20 66 6f 72 20 62 65 | 74 74 65 72 20 6d 75 6c |s for be|tter mul|
|00001550| 74 69 70 72 6f 67 72 61 | 6d 6d 69 6e 67 20 65 66 |tiprogra|mming ef|
|00001560| 66 6f 72 74 73 2e 06 43 | 4f 4d 50 49 4c 49 4e 47 |forts..C|OMPILING|
|00001570| 20 41 4e 44 20 4c 49 4e | 4b 49 4e 47 06 41 20 70 | AND LIN|KING.A p|
|00001580| 72 6f 67 72 61 6d 20 77 | 72 69 74 74 65 6e 20 69 |rogram w|ritten i|
|00001590| 6e 20 61 20 68 69 67 68 | 2d 6c 65 76 65 6c 20 6c |n a high|-level l|
|000015a0| 61 6e 67 75 61 67 65 20 | 69 73 20 6b 6e 6f 77 6e |anguage |is known|
|000015b0| 20 61 73 20 74 68 65 20 | 73 6f 75 72 63 65 20 63 | as the |source c|
|000015c0| 6f 64 65 20 6f 72 20 73 | 6f 75 72 63 65 20 66 69 |ode or s|ource fi|
|000015d0| 6c 65 2e 20 54 68 65 20 | 73 6f 75 72 63 65 20 66 |le. The |source f|
|000015e0| 69 6c 65 20 69 6e 20 43 | 2b 2b 20 68 61 73 20 74 |ile in C|++ has t|
|000015f0| 68 65 20 65 78 74 65 6e | 73 69 6f 6e 20 2e 63 70 |he exten|sion .cp|
|00001600| 70 20 61 6e 64 20 6c 69 | 6b 65 20 61 6c 6c 20 73 |p and li|ke all s|
|00001610| 6f 75 72 63 65 20 66 69 | 6c 65 73 2c 20 74 68 69 |ource fi|les, thi|
|00001620| 73 20 66 69 6c 65 20 69 | 73 20 6e 6f 74 20 69 6e |s file i|s not in|
|00001630| 20 74 68 65 20 65 78 65 | 63 75 74 61 62 6c 65 20 | the exe|cutable |
|00001640| 66 6f 72 6d 2e 20 49 6e | 20 6f 72 64 65 72 20 74 |form. In| order t|
|00001650| 6f 20 63 6f 6e 76 65 72 | 74 20 61 20 73 6f 75 72 |o conver|t a sour|
|00001660| 63 65 20 66 69 6c 65 20 | 69 6e 74 6f 20 61 6e 20 |ce file |into an |
|00001670| 65 78 65 63 75 74 61 62 | 6c 65 20 6f 6e 65 2c 20 |executab|le one, |
|00001680| 74 77 6f 20 70 72 6f 63 | 65 73 73 65 73 20 68 61 |two proc|esses ha|
|00001690| 76 65 20 74 6f 20 62 65 | 20 63 61 72 72 69 65 64 |ve to be| carried|
|000016a0| 20 6f 75 74 2c 20 6e 61 | 6d 65 6c 79 20 63 6f 6d | out, na|mely com|
|000016b0| 70 69 6c 69 6e 67 20 61 | 6e 64 20 6c 69 6e 6b 69 |piling a|nd linki|
|000016c0| 6e 67 2e 06 54 68 65 20 | 70 72 6f 63 65 73 73 20 |ng..The |process |
|000016d0| 6f 66 20 63 6f 6d 70 69 | 6c 69 6e 67 20 63 6f 6e |of compi|ling con|
|000016e0| 76 65 72 74 73 20 61 20 | 73 6f 75 72 63 65 20 66 |verts a |source f|
|000016f0| 69 6c 65 20 69 6e 74 6f | 20 61 6e 20 6f 62 6a 65 |ile into| an obje|
|00001700| 63 74 20 66 69 6c 65 2c | 20 77 69 74 68 20 74 68 |ct file,| with th|
|00001710| 65 20 65 78 74 65 6e 73 | 69 6f 6e 20 2e 6f 62 6a |e extens|ion .obj|
|00001720| 2e 20 54 68 65 20 6f 62 | 6a 65 63 74 20 66 69 6c |. The ob|ject fil|
|00001730| 65 20 63 6f 6e 74 61 69 | 6e 73 20 6d 61 63 68 69 |e contai|ns machi|
|00001740| 6e 65 20 6c 61 6e 67 75 | 61 67 65 20 69 6e 73 74 |ne langu|age inst|
|00001750| 72 75 63 74 69 6f 6e 73 | 20 74 68 61 74 20 63 61 |ructions| that ca|
|00001760| 6e 20 62 65 20 65 78 65 | 63 75 74 65 64 20 62 79 |n be exe|cuted by|
|00001770| 20 74 68 65 20 63 6f 6d | 70 75 74 65 72 2e 20 48 | the com|puter. H|
|00001780| 6f 77 65 76 65 72 2c 20 | 74 68 65 20 65 78 65 63 |owever, |the exec|
|00001790| 75 74 61 62 6c 65 20 66 | 69 6c 65 20 69 73 20 6e |utable f|ile is n|
|000017a0| 6f 74 20 6f 62 74 61 69 | 6e 65 64 20 75 6e 74 69 |ot obtai|ned unti|
|000017b0| 6c 20 74 68 65 20 70 72 | 6f 63 65 73 73 20 6f 66 |l the pr|ocess of|
|000017c0| 20 6c 69 6e 6b 69 6e 67 | 20 69 73 20 63 6f 6d 70 | linking| is comp|
|000017d0| 6c 65 74 65 2e 06 41 6e | 20 65 78 65 63 75 74 61 |lete..An| executa|
|000017e0| 62 6c 65 20 66 69 6c 65 | 20 61 6c 77 61 79 73 20 |ble file| always |
|000017f0| 63 6f 6e 74 61 69 6e 73 | 20 6d 6f 72 65 20 74 68 |contains| more th|
|00001800| 61 6e 20 6f 6e 65 20 6f | 62 6a 65 63 74 20 66 69 |an one o|bject fi|
|00001810| 6c 65 2c 20 62 65 63 61 | 75 73 65 20 70 72 6f 67 |le, beca|use prog|
|00001820| 72 61 6d 6d 65 72 73 20 | 75 73 75 61 6c 6c 79 20 |rammers |usually |
|00001830| 64 69 76 69 64 65 20 74 | 68 65 69 72 20 70 72 6f |divide t|heir pro|
|00001840| 67 72 61 6d 73 20 69 6e | 74 6f 20 73 65 76 65 72 |grams in|to sever|
|00001850| 61 6c 20 73 6f 75 72 63 | 65 20 66 69 6c 65 73 2e |al sourc|e files.|
|00001860| 20 45 61 63 68 20 6f 66 | 20 74 68 65 73 65 20 70 | Each of| these p|
|00001870| 72 6f 67 72 61 6d 73 20 | 69 73 20 74 68 65 6e 20 |rograms |is then |
|00001880| 63 6f 6e 76 65 72 74 65 | 64 20 74 6f 20 61 6e 20 |converte|d to an |
|00001890| 6f 62 6a 65 63 74 20 66 | 69 6c 65 2e 20 54 68 65 |object f|ile. The|
|000018a0| 20 70 72 6f 63 65 73 73 | 20 6f 66 20 63 6f 6d 62 | process| of comb|
|000018b0| 69 6e 69 6e 67 20 74 68 | 65 73 65 20 6f 62 6a 65 |ining th|ese obje|
|000018c0| 63 74 20 66 69 6c 65 73 | 20 69 73 20 6b 6e 6f 77 |ct files| is know|
|000018d0| 6e 20 61 73 20 6c 69 6e | 6b 69 6e 67 2e 20 4d 6f |n as lin|king. Mo|
|000018e0| 72 65 6f 76 65 72 2c 20 | 43 2b 2b 20 68 61 73 20 |reover, |C++ has |
|000018f0| 63 65 72 74 61 69 6e 20 | 69 6e 2d 62 75 69 6c 74 |certain |in-built|
|00001900| 20 66 75 6e 63 74 69 6f | 6e 73 2c 20 77 68 69 63 | functio|ns, whic|
|00001910| 68 20 61 72 65 20 70 72 | 65 73 65 6e 74 20 69 6e |h are pr|esent in|
|00001920| 20 61 20 6c 69 62 72 61 | 72 79 2e 20 54 68 65 73 | a libra|ry. Thes|
|00001930| 65 20 6c 69 62 72 61 72 | 79 20 72 6f 75 74 69 6e |e librar|y routin|
|00001940| 65 73 20 61 6c 73 6f 20 | 6e 65 65 64 20 74 6f 20 |es also |need to |
|00001950| 62 65 20 63 6f 6d 62 69 | 6e 65 64 20 77 69 74 68 |be combi|ned with|
|00001960| 20 74 68 65 20 75 73 65 | 72 2d 77 72 69 74 74 65 | the use|r-writte|
|00001970| 6e 20 70 72 6f 67 72 61 | 6d 2e 06 43 2b 2b 20 50 |n progra|m..C++ P|
|00001980| 52 4f 47 52 41 4d 4d 49 | 4e 47 20 42 41 53 49 43 |ROGRAMMI|NG BASIC|
|00001990| 53 06 54 68 65 72 65 20 | 61 72 65 20 63 65 72 74 |S.There |are cert|
|000019a0| 61 69 6e 20 66 75 6e 64 | 61 6d 65 6e 74 61 6c 73 |ain fund|amentals|
|000019b0| 20 6f 6e 65 20 6e 65 65 | 64 73 20 74 6f 20 6b 6e | one nee|ds to kn|
|000019c0| 6f 77 20 69 6e 20 61 6e | 79 20 6c 61 6e 67 75 61 |ow in an|y langua|
|000019d0| 67 65 20 62 65 66 6f 72 | 65 20 77 72 69 74 69 6e |ge befor|e writin|
|000019e0| 67 20 65 76 65 6e 20 74 | 68 65 20 6d 6f 73 74 20 |g even t|he most |
|000019f0| 65 6c 65 6d 65 6e 74 61 | 72 79 20 70 72 6f 67 72 |elementa|ry progr|
|00001a00| 61 6d 73 20 73 75 63 68 | 20 61 73 20 62 61 73 69 |ams such| as basi|
|00001a10| 63 20 70 72 6f 67 72 61 | 6d 20 63 6f 6e 73 74 72 |c progra|m constr|
|00001a20| 75 63 74 69 6f 6e 2c 20 | 76 61 72 69 61 62 6c 65 |uction, |variable|
|00001a30| 73 20 61 6e 64 20 69 6e | 70 75 74 2f 6f 75 74 70 |s and in|put/outp|
|00001a40| 75 74 2e 20 54 68 65 73 | 65 20 61 72 65 20 64 69 |ut. Thes|e are di|
|00001a50| 73 63 75 73 73 65 64 20 | 69 6e 20 64 65 74 61 69 |scussed |in detai|
|00001a60| 6c 20 69 6e 20 74 68 69 | 73 20 63 68 61 70 74 65 |l in thi|s chapte|
|00001a70| 72 2e 20 49 6e 20 6f 72 | 64 65 72 20 74 6f 20 6c |r. In or|der to l|
|00001a80| 65 61 72 6e 20 61 62 6f | 75 74 20 74 68 65 20 62 |earn abo|ut the b|
|00001a90| 61 73 69 63 20 63 6f 6e | 73 74 72 75 63 74 69 6f |asic con|structio|
|00001aa0| 6e 20 6f 66 20 43 2b 2b | 20 70 72 6f 67 72 61 6d |n of C++| program|
|00001ab0| 73 2c 20 63 6f 6e 73 69 | 64 65 72 20 74 68 65 20 |s, consi|der the |
|00001ac0| 66 6f 6c 6c 6f 77 69 6e | 67 20 65 78 61 6d 70 6c |followin|g exampl|
|00001ad0| 65 2e 06 23 69 6e 63 6c | 75 64 65 20 3c 69 6f 73 |e..#incl|ude <ios|
|00001ae0| 74 72 65 61 6d 2e 68 3e | 06 76 6f 69 64 20 6d 61 |tream.h>|.void ma|
|00001af0| 69 6e 28 29 06 7b 06 63 | 6f 75 74 3c 3c 20 22 57 |in().{.c|out<< "W|
|00001b00| 65 6c 6c 20 62 65 67 75 | 6e 20 69 73 20 68 61 6c |ell begu|n is hal|
|00001b10| 66 20 64 6f 6e 65 22 3b | 06 7d 06 46 55 4e 43 54 |f done";|.}.FUNCT|
|00001b20| 49 4f 4e 53 06 46 75 6e | 63 74 69 6f 6e 73 20 61 |IONS.Fun|ctions a|
|00001b30| 72 65 20 74 68 65 20 62 | 75 69 6c 64 69 6e 67 20 |re the b|uilding |
|00001b40| 62 6c 6f 63 6b 73 20 6f | 66 20 6d 6f 73 74 20 70 |blocks o|f most p|
|00001b50| 72 6f 67 72 61 6d 6d 69 | 6e 67 20 6c 61 6e 67 75 |rogrammi|ng langu|
|00001b60| 61 67 65 73 20 61 6e 64 | 20 43 2b 2b 20 69 73 20 |ages and| C++ is |
|00001b70| 6e 6f 20 65 78 63 65 70 | 74 69 6f 6e 2e 20 4e 6f |no excep|tion. No|
|00001b80| 74 69 63 65 20 74 68 61 | 74 20 74 68 65 20 61 62 |tice tha|t the ab|
|00001b90| 6f 76 65 20 70 72 6f 67 | 72 61 6d 20 68 61 73 20 |ove prog|ram has |
|00001ba0| 6f 6e 6c 79 20 6f 6e 65 | 20 66 75 6e 63 74 69 6f |only one| functio|
|00001bb0| 6e 20 63 61 6c 6c 65 64 | 20 6d 61 69 6e 28 29 2e |n called| main().|
|00001bc0| 20 45 76 65 72 79 20 43 | 2b 2b 20 70 72 6f 67 72 | Every C|++ progr|
|00001bd0| 61 6d 20 6d 75 73 74 20 | 65 73 73 65 6e 74 69 61 |am must |essentia|
|00001be0| 6c 6c 79 20 68 61 76 65 | 20 61 20 6d 61 69 6e 20 |lly have| a main |
|00001bf0| 66 75 6e 63 74 69 6f 6e | 2e 20 57 68 65 6e 20 61 |function|. When a|
|00001c00| 20 43 2b 2b 20 70 72 6f | 67 72 61 6d 20 69 73 20 | C++ pro|gram is |
|00001c10| 72 75 6e 2c 20 74 68 65 | 20 66 69 72 73 74 20 73 |run, the| first s|
|00001c20| 74 61 74 65 6d 65 6e 74 | 20 74 68 61 74 20 69 73 |tatement| that is|
|00001c30| 20 65 78 65 63 75 74 65 | 64 20 69 73 20 74 68 65 | execute|d is the|
|00001c40| 20 62 65 67 69 6e 6e 69 | 6e 67 20 6f 66 20 74 68 | beginni|ng of th|
|00001c50| 65 20 6d 61 69 6e 20 66 | 75 6e 63 74 69 6f 6e 2e |e main f|unction.|
|00001c60| 20 54 68 65 20 70 61 72 | 65 6e 74 68 65 73 65 73 | The par|entheses|
|00001c70| 20 66 6f 6c 6c 6f 77 69 | 6e 67 20 74 68 65 20 6e | followi|ng the n|
|00001c80| 61 6d 65 20 6f 66 20 74 | 68 65 20 66 75 6e 63 74 |ame of t|he funct|
|00001c90| 69 6f 6e 20 64 69 73 74 | 69 6e 67 75 69 73 68 65 |ion dist|inguishe|
|00001ca0| 73 20 69 74 20 66 72 6f | 6d 20 6f 74 68 65 72 20 |s it fro|m other |
|00001cb0| 70 72 6f 67 72 61 6d 20 | 65 6c 65 6d 65 6e 74 73 |program |elements|
|00001cc0| 20 61 6e 64 20 76 61 72 | 69 61 62 6c 65 73 2e 20 | and var|iables. |
|00001cd0| 54 68 65 20 6b 65 79 77 | 6f 72 64 20 76 6f 69 64 |The keyw|ord void|
|00001ce0| 20 70 72 65 63 65 64 69 | 6e 67 20 74 68 65 20 6e | precedi|ng the n|
|00001cf0| 61 6d 65 20 6f 66 20 74 | 68 65 20 66 75 6e 63 74 |ame of t|he funct|
|00001d00| 69 6f 6e 20 73 69 67 6e | 69 66 69 65 73 20 74 68 |ion sign|ifies th|
|00001d10| 61 74 20 74 68 69 73 20 | 66 75 6e 63 74 69 6f 6e |at this |function|
|00001d20| 20 64 6f 65 73 20 6e 6f | 74 20 72 65 74 75 72 6e | does no|t return|
|00001d30| 20 61 20 76 61 6c 75 65 | 20 61 6e 64 20 74 68 65 | a value| and the|
|00001d40| 20 65 6d 70 74 79 20 70 | 61 72 65 6e 74 68 65 73 | empty p|arenthes|
|00001d50| 65 73 20 64 65 6e 6f 74 | 65 20 74 68 61 74 20 74 |es denot|e that t|
|00001d60| 68 69 73 20 66 75 6e 63 | 74 69 6f 6e 20 64 6f 65 |his func|tion doe|
|00001d70| 73 20 6e 6f 74 20 63 61 | 72 72 79 20 61 6e 79 20 |s not ca|rry any |
|00001d80| 61 72 67 75 6d 65 6e 74 | 73 2e 20 52 65 74 75 72 |argument|s. Retur|
|00001d90| 6e 20 76 61 6c 75 65 73 | 20 61 6e 64 20 66 75 6e |n values| and fun|
|00001da0| 63 74 69 6f 6e 20 61 72 | 67 75 6d 65 6e 74 73 20 |ction ar|guments |
|00001db0| 77 69 6c 6c 20 62 65 20 | 64 69 73 63 75 73 73 65 |will be |discusse|
|00001dc0| 64 20 69 6e 20 64 65 74 | 61 69 6c 20 69 6e 20 74 |d in det|ail in t|
|00001dd0| 68 65 20 66 6f 6c 6c 6f | 77 69 6e 67 20 63 68 61 |he follo|wing cha|
|00001de0| 70 74 65 72 73 2e 06 42 | 72 61 63 65 73 20 73 75 |pters..B|races su|
|00001df0| 72 72 6f 75 6e 64 20 74 | 68 65 20 62 6f 64 79 20 |rround t|he body |
|00001e00| 6f 66 20 74 68 65 20 66 | 75 6e 63 74 69 6f 6e 2e |of the f|unction.|
|00001e10| 20 54 68 65 73 65 20 62 | 72 61 63 65 73 20 61 72 | These b|races ar|
|00001e20| 65 20 75 73 65 64 20 74 | 6f 20 64 65 6c 69 6d 69 |e used t|o delimi|
|00001e30| 74 20 61 20 62 6c 6f 63 | 6b 20 6f 66 20 73 74 61 |t a bloc|k of sta|
|00001e40| 74 65 6d 65 6e 74 73 2e | 20 49 6e 20 6f 75 72 20 |tements.| In our |
|00001e50| 65 78 61 6d 70 6c 65 2c | 20 74 68 65 20 66 75 6e |example,| the fun|
|00001e60| 63 74 69 6f 6e 20 62 6f | 64 79 20 63 6f 6e 74 61 |ction bo|dy conta|
|00001e70| 69 6e 73 20 6f 6e 6c 79 | 20 6f 6e 65 20 70 72 6f |ins only| one pro|
|00001e80| 67 72 61 6d 20 73 74 61 | 74 65 6d 65 6e 74 20 77 |gram sta|tement w|
|00001e90| 69 74 68 20 63 6f 75 74 | 2c 20 62 75 74 20 61 20 |ith cout|, but a |
|00001ea0| 66 75 6e 63 74 69 6f 6e | 20 62 6f 64 79 20 63 61 |function| body ca|
|00001eb0| 6e 20 63 6f 6e 73 69 73 | 74 20 6f 66 20 6d 61 6e |n consis|t of man|
|00001ec0| 79 20 73 75 63 68 20 73 | 74 61 74 65 6d 65 6e 74 |y such s|tatement|
|00001ed0| 73 2e 06 50 52 4f 47 52 | 41 4d 20 53 54 41 54 45 |s..PROGR|AM STATE|
|00001ee0| 4d 45 4e 54 53 06 50 72 | 6f 67 72 61 6d 20 73 74 |MENTS.Pr|ogram st|
|00001ef0| 61 74 65 6d 65 6e 74 73 | 20 61 72 65 20 74 68 65 |atements| are the|
|00001f00| 20 66 75 6e 64 61 6d 65 | 6e 74 61 6c 20 62 75 69 | fundame|ntal bui|
|00001f10| 6c 64 69 6e 67 20 62 6c | 6f 63 6b 73 20 6f 66 20 |lding bl|ocks of |
|00001f20| 61 6e 79 20 70 72 6f 67 | 72 61 6d 6d 69 6e 67 20 |any prog|ramming |
|00001f30| 6c 61 6e 67 75 61 67 65 | 2e 20 54 68 65 79 20 61 |language|. They a|
|00001f40| 72 65 20 69 6e 73 74 72 | 75 63 74 69 6f 6e 73 20 |re instr|uctions |
|00001f50| 67 69 76 65 6e 20 74 6f | 20 74 68 65 20 63 6f 6d |given to| the com|
|00001f60| 70 75 74 65 72 2e 20 49 | 6e 20 6f 75 72 20 65 78 |puter. I|n our ex|
|00001f70| 61 6d 70 6c 65 2c 20 74 | 68 65 20 66 6f 6c 6c 6f |ample, t|he follo|
|00001f80| 77 69 6e 67 20 6c 69 6e | 65 20 69 73 20 61 20 70 |wing lin|e is a p|
|00001f90| 72 6f 67 72 61 6d 20 73 | 74 61 74 65 6d 65 6e 74 |rogram s|tatement|
|00001fa0| 3a 06 63 6f 75 74 3c 3c | 20 22 57 65 6c 6c 20 62 |:.cout<<| "Well b|
|00001fb0| 65 67 75 6e 20 69 73 20 | 68 61 6c 66 20 64 6f 6e |egun is |half don|
|00001fc0| 65 22 3b 06 45 76 65 72 | 79 20 70 72 6f 67 72 61 |e";.Ever|y progra|
|00001fd0| 6d 20 73 74 61 74 65 6d | 65 6e 74 20 69 6e 20 43 |m statem|ent in C|
|00001fe0| 2b 2b 20 65 6e 64 73 20 | 77 69 74 68 20 61 20 73 |++ ends |with a s|
|00001ff0| 65 6d 69 63 6f 6c 6f 6e | 2e 20 49 66 20 74 68 65 |emicolon|. If the|
|00002000| 20 73 65 6d 69 63 6f 6c | 6f 6e 20 69 73 20 6e 6f | semicol|on is no|
|00002010| 74 20 70 6c 61 63 65 64 | 20 74 68 65 20 63 6f 6d |t placed| the com|
|00002020| 70 69 6c 65 72 20 73 68 | 6f 77 73 20 61 6e 20 65 |piler sh|ows an e|
|00002030| 72 72 6f 72 2e 06 50 52 | 45 50 52 4f 43 45 53 53 |rror..PR|EPROCESS|
|00002040| 4f 52 20 44 49 52 45 43 | 54 49 56 45 53 06 54 68 |OR DIREC|TIVES.Th|
|00002050| 65 20 66 69 72 73 74 20 | 6c 69 6e 65 20 6f 66 20 |e first |line of |
|00002060| 74 68 65 20 70 72 6f 67 | 72 61 6d 06 23 69 6e 63 |the prog|ram.#inc|
|00002070| 6c 75 64 65 20 3c 69 6f | 73 74 72 65 61 6d 2e 68 |lude <io|stream.h|
|00002080| 3e 06 69 73 20 63 61 6c | 6c 65 64 20 61 20 70 72 |>.is cal|led a pr|
|00002090| 65 70 72 6f 63 65 73 73 | 6f 72 20 64 69 72 65 63 |eprocess|or direc|
|000020a0| 74 69 76 65 2e 20 50 72 | 6f 67 72 61 6d 20 73 74 |tive. Pr|ogram st|
|000020b0| 61 74 65 6d 65 6e 74 73 | 2c 20 61 73 20 77 65 20 |atements|, as we |
|000020c0| 6b 6e 6f 77 2c 20 61 72 | 65 20 69 6e 73 74 72 75 |know, ar|e instru|
|000020d0| 63 74 69 6f 6e 73 20 67 | 69 76 65 6e 20 74 6f 20 |ctions g|iven to |
|000020e0| 74 68 65 20 63 6f 6d 70 | 75 74 65 72 2e 20 41 20 |the comp|uter. A |
|000020f0| 70 72 65 70 72 6f 63 65 | 73 73 6f 72 20 64 69 72 |preproce|ssor dir|
|00002100| 65 63 74 69 76 65 20 69 | 73 20 61 6e 20 69 6e 73 |ective i|s an ins|
|00002110| 74 72 75 63 74 69 6f 6e | 20 67 69 76 65 6e 20 74 |truction| given t|
|00002120| 6f 20 74 68 65 20 63 6f | 6d 70 69 6c 65 72 2e 20 |o the co|mpiler. |
|00002130| 54 68 65 20 70 72 65 70 | 72 6f 63 65 73 73 6f 72 |The prep|rocessor|
|00002140| 20 64 69 72 65 63 74 69 | 76 65 20 23 69 6e 63 6c | directi|ve #incl|
|00002150| 75 64 65 20 74 65 6c 6c | 73 20 74 68 65 20 63 6f |ude tell|s the co|
|00002160| 6d 70 69 6c 65 72 20 74 | 6f 20 69 6e 73 65 72 74 |mpiler t|o insert|
|00002170| 20 61 6e 6f 74 68 65 72 | 20 66 69 6c 65 20 69 6e | another| file in|
|00002180| 74 6f 20 74 68 65 20 73 | 6f 75 72 63 65 20 66 69 |to the s|ource fi|
|00002190| 6c 65 2e 20 49 6e 20 6f | 75 72 20 65 78 61 6d 70 |le. In o|ur examp|
|000021a0| 6c 65 2c 20 74 68 65 20 | 70 72 65 70 72 6f 63 65 |le, the |preproce|
|000021b0| 73 73 6f 72 20 64 69 72 | 65 63 74 69 76 65 20 23 |ssor dir|ective #|
|000021c0| 69 6e 63 6c 75 64 65 20 | 74 65 6c 6c 73 20 74 68 |include |tells th|
|000021d0| 65 20 63 6f 6d 70 69 6c | 65 72 20 74 6f 20 61 64 |e compil|er to ad|
|000021e0| 64 20 74 68 65 20 73 6f | 75 72 63 65 20 66 69 6c |d the so|urce fil|
|000021f0| 65 20 69 6f 73 74 72 65 | 61 6d 2e 68 20 74 6f 20 |e iostre|am.h to |
|00002200| 74 68 65 20 70 72 6f 67 | 72 61 6d 20 66 69 6c 65 |the prog|ram file|
|00002210| 20 62 65 66 6f 72 65 20 | 63 6f 6d 70 69 6c 61 74 | before |compilat|
|00002220| 69 6f 6e 2e 20 57 68 79 | 20 69 73 20 74 68 69 73 |ion. Why| is this|
|00002230| 20 64 6f 6e 65 3f 20 69 | 6f 73 74 72 65 61 6d 2e | done? i|ostream.|
|00002240| 68 20 69 73 20 61 6e 20 | 65 78 61 6d 70 6c 65 20 |h is an |example |
|00002250| 6f 66 20 61 20 68 65 61 | 64 65 72 20 66 69 6c 65 |of a hea|der file|
|00002260| 20 28 61 6c 73 6f 20 6b | 6e 6f 77 6e 20 61 73 20 | (also k|nown as |
|00002270| 69 6e 63 6c 75 64 65 20 | 66 69 6c 65 29 2e 20 54 |include |file). T|
|00002280| 68 69 73 20 66 69 6c 65 | 20 63 6f 6e 74 61 69 6e |his file| contain|
|00002290| 73 20 64 65 63 6c 61 72 | 61 74 69 6f 6e 73 20 74 |s declar|ations t|
|000022a0| 68 61 74 20 61 72 65 20 | 6e 65 65 64 65 64 20 62 |hat are |needed b|
|000022b0| 79 20 74 68 65 20 63 6f | 75 74 20 69 64 65 6e 74 |y the co|ut ident|
|000022c0| 69 66 69 65 72 20 61 6e | 64 20 3c 3c 20 6f 70 65 |ifier an|d << ope|
|000022d0| 72 61 74 6f 72 2e 20 57 | 69 74 68 6f 75 74 20 74 |rator. W|ithout t|
|000022e0| 68 65 73 65 20 64 65 63 | 6c 61 72 61 74 69 6f 6e |hese dec|laration|
|000022f0| 73 20 74 68 65 20 63 6f | 6d 70 69 6c 65 72 20 77 |s the co|mpiler w|
|00002300| 69 6c 6c 20 6e 6f 74 20 | 72 65 63 6f 67 6e 69 7a |ill not |recogniz|
|00002310| 65 20 74 68 65 73 65 20 | 74 77 6f 20 6b 65 79 77 |e these |two keyw|
|00002320| 6f 72 64 73 20 61 6e 64 | 20 67 69 76 65 73 20 61 |ords and| gives a|
|00002330| 6e 20 65 72 72 6f 72 20 | 64 75 72 69 6e 67 20 63 |n error |during c|
|00002340| 6f 6d 70 69 6c 61 74 69 | 6f 6e 2e 06 54 68 65 72 |ompilati|on..Ther|
|00002350| 65 20 61 72 65 20 61 20 | 6e 75 6d 62 65 72 20 6f |e are a |number o|
|00002360| 66 20 6f 74 68 65 72 20 | 68 65 61 64 65 72 20 66 |f other |header f|
|00002370| 69 6c 65 73 2c 20 66 6f | 72 20 65 78 61 6d 70 6c |iles, fo|r exampl|
|00002380| 65 20 73 74 64 69 6f 2e | 68 2c 20 64 6f 73 2e 68 |e stdio.|h, dos.h|
|00002390| 2c 20 73 74 72 69 6e 67 | 2e 68 2c 20 63 6f 6e 69 |, string|.h, coni|
|000023a0| 6f 2e 68 20 65 74 63 2e | 06 56 41 52 49 41 42 4c |o.h etc.|.VARIABL|
|000023b0| 45 53 20 41 4e 44 20 43 | 4f 4e 53 54 41 4e 54 53 |ES AND C|ONSTANTS|
|000023c0| 06 56 61 72 69 61 62 6c | 65 73 20 61 72 65 20 74 |.Variabl|es are t|
|000023d0| 68 65 20 6d 6f 73 74 20 | 66 75 6e 64 61 6d 65 6e |he most |fundamen|
|000023e0| 74 61 6c 20 70 61 72 74 | 20 6f 66 20 61 6e 79 20 |tal part| of any |
|000023f0| 70 72 6f 67 72 61 6d 6d | 69 6e 67 20 6c 61 6e 67 |programm|ing lang|
|00002400| 75 61 67 65 2e 20 41 73 | 20 74 68 65 20 6e 61 6d |uage. As| the nam|
|00002410| 65 20 73 75 67 67 65 73 | 74 73 2c 20 76 61 72 69 |e sugges|ts, vari|
|00002420| 61 62 6c 65 73 20 63 61 | 6e 20 76 61 72 79 20 69 |ables ca|n vary i|
|00002430| 6e 20 76 61 6c 75 65 2e | 20 54 68 65 79 20 63 61 |n value.| They ca|
|00002440| 6e 20 68 61 76 65 20 64 | 69 66 66 65 72 65 6e 74 |n have d|ifferent|
|00002450| 20 76 61 6c 75 65 73 20 | 61 74 20 64 69 66 66 65 | values |at diffe|
|00002460| 72 65 6e 74 20 74 69 6d | 65 73 20 28 65 78 65 63 |rent tim|es (exec|
|00002470| 75 74 69 6f 6e 29 2e 20 | 54 68 65 20 74 65 72 6d |ution). |The term|
|00002480| 20 76 61 72 69 61 62 6c | 65 20 69 73 20 61 20 73 | variabl|e is a s|
|00002490| 79 6d 62 6f 6c 69 63 20 | 6e 61 6d 65 20 67 69 76 |ymbolic |name giv|
|000024a0| 65 6e 20 74 6f 20 61 6e | 79 20 76 61 6c 75 65 2e |en to an|y value.|
|000024b0| 20 49 74 20 63 61 6e 20 | 61 6c 73 6f 20 62 65 20 | It can |also be |
|000024c0| 64 65 66 69 6e 65 64 20 | 61 73 20 61 20 73 79 6d |defined |as a sym|
|000024d0| 62 6f 6c 20 74 68 61 74 | 20 72 65 70 72 65 73 65 |bol that| represe|
|000024e0| 6e 74 73 20 74 68 65 20 | 73 74 6f 72 61 67 65 20 |nts the |storage |
|000024f0| 6c 6f 63 61 74 69 6f 6e | 20 69 6e 20 61 20 63 6f |location| in a co|
|00002500| 6d 70 75 74 65 72 27 73 | 20 6d 65 6d 6f 72 79 2e |mputer's| memory.|
|00002510| 20 54 68 65 20 69 6e 66 | 6f 72 6d 61 74 69 6f 6e | The inf|ormation|
|00002520| 20 74 68 61 74 20 69 73 | 20 73 74 6f 72 65 64 20 | that is| stored |
|00002530| 69 6e 20 74 68 61 74 20 | 6c 6f 63 61 74 69 6f 6e |in that |location|
|00002540| 20 69 73 20 63 61 6c 6c | 65 64 20 69 74 73 20 76 | is call|ed its v|
|00002550| 61 6c 75 65 2e 20 4d 6f | 73 74 20 70 72 6f 67 72 |alue. Mo|st progr|
|00002560| 61 6d 6d 69 6e 67 20 6c | 61 6e 67 75 61 67 65 73 |amming l|anguages|
|00002570| 20 68 61 76 65 20 67 65 | 6e 65 72 61 6c 20 76 61 | have ge|neral va|
|00002580| 72 69 61 62 6c 65 20 74 | 79 70 65 73 2c 20 73 75 |riable t|ypes, su|
|00002590| 63 68 20 61 73 20 69 6e | 74 65 67 65 72 73 2c 20 |ch as in|tegers, |
|000025a0| 63 68 61 72 61 63 74 65 | 72 73 20 61 6e 64 20 66 |characte|rs and f|
|000025b0| 6c 6f 61 74 69 6e 67 20 | 70 6f 69 6e 74 73 2e 06 |loating |points..|
|000025c0| 41 73 20 6f 70 70 6f 73 | 65 64 20 74 6f 20 76 61 |As oppos|ed to va|
|000025d0| 72 69 61 62 6c 65 73 2c | 20 63 6f 6e 73 74 61 6e |riables,| constan|
|000025e0| 74 73 20 63 6f 6e 74 61 | 69 6e 20 76 61 6c 75 65 |ts conta|in value|
|000025f0| 73 2c 20 77 68 69 63 68 | 20 72 65 6d 61 69 6e 20 |s, which| remain |
|00002600| 74 68 65 20 73 61 6d 65 | 20 74 68 72 6f 75 67 68 |the same| through|
|00002610| 6f 75 74 20 74 68 65 20 | 65 78 69 73 74 65 6e 63 |out the |existenc|
|00002620| 65 20 6f 66 20 61 20 70 | 72 6f 67 72 61 6d 2e 20 |e of a p|rogram. |
|00002630| 54 68 65 20 6e 75 6d 62 | 65 72 20 32 30 20 69 73 |The numb|er 20 is|
|00002640| 20 61 6e 20 69 6e 74 65 | 67 65 72 20 63 6f 6e 73 | an inte|ger cons|
|00002650| 74 61 6e 74 2e 20 54 68 | 65 20 73 74 61 74 65 6d |tant. Th|e statem|
|00002660| 65 6e 74 20 22 57 65 6c | 6c 20 62 65 67 75 6e 20 |ent "Wel|l begun |
|00002670| 69 73 20 68 61 6c 66 20 | 64 6f 6e 65 22 20 69 6e |is half |done" in|
|00002680| 20 6f 75 72 20 70 72 6f | 67 72 61 6d 20 69 73 20 | our pro|gram is |
|00002690| 61 20 73 74 72 69 6e 67 | 20 63 6f 6e 73 74 61 6e |a string| constan|
|000026a0| 74 2e 20 53 69 6d 69 6c | 61 72 6c 79 2c 20 27 61 |t. Simil|arly, 'a|
|000026b0| 27 20 69 73 20 61 20 63 | 68 61 72 61 63 74 65 72 |' is a c|haracter|
|000026c0| 20 63 6f 6e 73 74 61 6e | 74 2e 20 41 20 63 68 61 | constan|t. A cha|
|000026d0| 72 61 63 74 65 72 20 63 | 6f 6e 73 74 61 6e 74 20 |racter c|onstant |
|000026e0| 69 73 20 73 70 65 63 69 | 66 69 65 64 20 77 69 74 |is speci|fied wit|
|000026f0| 68 20 73 69 6e 67 6c 65 | 20 71 75 6f 74 61 74 69 |h single| quotati|
|00002700| 6f 6e 20 6d 61 72 6b 73 | 20 61 72 6f 75 6e 64 20 |on marks| around |
|00002710| 69 74 2c 20 77 68 65 72 | 65 61 73 20 61 20 73 74 |it, wher|eas a st|
|00002720| 72 69 6e 67 20 75 73 65 | 73 20 64 6f 75 62 6c 65 |ring use|s double|
|00002730| 20 71 75 6f 74 61 74 69 | 6f 6e 20 6d 61 72 6b 73 | quotati|on marks|
|00002740| 2e 06 56 41 52 49 41 42 | 4c 45 20 4e 41 4d 45 53 |..VARIAB|LE NAMES|
|00002750| 06 53 69 6e 63 65 20 61 | 20 76 61 72 69 61 62 6c |.Since a| variabl|
|00002760| 65 20 69 73 20 61 20 73 | 79 6d 62 6f 6c 69 63 20 |e is a s|ymbolic |
|00002770| 6e 61 6d 65 20 67 69 76 | 65 6e 20 74 6f 20 61 20 |name giv|en to a |
|00002780| 76 61 6c 75 65 2c 20 74 | 68 65 72 65 20 61 72 65 |value, t|here are|
|00002790| 20 73 6f 6d 65 20 6e 61 | 6d 69 6e 67 20 63 6f 6e | some na|ming con|
|000027a0| 76 65 6e 74 69 6f 6e 73 | 20 74 68 61 74 20 6d 75 |ventions| that mu|
|000027b0| 73 74 20 62 65 20 66 6f | 6c 6c 6f 77 65 64 2e 20 |st be fo|llowed. |
|000027c0| 42 6f 74 68 20 75 70 70 | 65 72 63 61 73 65 20 61 |Both upp|ercase a|
|000027d0| 6e 64 20 6c 6f 77 65 72 | 63 61 73 65 20 6c 65 74 |nd lower|case let|
|000027e0| 74 65 72 73 20 61 6e 64 | 20 64 69 67 69 74 73 20 |ters and| digits |
|000027f0| 66 72 6f 6d 20 31 20 74 | 6f 20 39 20 63 61 6e 20 |from 1 t|o 9 can |
|00002800| 62 65 20 75 73 65 64 2e | 20 54 68 65 20 75 6e 64 |be used.| The und|
|00002810| 65 72 73 63 6f 72 65 20 | 27 5f 27 20 73 69 67 6e |erscore |'_' sign|
|00002820| 20 63 61 6e 20 61 6c 73 | 6f 20 62 65 20 75 73 65 | can als|o be use|
|00002830| 64 2e 20 54 68 65 20 66 | 69 72 73 74 20 63 68 61 |d. The f|irst cha|
|00002840| 72 61 63 74 65 72 20 6f | 66 20 74 68 65 20 6e 61 |racter o|f the na|
|00002850| 6d 65 20 6d 75 73 74 20 | 62 65 20 61 20 6c 65 74 |me must |be a let|
|00002860| 74 65 72 20 6f 72 20 75 | 6e 64 65 72 73 63 6f 72 |ter or u|nderscor|
|00002870| 65 2e 20 54 68 65 20 63 | 6f 6d 70 69 6c 65 72 20 |e. The c|ompiler |
|00002880| 64 69 73 74 69 6e 67 75 | 69 73 68 65 73 20 62 65 |distingu|ishes be|
|00002890| 74 77 65 65 6e 20 75 70 | 70 65 72 63 61 73 65 20 |tween up|percase |
|000028a0| 61 6e 64 20 6c 6f 77 65 | 72 63 61 73 65 20 6c 65 |and lowe|rcase le|
|000028b0| 74 74 65 72 73 2e 20 4b | 65 79 77 6f 72 64 73 20 |tters. K|eywords |
|000028c0| 63 61 6e 6e 6f 74 20 62 | 65 20 75 73 65 64 20 61 |cannot b|e used a|
|000028d0| 73 20 76 61 72 69 61 62 | 6c 65 20 6e 61 6d 65 73 |s variab|le names|
|000028e0| 2e 06 44 41 54 41 20 54 | 59 50 45 53 06 41 73 20 |..DATA T|YPES.As |
|000028f0| 6d 65 6e 74 69 6f 6e 65 | 64 20 65 61 72 6c 69 65 |mentione|d earlie|
|00002900| 72 2c 20 65 76 65 72 79 | 20 6c 61 6e 67 75 61 67 |r, every| languag|
|00002910| 65 20 68 61 73 20 69 74 | 73 20 6f 77 6e 20 73 65 |e has it|s own se|
|00002920| 74 20 6f 66 20 64 61 74 | 61 20 74 79 70 65 73 2e |t of dat|a types.|
|00002930| 20 57 65 20 77 69 6c 6c | 20 6e 6f 77 20 6c 65 61 | We will| now lea|
|00002940| 72 6e 20 61 62 6f 75 74 | 20 74 68 65 20 64 61 74 |rn about| the dat|
|00002950| 61 20 74 79 70 65 73 20 | 6f 66 20 43 2b 2b 20 69 |a types |of C++ i|
|00002960| 6e 20 64 65 74 61 69 6c | 2e 06 49 6e 74 65 67 65 |n detail|..Intege|
|00002970| 72 20 64 61 74 61 20 74 | 79 70 65 73 06 49 6e 74 |r data t|ypes.Int|
|00002980| 65 67 65 72 20 76 61 72 | 69 61 62 6c 65 73 20 65 |eger var|iables e|
|00002990| 78 69 73 74 20 69 6e 20 | 73 65 76 65 72 61 6c 20 |xist in |several |
|000029a0| 73 69 7a 65 73 2c 20 61 | 6e 64 20 74 68 65 20 6d |sizes, a|nd the m|
|000029b0| 6f 73 74 20 63 6f 6d 6d | 6f 6e 6c 79 20 75 73 65 |ost comm|only use|
|000029c0| 64 20 69 6e 74 65 67 65 | 72 20 64 61 74 61 20 74 |d intege|r data t|
|000029d0| 79 70 65 20 69 73 20 69 | 6e 74 2e 20 54 68 69 73 |ype is i|nt. This|
|000029e0| 20 64 61 74 61 20 74 79 | 70 65 20 72 65 71 75 69 | data ty|pe requi|
|000029f0| 72 65 73 20 74 77 6f 20 | 62 79 74 65 73 20 6f 66 |res two |bytes of|
|00002a00| 20 6d 65 6d 6f 72 79 2e | 20 54 68 69 73 20 74 79 | memory.| This ty|
|00002a10| 70 65 20 6f 66 20 76 61 | 72 69 61 62 6c 65 20 63 |pe of va|riable c|
|00002a20| 61 6e 6e 6f 74 20 73 74 | 6f 72 65 20 6e 75 6d 62 |annot st|ore numb|
|00002a30| 65 72 73 20 77 69 74 68 | 20 64 65 63 69 6d 61 6c |ers with| decimal|
|00002a40| 73 2e 20 54 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |s. The f|ollowing|
|00002a50| 20 65 78 61 6d 70 6c 65 | 20 69 6c 6c 75 73 74 72 | example| illustr|
|00002a60| 61 74 65 73 20 74 68 65 | 20 75 73 61 67 65 20 6f |ates the| usage o|
|00002a70| 66 20 69 6e 74 65 67 65 | 72 20 76 61 72 69 61 62 |f intege|r variab|
|00002a80| 6c 65 73 2e 06 23 69 6e | 63 6c 75 64 65 3c 69 6f |les..#in|clude<io|
|00002a90| 73 74 72 65 61 6d 2e 68 | 3e 06 76 6f 69 64 20 6d |stream.h|>.void m|
|00002aa0| 61 69 6e 28 29 06 7b 06 | 69 6e 74 20 61 3b 06 69 |ain().{.|int a;.i|
|00002ab0| 6e 74 20 62 3b 06 61 3d | 32 30 3b 06 62 3d 61 2b |nt b;.a=|20;.b=a+|
|00002ac0| 34 30 3b 06 63 6f 75 74 | 3c 3c 61 3b 06 63 6f 75 |40;.cout|<<a;.cou|
|00002ad0| 74 3c 3c 62 3b 06 7d 06 | 54 68 65 20 73 74 61 74 |t<<b;.}.|The stat|
|00002ae0| 65 6d 65 6e 74 20 69 6e | 74 20 61 3b 20 64 65 63 |ement in|t a; dec|
|00002af0| 6c 61 72 65 73 20 61 20 | 76 61 72 69 61 62 6c 65 |lares a |variable|
|00002b00| 20 27 61 27 20 61 6e 64 | 20 73 70 65 63 69 66 69 | 'a' and| specifi|
|00002b10| 65 73 20 74 68 61 74 20 | 69 74 73 20 64 61 74 61 |es that |its data|
|00002b20| 20 74 79 70 65 20 69 73 | 20 69 6e 74 65 67 65 72 | type is| integer|
|00002b30| 2e 20 49 74 20 69 73 20 | 61 20 67 6f 6f 64 20 70 |. It is |a good p|
|00002b40| 72 61 63 74 69 63 65 20 | 74 6f 20 64 65 66 69 6e |ractice |to defin|
|00002b50| 65 20 61 20 76 61 72 69 | 61 62 6c 65 20 69 6e 20 |e a vari|able in |
|00002b60| 74 68 65 20 66 69 72 73 | 74 20 6c 69 6e 65 20 6f |the firs|t line o|
|00002b70| 66 20 74 68 65 20 70 72 | 6f 67 72 61 6d 2e 20 48 |f the pr|ogram. H|
|00002b80| 6f 77 65 76 65 72 2c 20 | 69 74 20 6d 61 79 20 61 |owever, |it may a|
|00002b90| 6c 73 6f 20 62 65 20 64 | 65 66 69 6e 65 64 20 61 |lso be d|efined a|
|00002ba0| 6e 79 77 68 65 72 65 20 | 69 6e 20 74 68 65 20 70 |nywhere |in the p|
|00002bb0| 72 6f 67 72 61 6d 20 62 | 65 66 6f 72 65 20 62 65 |rogram b|efore be|
|00002bc0| 69 6e 67 20 75 73 65 64 | 2e 06 44 65 63 6c 61 72 |ing used|..Declar|
|00002bd0| 61 74 69 6f 6e 20 61 6e | 64 20 69 6e 69 74 69 61 |ation an|d initia|
|00002be0| 6c 69 7a 61 74 69 6f 6e | 06 41 20 64 65 63 6c 61 |lization|.A decla|
|00002bf0| 72 61 74 69 6f 6e 20 69 | 6e 74 72 6f 64 75 63 65 |ration i|ntroduce|
|00002c00| 73 20 61 20 76 61 72 69 | 61 62 6c 65 20 6e 61 6d |s a vari|able nam|
|00002c10| 65 20 61 6e 64 20 69 74 | 73 20 64 61 74 61 20 74 |e and it|s data t|
|00002c20| 79 70 65 20 69 6e 20 74 | 68 65 20 70 72 6f 67 72 |ype in t|he progr|
|00002c30| 61 6d 2e 20 48 6f 77 65 | 76 65 72 2c 20 69 74 20 |am. Howe|ver, it |
|00002c40| 64 6f 65 73 20 6e 6f 74 | 20 72 65 73 65 72 76 65 |does not| reserve|
|00002c50| 20 6d 65 6d 6f 72 79 20 | 66 6f 72 20 74 68 65 20 | memory |for the |
|00002c60| 76 61 72 69 61 62 6c 65 | 2e 20 46 6f 72 20 69 6e |variable|. For in|
|00002c70| 73 74 61 6e 63 65 06 69 | 6e 74 20 61 3b 06 4f 6e |stance.i|nt a;.On|
|00002c80| 20 74 68 65 20 6f 74 68 | 65 72 20 68 61 6e 64 2c | the oth|er hand,|
|00002c90| 20 69 6e 69 74 69 61 6c | 69 7a 61 74 69 6f 6e 20 | initial|ization |
|00002ca0| 6f 66 20 76 61 72 69 61 | 62 6c 65 73 20 69 6e 76 |of varia|bles inv|
|00002cb0| 6f 6c 76 65 73 20 61 6c | 6c 6f 63 61 74 69 6e 67 |olves al|locating|
|00002cc0| 20 61 20 76 61 6c 75 65 | 20 74 6f 20 74 68 65 20 | a value| to the |
|00002cd0| 76 61 72 69 61 62 6c 65 | 20 61 6c 6f 6e 67 77 69 |variable| alongwi|
|00002ce0| 74 68 20 64 65 66 69 6e | 69 6e 67 20 69 74 2e 20 |th defin|ing it. |
|00002cf0| 46 6f 72 20 65 78 61 6d | 70 6c 65 06 69 6e 74 20 |For exam|ple.int |
|00002d00| 61 3d 31 30 3b 06 43 68 | 61 72 61 63 74 65 72 20 |a=10;.Ch|aracter |
|00002d10| 64 61 74 61 20 74 79 70 | 65 06 43 68 61 72 61 63 |data typ|e.Charac|
|00002d20| 74 65 72 20 76 61 72 69 | 61 62 6c 65 73 20 6f 63 |ter vari|ables oc|
|00002d30| 63 75 70 79 20 31 20 62 | 79 74 65 20 6f 66 20 6d |cupy 1 b|yte of m|
|00002d40| 65 6d 6f 72 79 2e 20 54 | 68 65 20 6b 65 79 77 6f |emory. T|he keywo|
|00002d50| 72 64 20 75 73 65 64 20 | 74 6f 20 72 65 70 72 65 |rd used |to repre|
|00002d60| 73 65 6e 74 20 63 68 61 | 72 61 63 74 65 72 20 76 |sent cha|racter v|
|00002d70| 61 72 69 61 62 6c 65 73 | 20 69 73 20 63 68 61 72 |ariables| is char|
|00002d80| 2e 20 54 68 69 73 20 74 | 79 70 65 20 73 74 6f 72 |. This t|ype stor|
|00002d90| 65 73 20 69 6e 74 65 67 | 65 72 73 20 69 6e 20 74 |es integ|ers in t|
|00002da0| 68 65 20 72 61 6e 67 65 | 20 6f 66 20 2d 31 32 38 |he range| of -128|
|00002db0| 20 74 6f 20 31 32 37 2e | 06 23 69 6e 63 6c 75 64 | to 127.|.#includ|
|00002dc0| 65 3c 69 6f 73 74 72 65 | 61 6d 2e 68 3e 06 76 6f |e<iostre|am.h>.vo|
|00002dd0| 69 64 20 6d 61 69 6e 28 | 29 06 7b 06 63 68 61 72 |id main(|).{.char|
|00002de0| 20 61 6c 70 68 61 3d 27 | 41 27 3b 06 63 6f 75 74 | alpha='|A';.cout|
|00002df0| 20 3c 3c 61 6c 70 68 61 | 3b 06 7d 06 46 6c 6f 61 | <<alpha|;.}.Floa|
|00002e00| 74 20 64 61 74 61 20 74 | 79 70 65 06 46 6c 6f 61 |t data t|ype.Floa|
|00002e10| 74 69 6e 67 20 70 6f 69 | 6e 74 20 76 61 72 69 61 |ting poi|nt varia|
|00002e20| 62 6c 65 73 20 61 72 65 | 20 75 73 65 64 20 74 6f |bles are| used to|
|00002e30| 20 72 65 70 72 65 73 65 | 6e 74 20 6e 75 6d 62 65 | represe|nt numbe|
|00002e40| 72 73 20 77 69 74 68 20 | 61 20 64 65 63 69 6d 61 |rs with |a decima|
|00002e50| 6c 20 70 6c 61 63 65 20 | 6c 69 6b 65 20 33 2e 31 |l place |like 3.1|
|00002e60| 34 39 38 20 6f 72 20 2d | 38 39 2e 37 39 20 65 74 |498 or -|89.79 et|
|00002e70| 63 2e 20 54 68 65 73 65 | 20 76 61 72 69 61 62 6c |c. These| variabl|
|00002e80| 65 73 20 61 72 65 20 75 | 73 65 64 20 74 6f 20 72 |es are u|sed to r|
|00002e90| 65 70 72 65 73 65 6e 74 | 20 72 65 61 6c 20 6e 75 |epresent| real nu|
|00002ea0| 6d 62 65 72 73 2e 20 54 | 68 65 20 66 6f 6c 6c 6f |mbers. T|he follo|
|00002eb0| 77 69 6e 67 20 65 78 61 | 6d 70 6c 65 20 63 61 6c |wing exa|mple cal|
|00002ec0| 63 75 6c 61 74 65 73 20 | 74 68 65 20 61 72 65 61 |culates |the area|
|00002ed0| 20 6f 66 20 61 20 63 69 | 72 63 6c 65 20 61 6e 64 | of a ci|rcle and|
|00002ee0| 20 64 69 73 70 6c 61 79 | 73 20 69 74 2e 20 54 68 | display|s it. Th|
|00002ef0| 65 20 6b 65 79 77 6f 72 | 64 20 66 6c 6f 61 74 20 |e keywor|d float |
|00002f00| 72 65 70 72 65 73 65 6e | 74 73 20 74 68 65 73 65 |represen|ts these|
|00002f10| 20 76 61 72 69 61 62 6c | 65 73 06 23 69 6e 63 6c | variabl|es.#incl|
|00002f20| 75 64 65 3c 69 6f 73 74 | 72 65 61 6d 2e 68 3e 06 |ude<iost|ream.h>.|
|00002f30| 76 6f 69 64 20 6d 61 69 | 6e 28 29 06 7b 06 69 6e |void mai|n().{.in|
|00002f40| 74 20 72 61 64 3d 34 3b | 06 66 6c 6f 61 74 20 70 |t rad=4;|.float p|
|00002f50| 3d 33 2e 31 34 06 63 6f | 75 74 3c 3c 22 54 68 65 |=3.14.co|ut<<"The|
|00002f60| 20 61 72 65 61 20 6f 66 | 20 74 68 65 20 63 69 72 | area of| the cir|
|00002f70| 63 6c 65 20 69 73 20 3a | 22 3b 06 63 6f 75 74 3c |cle is :|";.cout<|
|00002f80| 3c 70 2a 72 61 64 3b 06 | 7d 06 4c 6f 6e 67 20 64 |<p*rad;.|}.Long d|
|00002f90| 61 74 61 20 74 79 70 65 | 06 54 68 65 20 6c 6f 6e |ata type|.The lon|
|00002fa0| 67 20 64 61 74 61 20 74 | 79 70 65 20 69 73 20 73 |g data t|ype is s|
|00002fb0| 69 6d 69 6c 61 72 20 74 | 6f 20 74 68 65 20 69 6e |imilar t|o the in|
|00002fc0| 74 20 64 61 74 61 20 74 | 79 70 65 2c 20 65 78 63 |t data t|ype, exc|
|00002fd0| 65 70 74 20 74 68 61 74 | 20 69 74 20 6f 63 63 75 |ept that| it occu|
|00002fe0| 70 69 65 73 20 34 20 62 | 79 74 65 73 20 6f 66 20 |pies 4 b|ytes of |
|00002ff0| 6d 65 6d 6f 72 79 2e 20 | 54 68 61 74 20 69 73 20 |memory. |That is |
|00003000| 77 68 79 20 69 74 20 63 | 61 6e 20 68 6f 6c 64 20 |why it c|an hold |
|00003010| 61 20 6c 61 72 67 65 72 | 20 72 61 6e 67 65 20 6f |a larger| range o|
|00003020| 66 20 76 61 6c 75 65 73 | 2c 20 66 72 6f 6d 20 2d |f values|, from -|
|00003030| 32 2c 31 34 37 2c 34 38 | 33 2c 36 34 38 20 74 6f |2,147,48|3,648 to|
|00003040| 20 32 2c 31 34 37 2c 34 | 38 33 2c 36 34 37 2e 20 | 2,147,4|83,647. |
|00003050| 54 68 65 20 6c 6f 6e 67 | 20 74 79 70 65 20 63 61 |The long| type ca|
|00003060| 6e 20 61 6c 73 6f 20 62 | 65 20 64 65 66 69 6e 65 |n also b|e define|
|00003070| 64 20 61 73 20 6c 6f 6e | 67 20 69 6e 74 2e 06 6c |d as lon|g int..l|
|00003080| 6f 6e 67 20 69 6e 74 20 | 61 3b 06 6c 6f 6e 67 20 |ong int |a;.long |
|00003090| 61 3b 06 42 6f 74 68 20 | 74 68 65 20 61 62 6f 76 |a;.Both |the abov|
|000030a0| 65 20 64 65 63 6c 61 72 | 61 74 69 6f 6e 73 20 61 |e declar|ations a|
|000030b0| 72 65 20 76 61 6c 69 64 | 2e 06 54 68 65 72 65 20 |re valid|..There |
|000030c0| 61 72 65 20 74 68 72 65 | 65 20 69 6e 74 65 67 65 |are thre|e intege|
|000030d0| 72 20 64 61 74 61 20 74 | 79 70 65 73 20 6e 61 6d |r data t|ypes nam|
|000030e0| 65 6c 79 20 63 68 61 72 | 2c 20 69 6e 74 20 61 6e |ely char|, int an|
|000030f0| 64 20 6c 6f 6e 67 20 61 | 6e 64 20 74 68 72 65 65 |d long a|nd three|
|00003100| 20 66 6c 6f 61 74 69 6e | 67 20 70 6f 69 6e 74 20 | floatin|g point |
|00003110| 64 61 74 61 20 74 79 70 | 65 73 20 6e 61 6d 65 6c |data typ|es namel|
|00003120| 79 20 66 6c 6f 61 74 2c | 20 64 6f 75 62 6c 65 20 |y float,| double |
|00003130| 61 6e 64 20 6c 6f 6e 67 | 20 64 6f 75 62 6c 65 2e |and long| double.|
|00003140| 20 54 68 65 20 64 6f 75 | 62 6c 65 20 6f 63 63 75 | The dou|ble occu|
|00003150| 70 69 65 73 20 38 20 62 | 79 74 65 73 20 6f 66 20 |pies 8 b|ytes of |
|00003160| 6d 65 6d 6f 72 79 20 61 | 6e 64 20 69 73 20 63 61 |memory a|nd is ca|
|00003170| 70 61 62 6c 65 20 6f 66 | 20 73 74 6f 72 69 6e 67 |pable of| storing|
|00003180| 20 61 20 66 6c 6f 61 74 | 69 6e 67 20 70 6f 69 6e | a float|ing poin|
|00003190| 74 20 6e 75 6d 62 65 72 | 20 77 69 74 68 20 61 20 |t number| with a |
|000031a0| 6d 75 63 68 20 68 69 67 | 68 65 72 20 72 61 6e 67 |much hig|her rang|
|000031b0| 65 20 61 6e 64 20 70 72 | 65 63 69 73 69 6f 6e 2e |e and pr|ecision.|
|000031c0| 20 54 68 65 20 72 61 6e | 67 65 20 61 6e 64 20 70 | The ran|ge and p|
|000031d0| 72 65 63 69 73 69 6f 6e | 20 69 73 20 6d 65 6e 74 |recision| is ment|
|000031e0| 69 6f 6e 65 64 20 69 6e | 20 74 61 62 6c 65 20 31 |ioned in| table 1|
|000031f0| 2e 31 20 73 68 6f 77 69 | 6e 67 20 61 20 73 75 6d |.1 showi|ng a sum|
|00003200| 6d 61 72 79 20 6f 66 20 | 64 61 74 61 20 74 79 70 |mary of |data typ|
|00003210| 65 73 2e 20 54 68 65 20 | 64 61 74 61 20 74 79 70 |es. The |data typ|
|00003220| 65 20 6c 6f 6e 67 20 64 | 6f 75 62 6c 65 20 6f 63 |e long d|ouble oc|
|00003230| 63 75 70 69 65 73 20 31 | 30 20 62 79 74 65 73 20 |cupies 1|0 bytes |
|00003240| 6f 66 20 6d 65 6d 6f 72 | 79 20 61 6e 64 20 69 74 |of memor|y and it|
|00003250| 73 20 72 61 6e 67 65 20 | 6f 66 20 76 61 6c 75 65 |s range |of value|
|00003260| 73 20 61 6e 64 20 70 72 | 65 63 69 73 69 6f 6e 20 |s and pr|ecision |
|00003270| 69 73 20 73 6c 69 67 68 | 74 6c 79 20 6d 6f 72 65 |is sligh|tly more|
|00003280| 20 74 68 61 6e 20 74 68 | 61 74 20 6f 66 20 64 6f | than th|at of do|
|00003290| 75 62 6c 65 2e 06 55 6e | 73 69 67 6e 65 64 20 64 |uble..Un|signed d|
|000032a0| 61 74 61 20 74 79 70 65 | 73 06 54 68 65 20 64 61 |ata type|s.The da|
|000032b0| 74 61 20 74 79 70 65 73 | 20 74 68 61 74 20 68 61 |ta types| that ha|
|000032c0| 76 65 20 62 65 65 6e 20 | 64 69 73 63 75 73 73 65 |ve been |discusse|
|000032d0| 64 20 74 69 6c 6c 20 6e | 6f 77 20 68 61 76 65 20 |d till n|ow have |
|000032e0| 61 6c 6c 20 62 65 65 6e | 20 73 69 67 6e 65 64 2e |all been| signed.|
|000032f0| 20 54 68 61 74 20 69 73 | 2c 20 74 68 65 79 20 63 | That is|, they c|
|00003300| 61 6e 20 73 74 6f 72 65 | 20 62 6f 74 68 20 6e 65 |an store| both ne|
|00003310| 67 61 74 69 76 65 20 61 | 6e 64 20 70 6f 73 69 74 |gative a|nd posit|
|00003320| 69 76 65 20 76 61 6c 75 | 65 73 2e 20 53 6f 6d 65 |ive valu|es. Some|
|00003330| 74 69 6d 65 73 2c 20 77 | 65 20 6e 65 65 64 20 74 |times, w|e need t|
|00003340| 6f 20 73 74 6f 72 65 20 | 76 61 6c 75 65 73 2c 20 |o store |values, |
|00003350| 77 68 69 63 68 20 61 72 | 65 20 61 6c 77 61 79 73 |which ar|e always|
|00003360| 20 70 6f 73 69 74 69 76 | 65 20 73 75 63 68 20 61 | positiv|e such a|
|00003370| 73 20 74 68 65 20 61 67 | 65 20 6f 66 20 61 20 70 |s the ag|e of a p|
|00003380| 65 72 73 6f 6e 20 6f 72 | 20 74 68 65 20 73 61 6c |erson or| the sal|
|00003390| 61 72 79 20 6f 66 20 61 | 6e 20 65 6d 70 6c 6f 79 |ary of a|n employ|
|000033a0| 65 65 2e 20 49 6e 20 73 | 75 63 68 20 63 61 73 65 |ee. In s|uch case|
|000033b0| 73 2c 20 43 2b 2b 20 61 | 6c 6c 6f 77 73 20 75 73 |s, C++ a|llows us|
|000033c0| 20 74 6f 20 64 65 66 69 | 6e 65 20 76 61 72 69 61 | to defi|ne varia|
|000033d0| 62 6c 65 73 2c 20 77 68 | 69 63 68 20 61 72 65 20 |bles, wh|ich are |
|000033e0| 6f 6e 6c 79 20 70 6f 73 | 69 74 69 76 65 2c 20 61 |only pos|itive, a|
|000033f0| 6e 64 20 61 73 20 61 20 | 72 65 73 75 6c 74 20 63 |nd as a |result c|
|00003400| 61 6e 20 73 74 6f 72 65 | 20 61 20 6d 75 63 68 20 |an store| a much |
|00003410| 62 69 67 67 65 72 20 76 | 61 6c 75 65 20 69 6e 20 |bigger v|alue in |
|00003420| 74 68 65 20 73 61 6d 65 | 20 61 6d 6f 75 6e 74 20 |the same| amount |
|00003430| 6f 66 20 6d 65 6d 6f 72 | 79 2e 20 4f 6e 6c 79 20 |of memor|y. Only |
|00003440| 69 6e 74 65 67 65 72 20 | 64 61 74 61 20 74 79 70 |integer |data typ|
|00003450| 65 73 20 63 61 6e 20 62 | 65 20 75 6e 73 69 67 6e |es can b|e unsign|
|00003460| 65 64 2e 20 41 6c 6c 20 | 76 61 72 69 61 62 6c 65 |ed. All |variable|
|00003470| 73 20 61 72 65 20 62 79 | 20 64 65 66 61 75 6c 74 |s are by| default|
|00003480| 20 73 69 67 6e 65 64 2e | 20 54 68 65 79 20 61 72 | signed.| They ar|
|00003490| 65 20 6d 61 64 65 20 73 | 6f 20 62 79 20 61 64 64 |e made s|o by add|
|000034a0| 69 6e 67 20 74 68 65 20 | 6b 65 79 77 6f 72 64 20 |ing the |keyword |
|000034b0| 75 6e 73 69 67 6e 65 64 | 20 62 65 66 6f 72 65 20 |unsigned| before |
|000034c0| 74 68 65 20 76 61 72 69 | 61 62 6c 65 2e 06 75 6e |the vari|able..un|
|000034d0| 73 69 67 6e 65 64 20 63 | 68 61 72 20 61 3b 06 75 |signed c|har a;.u|
|000034e0| 6e 73 69 67 6e 65 64 20 | 69 6e 74 20 62 3b 06 75 |nsigned |int b;.u|
|000034f0| 6e 73 69 67 6e 65 64 20 | 66 6c 6f 61 74 20 63 3b |nsigned |float c;|
|00003500| 06 44 61 74 61 20 54 79 | 70 65 06 20 42 79 74 65 |.Data Ty|pe. Byte|
|00003510| 73 20 4f 63 63 75 70 69 | 65 64 06 20 4c 6f 77 65 |s Occupi|ed. Lowe|
|00003520| 73 74 20 56 61 6c 75 65 | 06 20 48 69 67 68 65 73 |st Value|. Highes|
|00003530| 74 20 56 61 6c 75 65 06 | 20 50 72 65 63 69 73 69 |t Value.| Precisi|
|00003540| 6f 6e 20 44 69 67 69 74 | 73 06 06 63 68 61 72 06 |on Digit|s..char.|
|00003550| 20 31 06 20 2d 31 32 38 | 06 20 31 32 37 06 20 4e | 1. -128|. 127. N|
|00003560| 2f 41 06 06 69 6e 74 06 | 20 32 06 20 2d 33 32 2c |/A..int.| 2. -32,|
|00003570| 37 36 38 06 20 33 32 2c | 37 36 37 06 20 4e 2f 41 |768. 32,|767. N/A|
|00003580| 06 06 6c 6f 6e 67 06 20 | 34 06 20 2d 32 2c 31 34 |..long. |4. -2,14|
|00003590| 37 2c 34 38 33 2c 36 34 | 38 06 20 32 2c 31 34 37 |7,483,64|8. 2,147|
|000035a0| 2c 34 38 33 2c 36 34 37 | 06 20 4e 2f 41 06 06 66 |,483,647|. N/A..f|
|000035b0| 6c 6f 61 74 06 20 34 06 | 20 33 2e 34 78 31 30 2d |loat. 4.| 3.4x10-|
|000035c0| 33 38 06 20 33 2e 34 78 | 31 30 33 38 06 20 37 06 |38. 3.4x|1038. 7.|
|000035d0| 06 64 6f 75 62 6c 65 06 | 20 38 06 20 31 2e 37 78 |.double.| 8. 1.7x|
|000035e0| 31 30 2d 33 30 38 06 20 | 31 2e 37 78 31 30 33 30 |10-308. |1.7x1030|
|000035f0| 38 06 20 31 35 06 06 6c | 6f 6e 67 20 64 6f 75 62 |8. 15..l|ong doub|
|00003600| 6c 65 06 20 31 30 06 20 | 33 2e 34 78 31 30 2d 34 |le. 10. |3.4x10-4|
|00003610| 39 33 32 06 20 31 2e 31 | 78 31 30 34 39 33 32 06 |932. 1.1|x104932.|
|00003620| 20 31 39 06 06 75 6e 73 | 69 67 6e 65 64 20 63 68 | 19..uns|igned ch|
|00003630| 61 72 06 20 31 06 20 30 | 06 20 32 35 35 06 20 4e |ar. 1. 0|. 255. N|
|00003640| 2f 41 06 06 75 6e 73 69 | 67 6e 65 64 20 69 6e 74 |/A..unsi|gned int|
|00003650| 06 20 32 06 20 30 06 20 | 36 35 2c 35 33 35 06 20 |. 2. 0. |65,535. |
|00003660| 4e 2f 41 06 06 75 6e 73 | 69 67 6e 65 64 20 6c 6f |N/A..uns|igned lo|
|00003670| 6e 67 06 20 34 06 20 30 | 06 20 34 2c 32 39 34 2c |ng. 4. 0|. 4,294,|
|00003680| 39 36 37 2c 32 39 35 06 | 20 4e 2f 41 06 06 49 4e |967,295.| N/A..IN|
|00003690| 50 55 54 20 41 4e 44 20 | 4f 55 54 50 55 54 06 49 |PUT AND |OUTPUT.I|
|000036a0| 6e 20 74 68 65 20 70 72 | 6f 67 72 61 6d 20 73 74 |n the pr|ogram st|
|000036b0| 61 74 65 6d 65 6e 74 20 | 63 6f 75 74 3c 3c 22 57 |atement |cout<<"W|
|000036c0| 65 6c 6c 20 62 65 67 75 | 6e 20 69 73 20 68 61 6c |ell begu|n is hal|
|000036d0| 66 20 64 6f 6e 65 22 3b | 20 74 68 65 20 6b 65 79 |f done";| the key|
|000036e0| 77 6f 72 64 20 63 6f 75 | 74 20 28 70 72 6f 6e 6f |word cou|t (prono|
|000036f0| 75 6e 63 65 64 20 61 73 | 20 22 63 6f 75 74 22 29 |unced as| "cout")|
|00003700| 20 69 73 20 75 73 65 64 | 20 74 6f 20 6f 75 74 70 | is used| to outp|
|00003710| 75 74 20 64 61 74 61 20 | 6f 6e 20 74 68 65 20 73 |ut data |on the s|
|00003720| 63 72 65 65 6e 2e 20 54 | 68 69 73 20 69 73 20 64 |creen. T|his is d|
|00003730| 6f 6e 65 20 77 69 74 68 | 20 74 68 65 20 68 65 6c |one with| the hel|
|00003740| 70 20 6f 66 20 74 68 65 | 20 69 6e 73 65 72 74 69 |p of the| inserti|
|00003750| 6f 6e 20 6f 70 65 72 61 | 74 6f 72 20 28 27 3c 3c |on opera|tor ('<<|
|00003760| 27 29 2e 06 63 6f 75 74 | 3c 3c 22 20 54 6f 64 61 |')..cout|<<" Toda|
|00003770| 79 20 69 73 20 61 20 66 | 69 6e 65 20 64 61 79 22 |y is a f|ine day"|
|00003780| 3b 06 69 6e 74 20 61 3d | 31 30 2c 20 69 6e 74 20 |;.int a=|10, int |
|00003790| 62 3d 39 30 2c 63 3b 06 | 63 6f 75 74 3c 3c 61 2b |b=90,c;.|cout<<a+|
|000037a0| 62 3b 06 63 3d 61 2b 62 | 3b 06 63 6f 75 74 3c 3c |b;.c=a+b|;.cout<<|
|000037b0| 22 54 68 65 20 76 61 6c | 75 65 20 6f 66 20 63 20 |"The val|ue of c |
|000037c0| 69 73 20 3a 22 3c 3c 63 | 3b 06 61 72 65 20 73 6f |is :"<<c|;.are so|
|000037d0| 6d 65 20 6f 66 20 74 68 | 65 20 77 61 79 73 20 69 |me of th|e ways i|
|000037e0| 6e 20 77 68 69 63 68 20 | 63 6f 75 74 20 63 61 6e |n which |cout can|
|000037f0| 20 62 65 20 75 73 65 64 | 20 74 6f 20 6f 75 74 70 | be used| to outp|
|00003800| 75 74 20 64 61 74 61 2e | 06 49 6e 70 75 74 74 69 |ut data.|.Inputti|
|00003810| 6e 67 20 76 61 6c 75 65 | 73 20 69 6e 74 6f 20 76 |ng value|s into v|
|00003820| 61 72 69 61 62 6c 65 73 | 20 69 6e 20 43 2b 2b 20 |ariables| in C++ |
|00003830| 63 61 6e 20 62 65 20 61 | 63 63 6f 6d 70 6c 69 73 |can be a|ccomplis|
|00003840| 68 65 64 20 77 69 74 68 | 20 74 68 65 20 68 65 6c |hed with| the hel|
|00003850| 70 20 6f 66 20 74 68 65 | 20 63 69 6e 20 6b 65 79 |p of the| cin key|
|00003860| 77 6f 72 64 2e 20 46 6f | 72 20 65 78 61 6d 70 6c |word. Fo|r exampl|
|00003870| 65 06 69 6e 74 20 61 3b | 06 63 6f 75 74 3c 3c 22 |e.int a;|.cout<<"|
|00003880| 45 6e 74 65 72 20 61 20 | 76 61 6c 75 65 20 22 3b |Enter a |value ";|
|00003890| 06 63 69 6e 3e 3e 61 3b | 06 54 68 65 20 27 3e 3e |.cin>>a;|.The '>>|
|000038a0| 27 20 6f 70 65 72 61 74 | 6f 72 20 69 73 20 6b 6e |' operat|or is kn|
|000038b0| 6f 77 6e 20 61 73 20 74 | 68 65 20 69 6e 73 65 72 |own as t|he inser|
|000038c0| 74 69 6f 6e 20 6f 70 65 | 72 61 74 6f 72 2e 20 54 |tion ope|rator. T|
|000038d0| 68 65 20 61 62 6f 76 65 | 20 73 74 61 74 65 6d 65 |he above| stateme|
|000038e0| 6e 74 20 63 61 75 73 65 | 73 20 74 68 65 20 76 61 |nt cause|s the va|
|000038f0| 6c 75 65 73 20 65 6e 74 | 65 72 65 64 20 62 79 20 |lues ent|ered by |
|00003900| 74 68 65 20 75 73 65 72 | 20 74 6f 20 62 65 20 73 |the user| to be s|
|00003910| 74 6f 72 65 64 20 69 6e | 20 74 68 65 20 76 61 72 |tored in| the var|
|00003920| 69 61 62 6c 65 20 61 2e | 06 4d 41 4e 49 50 55 4c |iable a.|.MANIPUL|
|00003930| 41 54 4f 52 53 06 4d 61 | 6e 69 70 75 6c 61 74 6f |ATORS.Ma|nipulato|
|00003940| 72 73 20 61 72 65 20 6f | 70 65 72 61 74 6f 72 73 |rs are o|perators|
|00003950| 20 75 73 65 64 20 77 69 | 74 68 20 74 68 65 20 69 | used wi|th the i|
|00003960| 6e 73 65 72 74 69 6f 6e | 20 6f 70 65 72 61 74 6f |nsertion| operato|
|00003970| 72 20 3c 3c 20 74 6f 20 | 6d 6f 64 69 66 79 20 6f |r << to |modify o|
|00003980| 72 20 6d 61 6e 69 70 75 | 6c 61 74 65 20 74 68 65 |r manipu|late the|
|00003990| 20 77 61 79 20 64 61 74 | 61 20 69 73 20 64 69 73 | way dat|a is dis|
|000039a0| 70 6c 61 79 65 64 2e 20 | 54 77 6f 20 6f 66 20 74 |played. |Two of t|
|000039b0| 68 65 20 6d 6f 73 74 20 | 63 6f 6d 6d 6f 6e 20 6d |he most |common m|
|000039c0| 61 6e 69 70 75 6c 61 74 | 6f 72 73 20 61 72 65 20 |anipulat|ors are |
|000039d0| 74 68 65 20 73 65 74 77 | 20 61 6e 64 20 65 6e 64 |the setw| and end|
|000039e0| 6c 20 6d 61 6e 69 70 75 | 6c 61 74 6f 72 73 2e 20 |l manipu|lators. |
|000039f0| 49 6e 20 6f 72 64 65 72 | 20 74 6f 20 75 73 65 20 |In order| to use |
|00003a00| 74 68 65 73 65 20 6d 61 | 6e 69 70 75 6c 61 74 6f |these ma|nipulato|
|00003a10| 72 73 20 74 68 65 20 68 | 65 61 64 65 72 20 66 69 |rs the h|eader fi|
|00003a20| 6c 65 20 69 6f 6d 61 6e | 69 70 2e 68 20 73 68 6f |le ioman|ip.h sho|
|00003a30| 75 6c 64 20 62 65 20 69 | 6e 63 6c 75 64 65 64 20 |uld be i|ncluded |
|00003a40| 69 6e 20 74 68 65 20 70 | 72 6f 67 72 61 6d 20 66 |in the p|rogram f|
|00003a50| 69 6c 65 2e 06 54 48 45 | 20 45 4e 44 4c 20 4d 41 |ile..THE| ENDL MA|
|00003a60| 4e 49 50 55 4c 41 54 4f | 52 06 54 68 69 73 20 6d |NIPULATO|R.This m|
|00003a70| 61 6e 69 70 75 6c 61 74 | 6f 72 20 63 61 75 73 65 |anipulat|or cause|
|00003a80| 73 20 61 20 6c 69 6e 65 | 20 74 6f 20 62 65 20 69 |s a line| to be i|
|00003a90| 6e 73 65 72 74 65 64 2e | 20 49 74 20 68 61 73 20 |nserted.| It has |
|00003aa0| 74 68 65 20 73 61 6d 65 | 20 65 66 66 65 63 74 20 |the same| effect |
|00003ab0| 61 73 20 73 65 6e 64 69 | 6e 67 20 74 68 65 20 73 |as sendi|ng the s|
|00003ac0| 69 6e 67 6c 65 20 27 5c | 6e 27 20 63 68 61 72 61 |ingle '\|n' chara|
|00003ad0| 63 74 65 72 2c 20 77 68 | 69 63 68 20 77 65 20 77 |cter, wh|ich we w|
|00003ae0| 69 6c 6c 20 64 69 73 63 | 75 73 73 20 6c 61 74 65 |ill disc|uss late|
|00003af0| 72 20 69 6e 20 65 73 63 | 61 70 65 20 73 65 71 75 |r in esc|ape sequ|
|00003b00| 65 6e 63 65 73 2e 06 43 | 6f 6e 73 69 64 65 72 20 |ences..C|onsider |
|00003b10| 74 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 70 72 |the foll|owing pr|
|00003b20| 6f 67 72 61 6d 06 23 69 | 6e 63 6c 75 64 65 3c 69 |ogram.#i|nclude<i|
|00003b30| 6f 73 74 72 65 61 6d 2e | 68 3e 06 76 6f 69 64 20 |ostream.|h>.void |
|00003b40| 6d 61 69 6e 28 29 06 7b | 06 6c 6f 6e 67 20 70 6f |main().{|.long po|
|00003b50| 70 31 3d 32 33 34 33 34 | 35 34 2c 20 70 6f 70 32 |p1=23434|54, pop2|
|00003b60| 3d 32 33 33 34 3b 06 63 | 6f 75 74 20 3c 3c 20 22 |=2334;.c|out << "|
|00003b70| 4c 6f 63 61 74 69 6f 6e | 20 22 20 3c 3c 20 22 50 |Location| " << "P|
|00003b80| 6f 70 75 6c 61 74 69 6f | 6e 22 3c 3c 65 6e 64 6c |opulatio|n"<<endl|
|00003b90| 3b 06 63 6f 75 74 3c 3c | 20 22 4e 65 77 20 44 65 |;.cout<<| "New De|
|00003ba0| 6c 68 69 20 22 3c 3c 70 | 6f 70 31 3c 3c 65 6e 64 |lhi "<<p|op1<<end|
|00003bb0| 6c 3b 06 63 6f 75 74 3c | 3c 20 22 42 6f 6d 62 61 |l;.cout<|< "Bomba|
|00003bc0| 79 20 22 20 3c 3c 20 70 | 6f 70 32 3c 3c 65 6e 64 |y " << p|op2<<end|
|00003bd0| 6c 3b 06 7d 06 54 68 65 | 20 6f 75 74 70 75 74 20 |l;.}.The| output |
|00003be0| 6f 66 20 74 68 65 20 70 | 72 6f 67 72 61 6d 20 69 |of the p|rogram i|
|00003bf0| 73 06 4c 6f 63 61 74 69 | 6f 6e 20 50 6f 70 75 6c |s.Locati|on Popul|
|00003c00| 61 74 69 6f 6e 06 4e 65 | 77 20 44 65 6c 68 69 20 |ation.Ne|w Delhi |
|00003c10| 32 33 34 33 34 35 34 06 | 42 6f 6d 62 61 79 20 32 |2343454.|Bombay 2|
|00003c20| 33 33 34 06 49 74 20 63 | 61 6e 20 62 65 20 76 69 |334.It c|an be vi|
|00003c30| 73 75 61 6c 69 7a 65 64 | 20 74 68 61 74 20 65 61 |sualized| that ea|
|00003c40| 63 68 20 76 61 6c 75 65 | 20 64 69 73 70 6c 61 79 |ch value| display|
|00003c50| 65 64 20 62 79 20 63 6f | 75 74 20 6f 63 63 75 70 |ed by co|ut occup|
|00003c60| 69 65 73 20 61 20 66 69 | 65 6c 64 2c 20 61 6e 20 |ies a fi|eld, an |
|00003c70| 69 6d 61 67 69 6e 61 72 | 79 20 62 6f 78 20 77 69 |imaginar|y box wi|
|00003c80| 74 68 20 61 20 63 65 72 | 74 61 69 6e 20 77 69 64 |th a cer|tain wid|
|00003c90| 74 68 2e 20 54 68 65 20 | 64 65 66 61 75 6c 74 20 |th. The |default |
|00003ca0| 66 69 65 6c 64 20 69 73 | 20 6a 75 73 74 20 77 69 |field is| just wi|
|00003cb0| 64 65 20 65 6e 6f 75 67 | 68 20 74 6f 20 68 6f 6c |de enoug|h to hol|
|00003cc0| 64 20 74 68 65 20 76 61 | 6c 75 65 2e 20 54 68 61 |d the va|lue. Tha|
|00003cd0| 74 20 69 73 2c 20 74 68 | 65 20 69 6e 74 65 67 65 |t is, th|e intege|
|00003ce0| 72 20 35 36 37 20 77 69 | 6c 6c 20 6f 63 63 75 70 |r 567 wi|ll occup|
|00003cf0| 79 20 61 20 66 69 65 6c | 64 20 74 68 72 65 65 20 |y a fiel|d three |
|00003d00| 63 68 61 72 61 63 74 65 | 72 73 20 77 69 64 65 2e |characte|rs wide.|
|00003d10| 20 48 65 6e 63 65 2c 20 | 74 68 65 20 6f 75 74 70 | Hence, |the outp|
|00003d20| 75 74 20 6f 66 20 6f 75 | 72 20 70 72 6f 67 72 61 |ut of ou|r progra|
|00003d30| 6d 20 61 62 6f 76 65 2e | 06 54 48 45 20 53 45 54 |m above.|.THE SET|
|00003d40| 57 20 4d 41 4e 49 50 55 | 4c 41 54 4f 52 06 57 69 |W MANIPU|LATOR.Wi|
|00003d50| 74 68 20 74 68 65 20 6f | 75 74 70 75 74 20 73 68 |th the o|utput sh|
|00003d60| 6f 77 6e 20 61 62 6f 76 | 65 20 69 74 20 69 73 20 |own abov|e it is |
|00003d70| 64 69 66 66 69 63 75 6c | 74 20 74 6f 20 63 6f 6d |difficul|t to com|
|00003d80| 70 61 72 65 20 69 6e 74 | 65 67 65 72 20 76 61 6c |pare int|eger val|
|00003d90| 75 65 73 2e 20 49 66 20 | 74 68 65 20 73 61 6d 65 |ues. If |the same|
|00003da0| 20 70 72 6f 67 72 61 6d | 20 69 73 20 77 72 69 74 | program| is writ|
|00003db0| 74 65 6e 20 77 69 74 68 | 20 74 68 65 20 68 65 6c |ten with| the hel|
|00003dc0| 70 20 6f 66 20 74 68 65 | 20 73 65 74 77 20 6d 61 |p of the| setw ma|
|00003dd0| 6e 69 70 75 6c 61 74 6f | 72 2c 20 74 68 65 20 6f |nipulato|r, the o|
|00003de0| 75 74 70 75 74 20 77 6f | 75 6c 64 20 62 65 20 73 |utput wo|uld be s|
|00003df0| 6f 6d 65 74 68 69 6e 67 | 20 65 6c 73 65 2e 06 23 |omething| else..#|
|00003e00| 69 6e 63 6c 75 64 65 3c | 69 6f 73 74 72 65 61 6d |include<|iostream|
|00003e10| 2e 68 3e 06 23 69 6e 63 | 6c 75 64 65 3c 69 6f 6d |.h>.#inc|lude<iom|
|00003e20| 61 6e 69 70 2e 68 3e 06 | 76 6f 69 64 20 6d 61 69 |anip.h>.|void mai|
|00003e30| 6e 28 29 06 7b 06 6c 6f | 6e 67 20 70 6f 70 31 3d |n().{.lo|ng pop1=|
|00003e40| 32 33 34 33 34 35 34 2c | 20 70 6f 70 32 3d 32 33 |2343454,| pop2=23|
|00003e50| 33 34 3b 06 63 6f 75 74 | 20 3c 3c 73 65 74 77 28 |34;.cout| <<setw(|
|00003e60| 38 29 3c 3c 22 4c 6f 63 | 61 74 69 6f 6e 20 22 20 |8)<<"Loc|ation " |
|00003e70| 3c 3c 20 73 65 74 77 28 | 31 32 29 3c 3c 22 50 6f |<< setw(|12)<<"Po|
|00003e80| 70 75 6c 61 74 69 6f 6e | 22 3c 3c 65 6e 64 6c 3b |pulation|"<<endl;|
|00003e90| 06 63 6f 75 74 3c 3c 73 | 65 74 77 28 38 29 3c 3c |.cout<<s|etw(8)<<|
|00003ea0| 22 4e 65 77 20 44 65 6c | 68 69 20 22 3c 3c 20 73 |"New Del|hi "<< s|
|00003eb0| 65 74 77 28 31 32 29 3c | 3c 70 6f 70 31 3c 3c 65 |etw(12)<|<pop1<<e|
|00003ec0| 6e 64 6c 3b 06 63 6f 75 | 74 3c 3c 20 73 65 74 77 |ndl;.cou|t<< setw|
|00003ed0| 28 38 29 3c 3c 22 42 6f | 6d 62 61 79 20 22 20 3c |(8)<<"Bo|mbay " <|
|00003ee0| 3c 20 73 65 74 77 28 31 | 32 29 3c 3c 70 6f 70 32 |< setw(1|2)<<pop2|
|00003ef0| 3c 3c 65 6e 64 6c 3b 06 | 7d 06 54 68 65 20 73 65 |<<endl;.|}.The se|
|00003f00| 74 77 20 6d 61 6e 69 70 | 75 6c 61 74 6f 72 20 63 |tw manip|ulator c|
|00003f10| 61 75 73 65 73 20 74 68 | 65 20 6e 75 6d 62 65 72 |auses th|e number|
|00003f20| 20 6f 72 20 73 74 72 69 | 6e 67 20 74 68 61 74 20 | or stri|ng that |
|00003f30| 66 6f 6c 6c 6f 77 73 20 | 74 6f 20 62 65 20 70 72 |follows |to be pr|
|00003f40| 69 6e 74 65 64 20 77 69 | 74 68 69 6e 20 61 20 66 |inted wi|thin a f|
|00003f50| 69 65 6c 64 20 6e 20 63 | 68 61 72 61 63 74 65 72 |ield n c|haracter|
|00003f60| 73 20 77 69 64 65 2c 20 | 77 68 65 72 65 20 6e 20 |s wide, |where n |
|00003f70| 69 73 20 74 68 65 20 61 | 72 67 75 6d 65 6e 74 20 |is the a|rgument |
|00003f80| 74 6f 20 73 65 74 77 28 | 6e 29 2e 20 54 68 65 20 |to setw(|n). The |
|00003f90| 76 61 6c 75 65 20 69 73 | 20 72 69 67 68 74 20 6a |value is| right j|
|00003fa0| 75 73 74 69 66 69 65 64 | 20 77 69 74 68 69 6e 20 |ustified| within |
|00003fb0| 74 68 65 20 66 69 65 6c | 64 2e 06 54 68 65 20 6e |the fiel|d..The n|
|00003fc0| 65 77 20 6f 75 74 70 75 | 74 20 77 6f 75 6c 64 20 |ew outpu|t would |
|00003fd0| 62 65 20 73 6f 6d 65 74 | 68 69 6e 67 20 6c 69 6b |be somet|hing lik|
|00003fe0| 65 20 74 68 69 73 06 4c | 6f 63 61 74 69 6f 6e 20 |e this.L|ocation |
|00003ff0| 50 6f 70 75 6c 61 74 69 | 6f 6e 06 4e 65 77 20 44 |Populati|on.New D|
|00004000| 65 6c 68 69 20 32 33 34 | 33 34 35 34 06 42 6f 6d |elhi 234|3454.Bom|
|00004010| 62 61 79 20 32 33 33 34 | 06 45 53 43 41 50 45 20 |bay 2334|.ESCAPE |
|00004020| 53 45 51 55 45 4e 43 45 | 53 06 41 70 61 72 74 20 |SEQUENCE|S.Apart |
|00004030| 66 72 6f 6d 20 75 73 69 | 6e 67 20 6d 61 6e 69 70 |from usi|ng manip|
|00004040| 75 6c 61 74 6f 72 73 20 | 74 68 65 72 65 20 69 73 |ulators |there is|
|00004050| 20 61 6e 6f 74 68 65 72 | 20 77 61 79 20 74 6f 20 | another| way to |
|00004060| 6f 62 74 61 69 6e 20 66 | 6f 72 6d 61 74 74 65 64 |obtain f|ormatted|
|00004070| 20 6f 75 74 70 75 74 2e | 20 54 68 69 73 20 63 61 | output.| This ca|
|00004080| 6e 20 62 65 20 64 6f 6e | 65 20 77 69 74 68 20 74 |n be don|e with t|
|00004090| 68 65 20 68 65 6c 70 20 | 6f 66 20 65 73 63 61 70 |he help |of escap|
|000040a0| 65 20 73 65 71 75 65 6e | 63 65 73 2e 20 54 68 65 |e sequen|ces. The|
|000040b0| 20 66 6f 6c 6c 6f 77 69 | 6e 67 20 65 78 61 6d 70 | followi|ng examp|
|000040c0| 6c 65 20 73 68 6f 77 73 | 20 74 68 65 20 75 73 61 |le shows| the usa|
|000040d0| 67 65 20 6f 66 20 61 20 | 76 65 72 79 20 63 6f 6d |ge of a |very com|
|000040e0| 6d 6f 6e 20 65 73 63 61 | 70 65 20 73 65 71 75 65 |mon esca|pe seque|
|000040f0| 6e 63 65 20 27 5c 6e 27 | 2e 06 63 6f 75 74 3c 3c |nce '\n'|..cout<<|
|00004100| 20 22 57 68 61 74 20 69 | 73 20 79 6f 75 72 20 6e | "What i|s your n|
|00004110| 61 6d 65 3f 22 3c 3c 20 | 22 5c 6e 22 3b 06 63 6f |ame?"<< |"\n";.co|
|00004120| 75 74 3c 3c 20 22 4d 79 | 20 6e 61 6d 65 20 69 73 |ut<< "My| name is|
|00004130| 20 56 61 6e 64 61 6e 61 | 22 3b 06 45 73 63 61 70 | Vandana|";.Escap|
|00004140| 65 20 73 65 71 75 65 6e | 63 65 73 20 63 61 6e 20 |e sequen|ces can |
|00004150| 62 65 20 75 73 65 64 20 | 62 6f 74 68 20 77 69 74 |be used |both wit|
|00004160| 68 20 63 68 61 72 61 63 | 74 65 72 20 61 6e 64 20 |h charac|ter and |
|00004170| 73 74 72 69 6e 67 20 63 | 6f 6e 73 74 61 6e 74 73 |string c|onstants|
|00004180| 2e 06 54 68 65 20 65 73 | 63 61 70 65 20 73 65 71 |..The es|cape seq|
|00004190| 75 65 6e 63 65 20 5c 6e | 20 63 61 75 73 65 73 20 |uence \n| causes |
|000041a0| 74 68 65 20 73 74 72 69 | 6e 67 20 22 4d 79 20 6e |the stri|ng "My n|
|000041b0| 61 6d 65 20 69 73 20 56 | 61 6e 64 61 6e 61 22 20 |ame is V|andana" |
|000041c0| 74 6f 20 62 65 20 70 72 | 69 6e 74 65 64 20 69 6e |to be pr|inted in|
|000041d0| 20 74 68 65 20 6e 65 78 | 74 20 6c 69 6e 65 2e 06 | the nex|t line..|
|000041e0| 54 68 65 20 66 6f 6c 6c | 6f 77 69 6e 67 20 74 61 |The foll|owing ta|
|000041f0| 62 6c 65 20 73 68 6f 77 | 73 20 61 20 6c 69 73 74 |ble show|s a list|
|00004200| 20 6f 66 20 73 6f 6d 65 | 20 65 73 63 61 70 65 20 | of some| escape |
|00004210| 73 65 71 75 65 6e 63 65 | 73 2e 06 45 73 63 61 70 |sequence|s..Escap|
|00004220| 65 20 53 65 71 75 65 6e | 63 65 06 20 43 68 61 72 |e Sequen|ce. Char|
|00004230| 61 63 74 65 72 06 06 5c | 61 06 20 42 65 6c 6c 20 |acter..\|a. Bell |
|00004240| 28 62 65 65 70 29 06 06 | 5c 62 06 20 42 61 63 6b |(beep)..|\b. Back|
|00004250| 73 70 61 63 65 42 f7 06 | 06 5c 6e 06 20 4e 65 77 |spaceB..|.\n. New|
|00004260| 20 6c 69 6e 65 06 06 5c | 72 06 20 52 65 74 75 72 | line..\|r. Retur|
|00004270| 6e 06 06 5c 92 06 20 53 | 69 6e 67 6c 65 20 71 75 |n..\.. S|ingle qu|
|00004280| 6f 74 61 74 69 6f 6e 06 | 06 5c 22 06 20 44 6f 75 |otation.|.\". Dou|
|00004290| 62 6c 65 20 71 75 6f 74 | 61 74 69 6f 6e 06 06 5c |ble quot|ation..\|
|000042a0| 66 06 20 46 6f 72 6d 20 | 66 65 65 64 06 06 5c 5c |f. Form |feed..\\|
|000042b0| 06 20 42 61 63 6b 73 6c | 61 73 68 06 06 54 61 62 |. Backsl|ash..Tab|
|000042c0| 6c 65 20 31 2e 32 3a 20 | 53 6f 6d 65 20 65 73 63 |le 1.2: |Some esc|
|000042d0| 61 70 65 20 73 65 71 75 | 65 6e 63 65 73 06 41 52 |ape sequ|ences.AR|
|000042e0| 49 54 48 4d 45 54 49 43 | 20 4f 50 45 52 41 54 4f |ITHMETIC| OPERATO|
|000042f0| 52 53 06 43 2b 2b 20 75 | 73 65 73 20 74 68 65 20 |RS.C++ u|ses the |
|00004300| 66 6f 75 72 20 6e 6f 72 | 6d 61 6c 20 61 72 69 74 |four nor|mal arit|
|00004310| 68 6d 65 74 69 63 20 6f | 70 65 72 61 74 6f 72 73 |hmetic o|perators|
|00004320| 20 2b 2c 2d 2c 2a 20 61 | 6e 64 20 2f 20 66 6f 72 | +,-,* a|nd / for|
|00004330| 20 61 64 64 69 74 69 6f | 6e 2c 20 73 75 62 74 72 | additio|n, subtr|
|00004340| 61 63 74 69 6f 6e 2c 20 | 6d 75 6c 74 69 70 6c 69 |action, |multipli|
|00004350| 63 61 74 69 6f 6e 20 61 | 6e 64 20 64 69 76 69 73 |cation a|nd divis|
|00004360| 69 6f 6e 2e 20 54 68 65 | 73 65 20 6f 70 65 72 61 |ion. The|se opera|
|00004370| 74 6f 72 73 20 77 6f 72 | 6b 20 6f 6e 20 61 6c 6c |tors wor|k on all|
|00004380| 20 74 68 65 20 64 61 74 | 61 20 74 79 70 65 73 2c | the dat|a types,|
|00004390| 20 62 6f 74 68 20 69 6e | 74 65 67 65 72 20 61 6e | both in|teger an|
|000043a0| 64 20 66 6c 6f 61 74 69 | 6e 67 2d 70 6f 69 6e 74 |d floati|ng-point|
|000043b0| 69 6e 67 2e 20 42 65 73 | 69 64 65 73 20 74 68 65 |ing. Bes|ides the|
|000043c0| 73 65 2c 20 74 68 65 72 | 65 20 61 72 65 20 6f 74 |se, ther|e are ot|
|000043d0| 68 65 72 20 6f 70 65 72 | 61 74 6f 72 73 20 77 68 |her oper|ators wh|
|000043e0| 69 63 68 20 61 72 65 20 | 75 73 65 64 20 69 6e 20 |ich are |used in |
|000043f0| 43 2b 2b 2e 06 54 48 45 | 20 52 45 4d 41 49 4e 44 |C++..THE| REMAIND|
|00004400| 45 52 20 4f 50 45 52 41 | 54 4f 52 06 54 68 65 20 |ER OPERA|TOR.The |
|00004410| 72 65 6d 61 69 6e 64 65 | 72 20 6f 70 65 72 61 74 |remainde|r operat|
|00004420| 6f 72 2c 20 72 65 70 72 | 65 73 65 6e 74 65 64 20 |or, repr|esented |
|00004430| 62 79 20 25 20 73 69 67 | 6e 2c 20 77 6f 72 6b 73 |by % sig|n, works|
|00004440| 20 6f 6e 6c 79 20 6f 6e | 20 69 6e 74 65 67 65 72 | only on| integer|
|00004450| 20 64 61 74 61 20 74 79 | 70 65 73 2e 20 41 6c 73 | data ty|pes. Als|
|00004460| 6f 20 72 65 66 65 72 72 | 65 64 20 74 6f 20 61 73 |o referr|ed to as|
|00004470| 20 74 68 65 20 6d 6f 64 | 75 6c 75 73 20 6f 70 65 | the mod|ulus ope|
|00004480| 72 61 74 6f 72 2c 20 69 | 74 20 66 69 6e 64 73 20 |rator, i|t finds |
|00004490| 74 68 65 20 72 65 6d 61 | 69 6e 64 65 72 20 77 68 |the rema|inder wh|
|000044a0| 65 6e 20 6f 6e 65 20 6e | 75 6d 62 65 72 20 64 69 |en one n|umber di|
|000044b0| 76 69 64 65 73 20 61 6e | 6f 74 68 65 72 2e 20 46 |vides an|other. F|
|000044c0| 6f 72 20 65 78 61 6d 70 | 6c 65 20 28 39 25 32 29 |or examp|le (9%2)|
|000044d0| 20 72 65 74 75 72 6e 73 | 20 74 68 65 20 76 61 6c | returns| the val|
|000044e0| 75 65 20 31 2e 06 54 48 | 45 20 41 53 53 49 47 4e |ue 1..TH|E ASSIGN|
|000044f0| 4d 45 4e 54 20 4f 50 45 | 52 41 54 4f 52 06 54 68 |MENT OPE|RATOR.Th|
|00004500| 69 73 20 6f 70 65 72 61 | 74 6f 72 2c 20 72 65 70 |is opera|tor, rep|
|00004510| 72 65 73 65 6e 74 65 64 | 20 62 79 20 27 3d 27 20 |resented| by '=' |
|00004520| 73 69 67 6e 2c 20 69 73 | 20 75 73 65 64 20 74 6f |sign, is| used to|
|00004530| 20 61 73 73 69 67 6e 20 | 61 20 76 61 6c 75 65 20 | assign |a value |
|00004540| 74 6f 20 61 20 76 61 72 | 69 61 62 6c 65 2e 20 46 |to a var|iable. F|
|00004550| 6f 72 20 65 78 61 6d 70 | 6c 65 2c 20 6e 75 6d 3d |or examp|le, num=|
|00004560| 35 20 6d 65 61 6e 73 20 | 74 68 65 20 76 61 6c 75 |5 means |the valu|
|00004570| 65 20 35 20 68 61 73 20 | 62 65 65 6e 20 61 73 73 |e 5 has |been ass|
|00004580| 69 67 6e 65 64 20 74 6f | 20 74 68 65 20 76 61 72 |igned to| the var|
|00004590| 69 61 62 6c 65 20 6e 75 | 6d 2e 20 54 68 69 73 20 |iable nu|m. This |
|000045a0| 6f 70 65 72 61 74 6f 72 | 20 63 61 6e 20 62 65 20 |operator| can be |
|000045b0| 75 73 65 64 20 69 6e 20 | 63 6f 6d 62 69 6e 61 74 |used in |combinat|
|000045c0| 69 6f 6e 20 77 69 74 68 | 20 6f 74 68 65 72 20 61 |ion with| other a|
|000045d0| 72 69 74 68 6d 65 74 69 | 63 20 6f 70 65 72 61 74 |rithmeti|c operat|
|000045e0| 6f 72 73 20 74 6f 20 63 | 6f 6e 64 65 6e 73 65 20 |ors to c|ondense |
|000045f0| 61 20 73 74 61 74 65 6d | 65 6e 74 2e 20 46 6f 72 |a statem|ent. For|
|00004600| 20 65 78 61 6d 70 6c 65 | 06 73 75 6d 3d 73 75 6d | example|.sum=sum|
|00004610| 2b 6e 75 6d 3b 06 68 61 | 73 20 74 68 65 20 73 61 |+num;.ha|s the sa|
|00004620| 6d 65 20 65 66 66 65 63 | 74 20 61 73 06 73 75 6d |me effec|t as.sum|
|00004630| 2b 3d 6e 75 6d 3b 06 49 | 4e 43 52 45 4d 45 4e 54 |+=num;.I|NCREMENT|
|00004640| 20 41 4e 44 20 44 45 43 | 52 45 4d 45 4e 54 20 4f | AND DEC|REMENT O|
|00004650| 50 45 52 41 54 4f 52 53 | 06 53 75 70 70 6f 73 65 |PERATORS|.Suppose|
|00004660| 20 74 68 65 20 76 61 6c | 75 65 20 6f 66 20 61 20 | the val|ue of a |
|00004670| 76 61 72 69 61 62 6c 65 | 20 68 61 73 20 74 6f 20 |variable| has to |
|00004680| 62 65 20 69 6e 63 72 65 | 61 73 65 64 20 62 79 20 |be incre|ased by |
|00004690| 31 2e 20 49 74 20 63 6f | 75 6c 64 20 62 65 20 61 |1. It co|uld be a|
|000046a0| 63 68 69 65 76 65 64 20 | 62 79 20 73 69 6d 70 6c |chieved |by simpl|
|000046b0| 79 20 77 72 69 74 69 6e | 67 06 76 61 72 3d 76 61 |y writin|g.var=va|
|000046c0| 72 2b 31 3b 06 41 20 73 | 70 65 63 69 61 6c 69 7a |r+1;.A s|pecializ|
|000046d0| 65 64 20 6f 70 65 72 61 | 74 6f 72 20 63 61 6c 6c |ed opera|tor call|
|000046e0| 65 64 20 74 68 65 20 69 | 6e 63 72 65 6d 65 6e 74 |ed the i|ncrement|
|000046f0| 20 6f 70 65 72 61 74 6f | 72 20 28 72 65 70 72 65 | operato|r (repre|
|00004700| 73 65 6e 74 65 64 20 62 | 79 20 27 2b 2b 27 29 20 |sented b|y '++') |
|00004710| 63 6f 75 6c 64 20 64 6f | 20 74 68 65 20 73 61 6d |could do| the sam|
|00004720| 65 2e 06 63 6f 75 6e 74 | 3d 63 6f 75 6e 74 2b 31 |e..count|=count+1|
|00004730| 3b 06 63 6f 75 6e 74 2b | 3d 31 3b 06 63 6f 75 6e |;.count+|=1;.coun|
|00004740| 74 2b 2b 3b 06 41 6c 6c | 20 6f 66 20 74 68 65 6d |t++;.All| of them|
|00004750| 20 68 61 76 65 20 74 68 | 65 20 73 61 6d 65 20 65 | have th|e same e|
|00004760| 66 66 65 63 74 2e 20 54 | 68 65 20 6f 70 70 6f 73 |ffect. T|he oppos|
|00004770| 69 74 65 20 6f 66 20 74 | 68 65 20 69 6e 63 72 65 |ite of t|he incre|
|00004780| 6d 65 6e 74 20 6f 70 65 | 72 61 74 6f 72 20 69 73 |ment ope|rator is|
|00004790| 20 74 68 65 20 64 65 63 | 72 65 6d 65 6e 74 20 6f | the dec|rement o|
|000047a0| 70 65 72 61 74 6f 72 20 | 27 2d 27 20 77 68 69 63 |perator |'-' whic|
|000047b0| 68 20 64 65 63 72 65 61 | 73 65 73 20 74 68 65 20 |h decrea|ses the |
|000047c0| 76 61 6c 75 65 20 6f 66 | 20 61 20 76 61 72 69 61 |value of| a varia|
|000047d0| 62 6c 65 2e 06 50 52 45 | 46 49 58 20 41 4e 44 20 |ble..PRE|FIX AND |
|000047e0| 50 4f 53 54 46 49 58 06 | 54 68 65 20 69 6e 63 72 |POSTFIX.|The incr|
|000047f0| 65 6d 65 6e 74 20 61 6e | 64 20 64 65 63 72 65 6d |ement an|d decrem|
|00004800| 65 6e 74 20 6f 70 65 72 | 61 74 6f 72 73 20 63 61 |ent oper|ators ca|
|00004810| 6e 20 62 65 20 75 73 65 | 64 20 69 6e 20 74 77 6f |n be use|d in two|
|00004820| 20 77 61 79 73 3a 20 70 | 72 65 66 69 78 20 61 6e | ways: p|refix an|
|00004830| 64 20 70 6f 73 74 66 69 | 78 2e 20 50 72 65 66 69 |d postfi|x. Prefi|
|00004840| 78 20 6d 65 61 6e 73 20 | 74 68 61 74 20 74 68 65 |x means |that the|
|00004850| 20 2b 2b 20 6f 70 65 72 | 61 74 6f 72 20 70 72 65 | ++ oper|ator pre|
|00004860| 63 65 64 65 73 20 74 68 | 65 20 76 61 72 69 61 62 |cedes th|e variab|
|00004870| 6c 65 20 61 6e 64 20 70 | 6f 73 74 66 69 78 20 6d |le and p|ostfix m|
|00004880| 65 61 6e 73 20 74 68 61 | 74 20 74 68 65 20 6f 70 |eans tha|t the op|
|00004890| 65 72 61 74 6f 72 20 66 | 6f 6c 6c 6f 77 73 20 74 |erator f|ollows t|
|000048a0| 68 65 20 76 61 72 69 61 | 62 6c 65 2e 20 54 68 69 |he varia|ble. Thi|
|000048b0| 73 20 77 69 6c 6c 20 62 | 65 20 63 6c 65 61 72 65 |s will b|e cleare|
|000048c0| 72 20 77 69 74 68 20 74 | 68 65 20 68 65 6c 70 20 |r with t|he help |
|000048d0| 6f 66 20 61 6e 20 65 78 | 61 6d 70 6c 65 2e 06 74 |of an ex|ample..t|
|000048e0| 6f 74 61 6c 3d 61 76 67 | 2a 2b 2b 63 6f 75 6e 74 |otal=avg|*++count|
|000048f0| 3b 06 54 68 65 20 71 75 | 65 73 74 69 6f 6e 20 74 |;.The qu|estion t|
|00004900| 6f 20 62 65 20 61 73 6b | 65 64 20 68 65 72 65 20 |o be ask|ed here |
|00004910| 69 73 20 74 68 69 73 20 | 3a 20 49 73 20 74 68 65 |is this |: Is the|
|00004920| 20 6d 75 6c 74 69 70 6c | 69 63 61 74 69 6f 6e 20 | multipl|ication |
|00004930| 70 65 72 66 6f 72 6d 65 | 64 20 62 65 66 6f 72 65 |performe|d before|
|00004940| 20 6f 72 20 61 66 74 65 | 72 20 74 68 65 20 63 6f | or afte|r the co|
|00004950| 75 6e 74 20 69 73 20 69 | 6e 63 72 65 6d 65 6e 74 |unt is i|ncrement|
|00004960| 65 64 3f 20 49 6e 20 74 | 68 69 73 20 63 61 73 65 |ed? In t|his case|
|00004970| 2c 20 63 6f 75 6e 74 20 | 69 73 20 69 6e 63 72 65 |, count |is incre|
|00004980| 6d 65 6e 74 65 64 20 66 | 69 72 73 74 20 61 6e 64 |mented f|irst and|
|00004990| 20 6d 75 6c 74 69 70 6c | 69 63 61 74 69 6f 6e 20 | multipl|ication |
|000049a0| 70 65 72 66 6f 72 6d 65 | 64 20 6c 61 74 65 72 20 |performe|d later |
|000049b0| 62 65 63 61 75 73 65 20 | 61 20 70 72 65 66 69 78 |because |a prefix|
|000049c0| 20 6e 6f 74 61 74 69 6f | 6e 20 69 73 20 75 73 65 | notatio|n is use|
|000049d0| 64 2e 20 48 61 64 20 77 | 65 20 64 6f 6e 65 20 73 |d. Had w|e done s|
|000049e0| 6f 6d 65 74 68 69 6e 67 | 20 6c 69 6b 65 20 74 68 |omething| like th|
|000049f0| 69 73 3a 20 74 6f 74 61 | 6c 3d 61 76 67 2a 63 6f |is: tota|l=avg*co|
|00004a00| 75 6e 74 2b 2b 2c 20 74 | 68 65 20 6f 70 70 6f 73 |unt++, t|he oppos|
|00004a10| 69 74 65 20 77 6f 75 6c | 64 20 68 61 76 65 20 62 |ite woul|d have b|
|00004a20| 65 65 6e 20 61 63 68 69 | 65 76 65 64 2e 06 52 45 |een achi|eved..RE|
|00004a30| 4c 41 54 49 4f 4e 41 4c | 20 4f 50 45 52 41 54 4f |LATIONAL| OPERATO|
|00004a40| 52 53 06 41 20 72 65 6c | 61 74 69 6f 6e 61 6c 20 |RS.A rel|ational |
|00004a50| 6f 70 65 72 61 74 6f 72 | 20 69 73 20 61 6e 20 6f |operator| is an o|
|00004a60| 70 65 72 61 74 6f 72 20 | 77 68 69 63 68 20 63 6f |perator |which co|
|00004a70| 6d 70 61 72 65 73 20 74 | 77 6f 20 76 61 6c 75 65 |mpares t|wo value|
|00004a80| 73 2e 20 54 68 65 20 63 | 6f 6d 70 61 72 69 73 6f |s. The c|ompariso|
|00004a90| 6e 20 69 6e 76 6f 6c 76 | 65 73 20 73 75 63 68 20 |n involv|es such |
|00004aa0| 72 65 6c 61 74 69 6f 6e | 73 68 69 70 73 20 61 73 |relation|ships as|
|00004ab0| 20 65 71 75 61 6c 20 74 | 6f 2c 20 6c 65 73 73 20 | equal t|o, less |
|00004ac0| 74 68 61 6e 2c 20 67 72 | 65 61 74 65 72 20 74 68 |than, gr|eater th|
|00004ad0| 61 6e 20 61 6e 64 20 73 | 6f 20 6f 6e 2e 20 54 68 |an and s|o on. Th|
|00004ae0| 65 20 72 65 73 75 6c 74 | 20 6f 66 20 74 68 65 20 |e result| of the |
|00004af0| 63 6f 6d 70 61 72 69 73 | 6f 6e 20 6d 61 79 20 62 |comparis|on may b|
|00004b00| 65 20 74 72 75 65 20 6f | 72 20 66 61 6c 73 65 2e |e true o|r false.|
|00004b10| 20 54 68 69 73 20 77 69 | 6c 6c 20 62 65 20 63 6c | This wi|ll be cl|
|00004b20| 65 61 72 65 72 20 77 69 | 74 68 20 74 68 65 20 68 |earer wi|th the h|
|00004b30| 65 6c 70 20 6f 66 20 61 | 6e 20 65 78 61 6d 70 6c |elp of a|n exampl|
|00004b40| 65 2e 06 23 69 6e 63 6c | 75 64 65 3c 69 6f 73 74 |e..#incl|ude<iost|
|00004b50| 72 65 61 6d 2e 68 3e 06 | 76 6f 69 64 20 6d 61 69 |ream.h>.|void mai|
|00004b60| 6e 28 29 06 7b 06 69 6e | 74 20 6e 75 6d 3b 06 63 |n().{.in|t num;.c|
|00004b70| 6f 75 74 3c 3c 20 22 45 | 6e 74 65 72 20 61 20 6e |out<< "E|nter a n|
|00004b80| 75 6d 62 65 72 20 3a 22 | 3c 3c 65 6e 64 6c 3b 06 |umber :"|<<endl;.|
|00004b90| 63 69 6e 3e 3e 6e 75 6d | 3b 06 63 6f 75 74 3c 3c |cin>>num|;.cout<<|
|00004ba0| 6e 75 6d 3c 31 30 3c 3c | 65 6e 64 6c 3b 06 63 6f |num<10<<|endl;.co|
|00004bb0| 75 74 3c 3c 6e 75 6d 3e | 31 30 3c 3c 65 6e 64 6c |ut<<num>|10<<endl|
|00004bc0| 3b 06 63 6f 75 74 3c 3c | 6e 75 6d 3d 20 3d 31 30 |;.cout<<|num= =10|
|00004bd0| 3c 3c 65 6e 64 6c 3b 06 | 7d 06 74 68 65 20 6f 75 |<<endl;.|}.the ou|
|00004be0| 74 70 75 74 20 6f 66 20 | 74 68 65 20 70 72 6f 67 |tput of |the prog|
|00004bf0| 72 61 6d 20 77 69 6c 6c | 20 62 65 20 73 6f 6d 65 |ram will| be some|
|00004c00| 74 68 69 6e 67 20 6c 69 | 6b 65 20 74 68 69 73 06 |thing li|ke this.|
|00004c10| 45 6e 74 65 72 20 61 20 | 6e 75 6d 62 65 72 20 3a |Enter a |number :|
|00004c20| 20 32 30 06 30 06 31 06 | 30 06 54 68 65 20 76 61 | 20.0.1.|0.The va|
|00004c30| 6c 75 65 20 6f 66 20 61 | 20 74 72 75 65 20 65 78 |lue of a| true ex|
|00004c40| 70 72 65 73 73 69 6f 6e | 20 69 73 20 31 20 61 6e |pression| is 1 an|
|00004c50| 64 20 74 68 65 20 76 61 | 6c 75 65 20 6f 66 20 61 |d the va|lue of a|
|00004c60| 20 66 61 6c 73 65 20 65 | 78 70 72 65 73 73 69 6f | false e|xpressio|
|00004c70| 6e 20 69 73 20 61 73 73 | 75 6d 65 64 20 74 6f 20 |n is ass|umed to |
|00004c80| 62 65 20 30 2e 20 54 68 | 65 72 65 66 6f 72 65 20 |be 0. Th|erefore |
|00004c90| 74 68 65 20 6f 75 74 70 | 75 74 20 69 73 20 6c 69 |the outp|ut is li|
|00004ca0| 6b 65 20 74 68 65 20 6f | 6e 65 20 61 62 6f 76 65 |ke the o|ne above|
|00004cb0| 2e 06 54 68 65 72 65 20 | 61 72 65 20 73 69 78 20 |..There |are six |
|00004cc0| 72 65 6c 61 74 69 6f 6e | 61 6c 20 6f 70 65 72 61 |relation|al opera|
|00004cd0| 74 6f 72 73 2e 20 48 65 | 72 65 20 69 73 20 61 20 |tors. He|re is a |
|00004ce0| 6c 69 73 74 20 6f 66 20 | 74 68 65 6d 2e 06 4f 70 |list of |them..Op|
|00004cf0| 65 72 61 74 6f 72 06 20 | 4d 65 61 6e 69 6e 67 06 |erator. |Meaning.|
|00004d00| 06 3e 06 20 49 73 20 67 | 72 65 61 74 65 72 20 74 |.>. Is g|reater t|
|00004d10| 68 61 6e 06 06 3c 06 20 | 49 73 20 6c 65 73 73 20 |han..<. |Is less |
|00004d20| 74 68 61 6e 06 06 3d 20 | 3d 06 20 49 73 20 65 71 |than..= |=. Is eq|
|00004d30| 75 61 6c 20 74 6f 06 06 | 21 20 3d 06 20 4e 6f 74 |ual to..|! =. Not|
|00004d40| 20 65 71 75 61 6c 20 74 | 6f 06 06 3e 3d 06 20 47 | equal t|o..>=. G|
|00004d50| 72 65 61 74 65 72 20 74 | 68 61 6e 20 6f 72 20 65 |reater t|han or e|
|00004d60| 71 75 61 6c 20 74 6f 06 | 06 3c 3d 06 20 4c 65 73 |qual to.|.<=. Les|
|00004d70| 73 20 74 68 61 6e 20 6f | 72 20 65 71 75 61 6c 20 |s than o|r equal |
|00004d80| 74 6f 06 4c 4f 4f 50 53 | 06 57 68 65 6e 20 77 65 |to.LOOPS|.When we|
|00004d90| 20 77 61 6e 74 20 61 20 | 70 61 72 74 20 6f 66 20 | want a |part of |
|00004da0| 61 20 70 72 6f 67 72 61 | 6d 20 74 6f 20 62 65 20 |a progra|m to be |
|00004db0| 72 65 70 65 61 74 65 64 | 6c 79 20 65 78 65 63 75 |repeated|ly execu|
|00004dc0| 74 65 64 20 61 20 63 65 | 72 74 61 69 6e 20 6e 75 |ted a ce|rtain nu|
|00004dd0| 6d 62 65 72 20 6f 66 20 | 74 69 6d 65 73 2c 20 6c |mber of |times, l|
|00004de0| 6f 6f 70 73 20 61 72 65 | 20 75 73 65 64 2e 20 54 |oops are| used. T|
|00004df0| 68 65 20 72 65 70 65 74 | 69 74 69 6f 6e 20 63 6f |he repet|ition co|
|00004e00| 6e 74 69 6e 75 65 73 20 | 75 6e 74 69 6c 20 61 20 |ntinues |until a |
|00004e10| 63 65 72 74 61 69 6e 20 | 63 6f 6e 64 69 74 69 6f |certain |conditio|
|00004e20| 6e 20 69 73 20 74 72 75 | 65 2e 20 57 68 65 6e 20 |n is tru|e. When |
|00004e30| 74 68 65 20 63 6f 6e 64 | 69 74 69 6f 6e 20 62 65 |the cond|ition be|
|00004e40| 63 6f 6d 65 73 20 66 61 | 6c 73 65 2c 20 74 68 65 |comes fa|lse, the|
|00004e50| 20 63 6f 6e 74 72 6f 6c | 20 69 73 20 74 72 61 6e | control| is tran|
|00004e60| 73 66 65 72 72 65 64 20 | 74 6f 20 74 68 65 20 70 |sferred |to the p|
|00004e70| 72 6f 67 72 61 6d 20 73 | 74 61 74 65 6d 65 6e 74 |rogram s|tatement|
|00004e80| 20 66 6f 6c 6c 6f 77 69 | 6e 67 20 74 68 65 20 6c | followi|ng the l|
|00004e90| 6f 6f 70 2e 06 54 48 45 | 20 46 4f 52 20 4c 4f 4f |oop..THE| FOR LOO|
|00004ea0| 50 06 54 68 65 20 66 6f | 72 20 6c 6f 6f 70 20 69 |P.The fo|r loop i|
|00004eb0| 73 20 74 68 65 20 6d 6f | 73 74 20 70 6f 70 75 6c |s the mo|st popul|
|00004ec0| 61 72 20 66 6f 72 6d 20 | 6f 66 20 6c 6f 6f 70 73 |ar form |of loops|
|00004ed0| 2e 20 4c 69 6b 65 20 61 | 6c 6c 20 6c 6f 6f 70 73 |. Like a|ll loops|
|00004ee0| 20 74 68 65 20 66 6f 72 | 20 6c 6f 6f 70 20 61 6c | the for| loop al|
|00004ef0| 73 6f 20 65 78 65 63 75 | 74 65 73 20 61 20 73 65 |so execu|tes a se|
|00004f00| 63 74 69 6f 6e 20 6f 66 | 20 61 20 63 6f 64 65 20 |ction of| a code |
|00004f10| 61 20 70 72 65 73 63 72 | 69 62 65 64 20 6e 75 6d |a prescr|ibed num|
|00004f20| 62 65 72 20 6f 66 20 74 | 69 6d 65 73 2e 20 49 74 |ber of t|imes. It|
|00004f30| 20 69 73 20 75 73 75 61 | 6c 6c 79 20 75 73 65 64 | is usua|lly used|
|00004f40| 20 77 68 65 6e 20 74 68 | 65 20 70 72 6f 67 72 61 | when th|e progra|
|00004f50| 6d 6d 65 72 20 6b 6e 6f | 77 73 20 62 65 66 6f 72 |mmer kno|ws befor|
|00004f60| 65 68 61 6e 64 20 68 6f | 77 20 6d 61 6e 79 20 74 |ehand ho|w many t|
|00004f70| 69 6d 65 73 20 74 68 65 | 20 73 65 63 74 69 6f 6e |imes the| section|
|00004f80| 20 6f 66 20 74 68 65 20 | 63 6f 64 65 20 68 61 73 | of the |code has|
|00004f90| 20 74 6f 20 62 65 20 65 | 78 65 63 75 74 65 64 2e | to be e|xecuted.|
|00004fa0| 20 54 68 65 20 66 6f 6c | 6c 6f 77 69 6e 67 20 65 | The fol|lowing e|
|00004fb0| 78 61 6d 70 6c 65 20 64 | 65 6d 6f 6e 73 74 72 61 |xample d|emonstra|
|00004fc0| 74 65 73 20 74 68 65 20 | 75 73 61 67 65 20 6f 66 |tes the |usage of|
|00004fd0| 20 74 68 65 20 66 6f 72 | 20 6c 6f 6f 70 3a 06 23 | the for| loop:.#|
|00004fe0| 69 6e 63 6c 75 64 65 3c | 69 6f 73 74 72 65 61 6d |include<|iostream|
|00004ff0| 2e 68 3e 06 76 6f 69 64 | 20 6d 61 69 6e 28 29 06 |.h>.void| main().|
|00005000| 7b 06 69 6e 74 20 69 3b | 06 66 6f 72 28 69 3d 30 |{.int i;|.for(i=0|
|00005010| 3b 69 3c 31 30 3b 69 2b | 2b 29 06 7b 06 63 6f 75 |;i<10;i+|+).{.cou|
|00005020| 74 3c 3c 49 3c 3c 65 6e | 64 6c 3b 06 7d 06 7d 06 |t<<I<<en|dl;.}.}.|
|00005030| 54 68 65 20 6f 75 74 70 | 75 74 20 6f 66 20 74 68 |The outp|ut of th|
|00005040| 65 20 70 72 6f 67 72 61 | 6d 20 69 73 20 61 73 20 |e progra|m is as |
|00005050| 66 6f 6c 6c 6f 77 73 06 | 30 06 31 06 32 06 33 06 |follows.|0.1.2.3.|
|00005060| 34 06 35 06 36 06 37 06 | 38 06 39 06 54 68 65 20 |4.5.6.7.|8.9.The |
|00005070| 66 6f 72 20 73 74 61 74 | 65 6d 65 6e 74 20 63 6f |for stat|ement co|
|00005080| 6e 74 72 6f 6c 73 20 74 | 68 65 20 6c 6f 6f 70 2e |ntrols t|he loop.|
|00005090| 20 54 68 65 20 6b 65 79 | 77 6f 72 64 20 66 6f 72 | The key|word for|
|000050a0| 20 69 73 20 66 6f 6c 6c | 6f 77 65 64 20 62 79 20 | is foll|owed by |
|000050b0| 70 61 72 65 6e 74 68 65 | 73 65 73 2c 20 77 68 69 |parenthe|ses, whi|
|000050c0| 63 68 20 63 6f 6e 74 61 | 69 6e 20 74 68 65 20 65 |ch conta|in the e|
|000050d0| 78 70 72 65 73 73 69 6f | 6e 73 20 73 65 70 61 72 |xpressio|ns separ|
|000050e0| 61 74 65 64 20 62 79 20 | 73 65 6d 69 63 6f 6c 6f |ated by |semicolo|
|000050f0| 6e 73 2e 06 66 6f 72 20 | 28 69 3d 30 3b 69 3c 31 |ns..for |(i=0;i<1|
|00005100| 30 3b 69 2b 2b 29 06 54 | 68 65 20 74 68 72 65 65 |0;i++).T|he three|
|00005110| 20 65 78 70 72 65 73 73 | 69 6f 6e 73 20 61 72 65 | express|ions are|
|00005120| 20 69 6e 69 74 69 61 6c | 69 7a 61 74 69 6f 6e 2c | initial|ization,|
|00005130| 20 74 65 73 74 20 63 6f | 6e 64 69 74 69 6f 6e 20 | test co|ndition |
|00005140| 61 6e 64 20 69 6e 63 72 | 65 6d 65 6e 74 2f 64 65 |and incr|ement/de|
|00005150| 63 72 65 6d 65 6e 74 20 | 65 78 70 72 65 73 73 69 |crement |expressi|
|00005160| 6f 6e 73 2e 06 54 68 65 | 20 69 6e 69 74 69 61 6c |ons..The| initial|
|00005170| 69 7a 61 74 69 6f 6e 20 | 65 78 70 72 65 73 73 69 |ization |expressi|
|00005180| 6f 6e 20 69 73 20 65 78 | 65 63 75 74 65 64 20 6f |on is ex|ecuted o|
|00005190| 6e 6c 79 20 6f 6e 63 65 | 2c 20 77 68 65 6e 20 74 |nly once|, when t|
|000051a0| 68 65 20 6c 6f 6f 70 20 | 69 73 20 65 78 65 63 75 |he loop |is execu|
|000051b0| 74 65 64 20 66 6f 72 20 | 74 68 65 20 66 69 72 73 |ted for |the firs|
|000051c0| 74 20 74 69 6d 65 2e 20 | 49 74 20 67 69 76 65 73 |t time. |It gives|
|000051d0| 20 61 20 6c 6f 6f 70 20 | 76 61 72 69 61 62 6c 65 | a loop |variable|
|000051e0| 20 61 6e 20 69 6e 69 74 | 69 61 6c 20 76 61 6c 75 | an init|ial valu|
|000051f0| 65 2e 20 41 20 6c 6f 6f | 70 20 76 61 72 69 61 62 |e. A loo|p variab|
|00005200| 6c 65 20 69 73 20 61 20 | 76 61 72 69 61 62 6c 65 |le is a |variable|
|00005210| 2c 20 77 68 69 63 68 20 | 69 73 20 69 6e 76 6f 6c |, which |is invol|
|00005220| 76 65 64 20 69 6e 20 74 | 68 65 20 65 78 70 72 65 |ved in t|he expre|
|00005230| 73 73 69 6f 6e 73 20 6f | 66 20 74 68 65 20 6c 6f |ssions o|f the lo|
|00005240| 6f 70 2e 20 54 68 65 72 | 65 20 6d 61 79 20 61 6c |op. Ther|e may al|
|00005250| 73 6f 20 62 65 20 6d 6f | 72 65 20 74 68 61 6e 20 |so be mo|re than |
|00005260| 6f 6e 65 20 6c 6f 6f 70 | 20 76 61 72 69 61 62 6c |one loop| variabl|
|00005270| 65 2e 06 54 68 65 20 74 | 65 73 74 20 63 6f 6e 64 |e..The t|est cond|
|00005280| 69 74 69 6f 6e 20 65 78 | 70 72 65 73 73 69 6f 6e |ition ex|pression|
|00005290| 20 75 73 75 61 6c 6c 79 | 20 69 6e 76 6f 6c 76 65 | usually| involve|
|000052a0| 73 20 61 20 72 65 6c 61 | 74 69 6f 6e 61 6c 20 6f |s a rela|tional o|
|000052b0| 70 65 72 61 74 6f 72 2e | 20 49 74 20 69 73 20 65 |perator.| It is e|
|000052c0| 76 61 6c 75 61 74 65 64 | 20 65 61 63 68 20 74 69 |valuated| each ti|
|000052d0| 6d 65 20 74 68 72 6f 75 | 67 68 20 74 68 65 20 6c |me throu|gh the l|
|000052e0| 6f 6f 70 2e 20 49 74 20 | 64 65 74 65 72 6d 69 6e |oop. It |determin|
|000052f0| 65 73 20 77 68 65 74 68 | 65 72 20 74 68 65 20 6c |es wheth|er the l|
|00005300| 6f 6f 70 20 77 69 6c 6c | 20 62 65 20 65 78 65 63 |oop will| be exec|
|00005310| 75 74 65 64 20 61 67 61 | 69 6e 20 6f 72 20 6e 6f |uted aga|in or no|
|00005320| 74 2e 20 49 66 20 74 68 | 65 20 63 6f 6e 64 69 74 |t. If th|e condit|
|00005330| 69 6f 6e 20 69 73 20 74 | 72 75 65 2c 20 74 68 65 |ion is t|rue, the|
|00005340| 20 6c 6f 6f 70 20 69 73 | 20 65 78 65 63 75 74 65 | loop is| execute|
|00005350| 64 20 61 67 61 69 6e 2e | 20 49 66 20 74 68 65 20 |d again.| If the |
|00005360| 63 6f 6e 64 69 74 69 6f | 6e 20 69 73 20 66 61 6c |conditio|n is fal|
|00005370| 73 65 20 74 68 65 20 63 | 6f 6e 74 72 6f 6c 20 63 |se the c|ontrol c|
|00005380| 6f 6d 65 73 20 6f 75 74 | 20 6f 66 20 74 68 65 20 |omes out| of the |
|00005390| 6c 6f 6f 70 20 61 6e 64 | 20 74 68 65 20 70 72 6f |loop and| the pro|
|000053a0| 67 72 61 6d 20 73 74 61 | 74 65 6d 65 6e 74 20 66 |gram sta|tement f|
|000053b0| 6f 6c 6c 6f 77 69 6e 67 | 20 74 68 65 20 6c 6f 6f |ollowing| the loo|
|000053c0| 70 20 69 73 20 65 78 65 | 63 75 74 65 64 2e 06 54 |p is exe|cuted..T|
|000053d0| 68 65 20 69 6e 63 72 65 | 6d 65 6e 74 20 65 78 70 |he incre|ment exp|
|000053e0| 72 65 73 73 69 6f 6e 20 | 63 68 61 6e 67 65 73 20 |ression |changes |
|000053f0| 74 68 65 20 76 61 6c 75 | 65 20 6f 66 20 74 68 65 |the valu|e of the|
|00005400| 20 6c 6f 6f 70 20 76 61 | 72 69 61 62 6c 65 2c 20 | loop va|riable, |
|00005410| 6f 66 74 65 6e 20 62 79 | 20 69 6e 63 72 65 6d 65 |often by| increme|
|00005420| 6e 74 69 6e 67 20 69 74 | 2e 20 49 74 20 69 73 20 |nting it|. It is |
|00005430| 61 6c 77 61 79 73 20 65 | 78 65 63 75 74 65 64 20 |always e|xecuted |
|00005440| 61 74 20 74 68 65 20 65 | 6e 64 20 6f 66 20 74 68 |at the e|nd of th|
|00005450| 65 20 6c 6f 6f 70 2c 20 | 61 66 74 65 72 20 74 68 |e loop, |after th|
|00005460| 65 20 6c 6f 6f 70 20 62 | 6f 64 79 20 68 61 73 20 |e loop b|ody has |
|00005470| 62 65 65 6e 20 65 78 65 | 63 75 74 65 64 2e 20 49 |been exe|cuted. I|
|00005480| 6e 20 6f 75 72 20 65 78 | 61 6d 70 6c 65 2c 20 74 |n our ex|ample, t|
|00005490| 68 65 20 6c 6f 6f 70 20 | 69 73 20 65 78 65 63 75 |he loop |is execu|
|000054a0| 74 65 64 20 31 30 20 74 | 69 6d 65 73 2e 20 54 68 |ted 10 t|imes. Th|
|000054b0| 65 20 66 69 72 73 74 20 | 74 69 6d 65 20 74 68 65 |e first |time the|
|000054c0| 20 76 61 6c 75 65 20 6f | 66 20 69 20 69 73 20 30 | value o|f i is 0|
|000054d0| 2e 20 54 68 69 73 20 6b | 65 65 70 73 20 69 6e 63 |. This k|eeps inc|
|000054e0| 72 65 6d 65 6e 74 69 6e | 67 20 74 69 6c 6c 20 69 |rementin|g till i|
|000054f0| 74 20 61 74 74 61 69 6e | 73 20 74 68 65 20 76 61 |t attain|s the va|
|00005500| 6c 75 65 20 6f 66 20 39 | 2e 20 4f 6e 63 65 20 74 |lue of 9|. Once t|
|00005510| 68 65 20 63 6f 6e 64 69 | 74 69 6f 6e 20 69 3c 31 |he condi|tion i<1|
|00005520| 30 20 62 65 63 6f 6d 65 | 73 20 66 61 6c 73 65 2c |0 become|s false,|
|00005530| 20 74 68 65 20 63 6f 6e | 74 72 6f 6c 20 63 6f 6d | the con|trol com|
|00005540| 65 73 20 6f 75 74 20 6f | 66 20 74 68 65 20 6c 6f |es out o|f the lo|
|00005550| 6f 70 2e 20 54 68 65 20 | 62 6f 64 79 20 6f 66 20 |op. The |body of |
|00005560| 74 68 65 20 6c 6f 6f 70 | 20 69 73 20 74 68 65 20 |the loop| is the |
|00005570| 63 6f 64 65 2c 20 77 68 | 69 63 68 20 68 61 73 20 |code, wh|ich has |
|00005580| 74 6f 20 62 65 20 65 78 | 65 63 75 74 65 64 20 72 |to be ex|ecuted r|
|00005590| 65 70 65 61 74 65 64 6c | 79 20 75 6e 74 69 6c 20 |epeatedl|y until |
|000055a0| 74 68 65 20 63 6f 6e 64 | 69 74 69 6f 6e 20 69 73 |the cond|ition is|
|000055b0| 20 74 72 75 65 2e 20 49 | 6e 20 6f 75 72 20 65 78 | true. I|n our ex|
|000055c0| 61 6d 70 6c 65 2c 20 74 | 68 65 20 62 6f 64 79 20 |ample, t|he body |
|000055d0| 6f 66 20 74 68 65 20 6c | 6f 6f 70 20 63 6f 6e 74 |of the l|oop cont|
|000055e0| 61 69 6e 73 20 6f 6e 6c | 79 20 6f 6e 65 20 70 72 |ains onl|y one pr|
|000055f0| 6f 67 72 61 6d 20 73 74 | 61 74 65 6d 65 6e 74 2c |ogram st|atement,|
|00005600| 20 62 75 74 20 69 6e 20 | 6f 74 68 65 72 20 63 61 | but in |other ca|
|00005610| 73 65 73 20 69 74 20 6d | 61 79 20 63 6f 6e 74 61 |ses it m|ay conta|
|00005620| 69 6e 20 6d 6f 72 65 20 | 74 68 61 6e 20 6f 6e 65 |in more |than one|
|00005630| 2e 20 54 68 65 72 65 20 | 69 73 20 6e 6f 20 73 65 |. There |is no se|
|00005640| 6d 69 63 6f 6c 6f 6e 20 | 61 66 74 65 72 20 74 68 |micolon |after th|
|00005650| 65 20 66 6f 72 20 73 74 | 61 74 65 6d 65 6e 74 20 |e for st|atement |
|00005660| 62 65 63 61 75 73 65 20 | 74 68 65 20 66 6f 72 20 |because |the for |
|00005670| 73 74 61 74 65 6d 65 6e | 74 20 61 6e 64 20 6c 6f |statemen|t and lo|
|00005680| 6f 70 20 62 6f 64 79 20 | 74 6f 67 65 74 68 65 72 |op body |together|
|00005690| 20 61 72 65 20 63 6f 6e | 73 69 64 65 72 65 64 20 | are con|sidered |
|000056a0| 74 6f 20 62 65 20 6f 6e | 65 20 70 72 6f 67 72 61 |to be on|e progra|
|000056b0| 6d 20 73 74 61 74 65 6d | 65 6e 74 2e 06 4e 6f 74 |m statem|ent..Not|
|000056c0| 65 20 3a 20 41 20 66 6f | 72 20 73 74 61 74 65 6d |e : A fo|r statem|
|000056d0| 65 6e 74 20 77 69 74 68 | 20 73 69 6e 67 6c 65 20 |ent with| single |
|000056e0| 6c 69 6e 65 20 62 6f 64 | 79 20 64 6f 65 73 20 6e |line bod|y does n|
|000056f0| 6f 74 20 6e 65 65 64 20 | 62 72 61 63 65 73 2e 06 |ot need |braces..|
|00005700| 54 68 65 20 69 6e 63 72 | 65 6d 65 6e 74 20 65 78 |The incr|ement ex|
|00005710| 70 72 65 73 73 69 6f 6e | 20 64 6f 65 73 20 6e 6f |pression| does no|
|00005720| 74 20 61 6c 77 61 79 73 | 20 6e 65 65 64 20 74 6f |t always| need to|
|00005730| 20 69 6e 63 72 65 6d 65 | 6e 74 2e 20 49 74 20 63 | increme|nt. It c|
|00005740| 61 6e 20 61 6c 73 6f 20 | 70 65 72 66 6f 72 6d 20 |an also |perform |
|00005750| 6f 74 68 65 72 20 6f 70 | 65 72 61 74 69 6f 6e 73 |other op|erations|
|00005760| 2e 20 49 6e 20 74 68 65 | 20 6e 65 78 74 20 65 78 |. In the| next ex|
|00005770| 61 6d 70 6c 65 2c 20 74 | 68 65 20 6c 6f 6f 70 20 |ample, t|he loop |
|00005780| 76 61 72 69 61 62 6c 65 | 20 69 73 20 64 65 63 72 |variable| is decr|
|00005790| 65 6d 65 6e 74 65 64 2e | 06 23 69 6e 63 6c 75 64 |emented.|.#includ|
|000057a0| 65 3c 69 6f 73 74 72 65 | 61 6d 2e 68 3e 06 76 6f |e<iostre|am.h>.vo|
|000057b0| 69 64 20 6d 61 69 6e 28 | 29 06 7b 06 75 6e 73 69 |id main(|).{.unsi|
|000057c0| 67 6e 65 64 20 69 6e 74 | 20 6e 75 6d 3b 06 75 6e |gned int| num;.un|
|000057d0| 73 69 67 6e 65 64 20 6c | 6f 6e 67 20 66 61 63 74 |signed l|ong fact|
|000057e0| 3d 31 3b 06 63 6f 75 74 | 3c 3c 20 22 45 6e 74 65 |=1;.cout|<< "Ente|
|000057f0| 72 20 61 20 6e 75 6d 62 | 65 72 20 3a 22 3b 06 63 |r a numb|er :";.c|
|00005800| 69 6e 3e 3e 6e 75 6d 3b | 06 66 6f 72 20 28 69 6e |in>>num;|.for (in|
|00005810| 74 20 69 3d 6e 75 6d 3b | 69 3e 30 3b 69 2d 2d 29 |t i=num;|i>0;i--)|
|00005820| 06 7b 06 66 61 63 74 2a | 3d 69 3b 06 7d 06 63 6f |.{.fact*|=i;.}.co|
|00005830| 75 74 3c 3c 20 22 54 68 | 65 20 66 61 63 74 6f 72 |ut<< "Th|e factor|
|00005840| 69 61 6c 20 69 73 20 3a | 22 3c 3c 66 61 63 74 3b |ial is :|"<<fact;|
|00005850| 06 7d 06 57 65 20 63 61 | 6e 20 70 75 74 20 6d 6f |.}.We ca|n put mo|
|00005860| 72 65 20 74 68 61 6e 20 | 6f 6e 65 20 65 78 70 72 |re than |one expr|
|00005870| 65 73 73 69 6f 6e 20 69 | 6e 20 74 68 65 20 69 6e |ession i|n the in|
|00005880| 69 74 69 61 6c 69 7a 61 | 74 69 6f 6e 2c 20 74 65 |itializa|tion, te|
|00005890| 73 74 20 63 6f 6e 64 69 | 74 69 6f 6e 20 61 6e 64 |st condi|tion and|
|000058a0| 20 69 6e 63 72 65 6d 65 | 6e 74 20 65 78 70 72 65 | increme|nt expre|
|000058b0| 73 73 69 6f 6e 73 20 70 | 61 72 74 73 20 6f 66 20 |ssions p|arts of |
|000058c0| 74 68 65 20 66 6f 72 20 | 73 74 61 74 65 6d 65 6e |the for |statemen|
|000058d0| 74 2e 20 43 6f 6d 6d 61 | 73 20 73 65 70 61 72 61 |t. Comma|s separa|
|000058e0| 74 65 20 74 68 65 20 64 | 69 66 66 65 72 65 6e 74 |te the d|ifferent|
|000058f0| 20 65 78 70 72 65 73 73 | 69 6f 6e 73 2e 06 46 6f | express|ions..Fo|
|00005900| 72 20 65 78 61 6d 70 6c | 65 3a 06 66 6f 72 28 6b |r exampl|e:.for(k|
|00005910| 3d 30 2c 6a 3d 31 3b 20 | 6b 3c 3d 31 30 2c 6a 3e |=0,j=1; |k<=10,j>|
|00005920| 32 30 3b 85 29 06 54 48 | 45 20 57 48 49 4c 45 20 |20;.).TH|E WHILE |
|00005930| 4c 4f 4f 50 06 54 68 65 | 20 66 6f 72 20 6c 6f 6f |LOOP.The| for loo|
|00005940| 70 20 65 78 65 63 75 74 | 65 73 20 61 20 63 6f 64 |p execut|es a cod|
|00005950| 65 20 66 6f 72 20 61 20 | 66 69 78 65 64 20 6e 75 |e for a |fixed nu|
|00005960| 6d 62 65 72 20 6f 66 20 | 74 69 6d 65 73 2e 20 57 |mber of |times. W|
|00005970| 68 61 74 20 77 6f 75 6c | 64 20 68 61 70 70 65 6e |hat woul|d happen|
|00005980| 20 69 66 20 77 65 20 64 | 6f 20 6e 6f 74 20 73 70 | if we d|o not sp|
|00005990| 65 63 69 66 79 20 68 6f | 77 20 6d 61 6e 79 20 74 |ecify ho|w many t|
|000059a0| 69 6d 65 73 20 77 65 20 | 77 61 6e 74 20 74 6f 20 |imes we |want to |
|000059b0| 65 78 65 63 75 74 65 20 | 74 68 65 20 63 6f 64 65 |execute |the code|
|000059c0| 2e 20 49 6e 20 73 75 63 | 68 20 63 61 73 65 73 20 |. In suc|h cases |
|000059d0| 77 65 20 6d 61 6b 65 20 | 75 73 65 20 6f 66 20 74 |we make |use of t|
|000059e0| 68 65 20 77 68 69 6c 65 | 20 6c 6f 6f 70 2e 20 49 |he while| loop. I|
|000059f0| 6e 20 74 68 65 20 66 6f | 6c 6c 6f 77 69 6e 67 20 |n the fo|llowing |
|00005a00| 65 78 61 6d 70 6c 65 20 | 77 65 20 61 73 6b 20 74 |example |we ask t|
|00005a10| 68 65 20 75 73 65 72 20 | 74 6f 20 65 6e 74 65 72 |he user |to enter|
|00005a20| 20 61 20 6e 75 6d 62 65 | 72 2e 20 49 66 20 74 68 | a numbe|r. If th|
|00005a30| 65 20 6e 75 6d 62 65 72 | 20 69 73 20 61 20 30 2c |e number| is a 0,|
|00005a40| 20 74 68 65 20 6c 6f 6f | 70 20 74 65 72 6d 69 6e | the loo|p termin|
|00005a50| 61 74 65 73 2c 20 6f 74 | 68 65 72 77 69 73 65 20 |ates, ot|herwise |
|00005a60| 74 68 65 20 75 73 65 72 | 20 69 73 20 70 72 6f 6d |the user| is prom|
|00005a70| 70 74 65 64 20 74 6f 20 | 65 6e 74 65 72 20 61 6e |pted to |enter an|
|00005a80| 6f 74 68 65 72 20 6e 75 | 6d 62 65 72 2e 20 54 68 |other nu|mber. Th|
|00005a90| 65 72 65 20 69 73 20 6e | 6f 20 77 61 79 20 74 68 |ere is n|o way th|
|00005aa0| 65 20 70 72 6f 67 72 61 | 6d 20 77 6f 75 6c 64 20 |e progra|m would |
|00005ab0| 6b 6e 6f 77 20 68 6f 77 | 20 6d 61 6e 79 20 74 69 |know how| many ti|
|00005ac0| 6d 65 73 20 74 68 65 20 | 75 73 65 72 20 69 73 20 |mes the |user is |
|00005ad0| 70 72 6f 6d 70 74 65 64 | 2e 20 54 68 69 73 20 69 |prompted|. This i|
|00005ae0| 73 20 74 6f 74 61 6c 6c | 79 20 63 6f 6e 74 72 6f |s totall|y contro|
|00005af0| 6c 6c 65 64 20 62 79 20 | 74 68 65 20 75 73 65 72 |lled by |the user|
|00005b00| 2e 06 23 69 6e 63 6c 75 | 64 65 3c 69 6f 73 74 72 |..#inclu|de<iostr|
|00005b10| 65 61 6d 2e 68 3e 06 76 | 6f 69 64 20 6d 61 69 6e |eam.h>.v|oid main|
|00005b20| 28 29 06 7b 06 69 6e 74 | 20 69 3d 39 39 3b 06 77 |().{.int| i=99;.w|
|00005b30| 68 69 6c 65 20 28 69 21 | 3d 30 29 06 7b 06 63 69 |hile (i!|=0).{.ci|
|00005b40| 6e 3e 3e 69 3b 06 7d 06 | 7d 06 54 68 65 20 73 79 |n>>i;.}.|}.The sy|
|00005b50| 6e 74 61 78 20 6f 66 20 | 74 68 65 20 77 68 69 6c |ntax of |the whil|
|00005b60| 65 20 6c 6f 6f 70 20 69 | 73 20 73 69 6d 70 6c 65 |e loop i|s simple|
|00005b70| 72 20 74 68 61 6e 20 74 | 68 65 20 66 6f 72 20 6c |r than t|he for l|
|00005b80| 6f 6f 70 2e 20 49 74 20 | 63 6f 6e 74 61 69 6e 73 |oop. It |contains|
|00005b90| 20 61 20 74 65 73 74 20 | 63 6f 6e 64 69 74 69 6f | a test |conditio|
|00005ba0| 6e 20 65 78 70 72 65 73 | 73 69 6f 6e 20 62 75 74 |n expres|sion but|
|00005bb0| 20 6e 6f 20 69 6e 69 74 | 69 61 6c 69 7a 61 74 69 | no init|ializati|
|00005bc0| 6f 6e 20 61 6e 64 20 69 | 6e 63 72 65 6d 65 6e 74 |on and i|ncrement|
|00005bd0| 20 65 78 70 72 65 73 73 | 69 6f 6e 73 2e 20 41 73 | express|ions. As|
|00005be0| 20 6c 6f 6e 67 20 61 73 | 20 74 68 65 20 63 6f 6e | long as| the con|
|00005bf0| 64 69 74 69 6f 6e 20 69 | 6e 20 74 68 65 20 74 65 |dition i|n the te|
|00005c00| 73 74 20 63 6f 6e 64 69 | 74 69 6f 6e 20 65 78 70 |st condi|tion exp|
|00005c10| 72 65 73 73 69 6f 6e 20 | 69 73 20 74 72 75 65 20 |ression |is true |
|00005c20| 74 68 65 20 6c 6f 6f 70 | 20 69 73 20 65 78 65 63 |the loop| is exec|
|00005c30| 75 74 65 64 2e 20 54 68 | 65 20 61 62 73 65 6e 63 |uted. Th|e absenc|
|00005c40| 65 20 6f 66 20 74 68 65 | 20 69 6e 63 72 65 6d 65 |e of the| increme|
|00005c50| 6e 74 20 65 78 70 72 65 | 73 73 69 6f 6e 20 6d 61 |nt expre|ssion ma|
|00005c60| 79 20 63 72 65 61 74 65 | 20 73 6f 6d 65 20 70 72 |y create| some pr|
|00005c70| 6f 62 6c 65 6d 73 2e 20 | 46 6f 72 20 69 6e 73 74 |oblems. |For inst|
|00005c80| 61 6e 63 65 2c 20 74 68 | 65 20 6c 6f 6f 70 20 6d |ance, th|e loop m|
|00005c90| 61 79 20 77 6f 72 6b 20 | 65 6e 64 6c 65 73 73 6c |ay work |endlessl|
|00005ca0| 79 2e 20 49 6e 20 6f 72 | 64 65 72 20 74 6f 20 63 |y. In or|der to c|
|00005cb0| 6f 6e 74 72 6f 6c 20 74 | 68 69 73 2c 20 61 20 6c |ontrol t|his, a l|
|00005cc0| 6f 6f 70 20 76 61 72 69 | 61 62 6c 65 20 6d 61 79 |oop vari|able may|
|00005cd0| 20 62 65 20 69 6e 63 6c | 75 64 65 64 20 77 68 69 | be incl|uded whi|
|00005ce0| 63 68 20 63 6f 6e 74 72 | 6f 6c 73 20 74 68 65 20 |ch contr|ols the |
|00005cf0| 6e 75 6d 62 65 72 20 6f | 66 20 74 69 6d 65 73 20 |number o|f times |
|00005d00| 74 68 65 20 62 6c 6f 63 | 6b 20 6f 66 20 63 6f 64 |the bloc|k of cod|
|00005d10| 65 20 69 73 20 65 78 65 | 63 75 74 65 64 2e 20 4c |e is exe|cuted. L|
|00005d20| 69 6b 65 20 74 68 65 20 | 66 6f 72 20 6c 6f 6f 70 |ike the |for loop|
|00005d30| 2c 20 74 68 69 73 20 6c | 6f 6f 70 20 6d 61 79 20 |, this l|oop may |
|00005d40| 61 6c 73 6f 20 68 61 76 | 65 20 6d 75 6c 74 69 70 |also hav|e multip|
|00005d50| 6c 65 20 70 72 6f 67 72 | 61 6d 20 73 74 61 74 65 |le progr|am state|
|00005d60| 6d 65 6e 74 73 2e 06 54 | 48 45 20 44 4f 20 57 48 |ments..T|HE DO WH|
|00005d70| 49 4c 45 20 4c 4f 4f 50 | 06 49 6e 20 61 20 77 68 |ILE LOOP|.In a wh|
|00005d80| 69 6c 65 20 6c 6f 6f 70 | 2c 20 74 68 65 20 74 65 |ile loop|, the te|
|00005d90| 73 74 20 65 78 70 72 65 | 73 73 69 6f 6e 20 69 73 |st expre|ssion is|
|00005da0| 20 65 76 61 6c 75 61 74 | 65 64 20 61 74 20 74 68 | evaluat|ed at th|
|00005db0| 65 20 62 65 67 69 6e 6e | 69 6e 67 20 6f 66 20 74 |e beginn|ing of t|
|00005dc0| 68 65 20 6c 6f 6f 70 2e | 20 49 66 20 74 68 65 20 |he loop.| If the |
|00005dd0| 74 65 73 74 20 65 78 70 | 72 65 73 73 69 6f 6e 20 |test exp|ression |
|00005de0| 69 73 20 66 61 6c 73 65 | 20 77 68 65 6e 20 74 68 |is false| when th|
|00005df0| 65 20 6c 6f 6f 70 20 69 | 73 20 65 6e 74 65 72 65 |e loop i|s entere|
|00005e00| 64 2c 20 74 68 65 20 62 | 6c 6f 63 6b 20 6f 66 20 |d, the b|lock of |
|00005e10| 63 6f 64 65 20 77 69 6c | 6c 20 6e 6f 74 20 62 65 |code wil|l not be|
|00005e20| 20 65 78 65 63 75 74 65 | 64 2e 20 49 6e 20 73 6f | execute|d. In so|
|00005e30| 6d 65 20 73 69 74 75 61 | 74 69 6f 6e 73 20 77 65 |me situa|tions we|
|00005e40| 20 6d 61 79 20 77 61 6e | 74 20 74 68 65 20 6c 6f | may wan|t the lo|
|00005e50| 6f 70 20 74 6f 20 62 65 | 20 65 78 65 63 75 74 65 |op to be| execute|
|00005e60| 64 20 61 74 20 6c 65 61 | 73 74 20 6f 6e 63 65 20 |d at lea|st once |
|00005e70| 72 65 67 61 72 64 6c 65 | 73 73 20 6f 66 20 74 68 |regardle|ss of th|
|00005e80| 65 20 63 6f 6e 64 69 74 | 69 6f 6e 2e 20 49 6e 20 |e condit|ion. In |
|00005e90| 73 75 63 68 20 63 61 73 | 65 73 20 74 68 65 20 64 |such cas|es the d|
|00005ea0| 6f 20 77 68 69 6c 65 20 | 6c 6f 6f 70 20 69 73 20 |o while |loop is |
|00005eb0| 75 73 65 64 2e 06 23 69 | 6e 63 6c 75 64 65 3c 69 |used..#i|nclude<i|
|00005ec0| 6f 73 74 72 65 61 6d 2e | 68 3e 06 76 6f 69 64 20 |ostream.|h>.void |
|00005ed0| 6d 61 69 6e 28 29 06 7b | 06 69 6e 74 20 6e 2c 20 |main().{|.int n, |
|00005ee0| 66 3d 31 3b 06 63 6f 75 | 74 3c 3c 20 22 45 6e 74 |f=1;.cou|t<< "Ent|
|00005ef0| 65 72 20 61 20 70 6f 73 | 69 74 69 76 65 20 69 6e |er a pos|itive in|
|00005f00| 74 65 67 65 72 20 3a 22 | 3b 06 63 69 6e 3e 3e 6e |teger :"|;.cin>>n|
|00005f10| 3b 06 64 6f 06 7b 06 66 | 2a 3d 6e 3b 06 6e 2d 2d |;.do.{.f|*=n;.n--|
|00005f20| 3b 06 7d 06 77 68 69 6c | 65 28 6e 3e 31 29 06 63 |;.}.whil|e(n>1).c|
|00005f30| 6f 75 74 3c 3c 20 22 54 | 68 65 20 66 61 63 74 6f |out<< "T|he facto|
|00005f40| 72 69 61 6c 20 69 73 20 | 3a 22 3c 3c 66 3b 06 44 |rial is |:"<<f;.D|
|00005f50| 45 43 49 53 49 4f 4e 53 | 06 44 65 63 69 73 69 6f |ECISIONS|.Decisio|
|00005f60| 6e 73 2c 20 6c 69 6b 65 | 20 6c 6f 6f 70 73 2c 20 |ns, like| loops, |
|00005f70| 61 72 65 20 69 6d 70 6f | 72 74 61 6e 74 20 62 75 |are impo|rtant bu|
|00005f80| 69 6c 64 69 6e 67 20 62 | 6c 6f 63 6b 73 20 6f 66 |ilding b|locks of|
|00005f90| 20 70 72 6f 67 72 61 6d | 73 2e 20 41 74 20 73 6f | program|s. At so|
|00005fa0| 6d 65 20 70 6f 69 6e 74 | 20 6f 72 20 74 68 65 20 |me point| or the |
|00005fb0| 6f 74 68 65 72 2c 20 61 | 20 70 72 6f 67 72 61 6d |other, a| program|
|00005fc0| 20 6e 65 65 64 73 20 74 | 6f 20 6d 61 6b 65 20 61 | needs t|o make a|
|00005fd0| 20 64 65 63 69 73 69 6f | 6e 20 77 68 65 74 68 65 | decisio|n whethe|
|00005fe0| 72 20 61 20 70 61 72 74 | 69 63 75 6c 61 72 20 62 |r a part|icular b|
|00005ff0| 6c 6f 63 6b 20 6f 66 20 | 63 6f 64 65 20 68 61 73 |lock of |code has|
|00006000| 20 74 6f 20 62 65 20 65 | 78 65 63 75 74 65 64 20 | to be e|xecuted |
|00006010| 6f 72 20 6e 6f 74 2e 20 | 44 65 63 69 73 69 6f 6e |or not. |Decision|
|00006020| 2d 6d 61 6b 69 6e 67 20 | 69 73 20 73 75 70 70 6c |-making |is suppl|
|00006030| 65 6d 65 6e 74 65 64 20 | 62 79 20 73 74 61 74 65 |emented |by state|
|00006040| 6d 65 6e 74 73 20 6c 69 | 6b 65 20 69 66 85 2e 65 |ments li|ke if..e|
|00006050| 6c 73 65 20 61 6e 64 20 | 73 77 69 74 63 68 20 73 |lse and |switch s|
|00006060| 74 61 74 65 6d 65 6e 74 | 73 2e 20 41 73 20 61 20 |tatement|s. As a |
|00006070| 72 65 73 75 6c 74 20 6f | 66 20 64 65 63 69 73 69 |result o|f decisi|
|00006080| 6f 6e 2d 6d 61 6b 69 6e | 67 2c 20 74 68 65 20 63 |on-makin|g, the c|
|00006090| 6f 6e 74 72 6f 6c 20 6f | 66 20 74 68 65 20 70 72 |ontrol o|f the pr|
|000060a0| 6f 67 72 61 6d 20 6a 75 | 6d 70 73 20 74 6f 20 61 |ogram ju|mps to a|
|000060b0| 20 64 69 66 66 65 72 65 | 6e 74 20 70 61 72 74 20 | differe|nt part |
|000060c0| 6f 66 20 74 68 65 20 70 | 72 6f 67 72 61 6d 2e 06 |of the p|rogram..|
|000060d0| 54 48 45 20 49 46 20 53 | 54 41 54 45 4d 45 4e 54 |THE IF S|TATEMENT|
|000060e0| 06 54 68 65 20 69 66 20 | 73 74 61 74 65 6d 65 6e |.The if |statemen|
|000060f0| 74 20 69 73 20 74 68 65 | 20 73 69 6d 70 6c 65 73 |t is the| simples|
|00006100| 74 20 66 6f 72 6d 20 6f | 66 20 61 20 64 65 63 69 |t form o|f a deci|
|00006110| 73 69 6f 6e 2d 6d 61 6b | 69 6e 67 20 73 74 61 74 |sion-mak|ing stat|
|00006120| 65 6d 65 6e 74 20 61 6e | 64 20 69 73 20 61 6c 73 |ement an|d is als|
|00006130| 6f 20 74 68 65 20 6d 6f | 73 74 20 75 73 65 66 75 |o the mo|st usefu|
|00006140| 6c 2e 20 48 65 72 65 20 | 69 73 20 61 6e 20 65 78 |l. Here |is an ex|
|00006150| 61 6d 70 6c 65 06 23 69 | 6e 63 6c 75 64 65 3c 69 |ample.#i|nclude<i|
|00006160| 6f 73 74 72 65 61 6d 2e | 68 3e 06 76 6f 69 64 20 |ostream.|h>.void |
|00006170| 6d 61 69 6e 28 29 06 7b | 06 69 6e 74 20 78 3b 06 |main().{|.int x;.|
|00006180| 63 6f 75 74 3c 3c 20 22 | 45 6e 74 65 72 20 61 20 |cout<< "|Enter a |
|00006190| 6e 75 6d 62 65 72 20 3a | 22 3b 06 63 69 6e 3e 3e |number :|";.cin>>|
|000061a0| 78 3b 06 69 66 28 78 3e | 31 30 30 29 06 7b 06 63 |x;.if(x>|100).{.c|
|000061b0| 6f 75 74 3c 3c 20 22 54 | 68 65 20 6e 75 6d 62 65 |out<< "T|he numbe|
|000061c0| 72 20 69 73 20 67 72 65 | 61 74 65 72 20 74 68 61 |r is gre|ater tha|
|000061d0| 6e 20 31 30 30 22 3b 06 | 7d 06 54 68 65 20 6f 75 |n 100";.|}.The ou|
|000061e0| 74 70 75 74 20 6f 66 20 | 74 68 65 20 61 62 6f 76 |tput of |the abov|
|000061f0| 65 20 70 72 6f 67 72 61 | 6d 20 69 73 20 73 6f 6d |e progra|m is som|
|00006200| 65 74 68 69 6e 67 20 6c | 69 6b 65 20 74 68 69 73 |ething l|ike this|
|00006210| 06 45 6e 74 65 72 20 61 | 20 6e 75 6d 62 65 72 20 |.Enter a| number |
|00006220| 3a 20 39 30 30 06 54 68 | 65 20 6e 75 6d 62 65 72 |: 900.Th|e number|
|00006230| 20 69 73 20 67 72 65 61 | 74 65 72 20 74 68 61 6e | is grea|ter than|
|00006240| 20 31 30 30 2e 06 54 68 | 65 20 6b 65 79 77 6f 72 | 100..Th|e keywor|
|00006250| 64 20 69 66 20 69 73 20 | 66 6f 6c 6c 6f 77 65 64 |d if is |followed|
|00006260| 20 62 79 20 61 20 74 65 | 73 74 20 65 78 70 72 65 | by a te|st expre|
|00006270| 73 73 69 6f 6e 20 69 6e | 20 70 61 72 65 6e 74 68 |ssion in| parenth|
|00006280| 65 73 65 73 2e 20 54 68 | 65 20 73 79 6e 74 61 78 |eses. Th|e syntax|
|00006290| 20 6f 66 20 74 68 65 20 | 69 66 20 73 74 61 74 65 | of the |if state|
|000062a0| 6d 65 6e 74 20 69 73 20 | 76 65 72 79 20 6d 75 63 |ment is |very muc|
|000062b0| 68 20 6c 69 6b 65 20 74 | 68 61 74 20 6f 66 20 74 |h like t|hat of t|
|000062c0| 68 65 20 77 68 69 6c 65 | 20 73 74 61 74 65 6d 65 |he while| stateme|
|000062d0| 6e 74 2e 20 42 75 74 20 | 74 68 65 20 64 69 66 66 |nt. But |the diff|
|000062e0| 65 72 65 6e 63 65 20 69 | 73 20 74 68 61 74 20 74 |erence i|s that t|
|000062f0| 68 65 20 73 74 61 74 65 | 6d 65 6e 74 73 20 66 6f |he state|ments fo|
|00006300| 6c 6c 6f 77 69 6e 67 20 | 69 66 20 61 72 65 20 65 |llowing |if are e|
|00006310| 78 65 63 75 74 65 64 20 | 6f 6e 6c 79 20 6f 6e 63 |xecuted |only onc|
|00006320| 65 20 61 6e 64 20 74 68 | 61 74 20 6f 66 20 77 68 |e and th|at of wh|
|00006330| 69 6c 65 20 61 72 65 20 | 72 65 70 65 61 74 65 64 |ile are |repeated|
|00006340| 20 74 69 6c 6c 20 74 68 | 65 20 74 65 73 74 20 65 | till th|e test e|
|00006350| 78 70 72 65 73 73 69 6f | 6e 20 69 73 20 74 72 75 |xpressio|n is tru|
|00006360| 65 2e 20 54 68 65 72 65 | 20 63 61 6e 20 62 65 20 |e. There| can be |
|00006370| 6d 75 6c 74 69 70 6c 65 | 20 73 74 61 74 65 6d 65 |multiple| stateme|
|00006380| 6e 74 73 20 64 65 6c 69 | 6d 69 74 65 64 20 62 79 |nts deli|mited by|
|00006390| 20 62 72 61 63 65 73 20 | 69 6e 20 74 68 65 20 69 | braces |in the i|
|000063a0| 66 20 73 74 61 74 65 6d | 65 6e 74 2e 20 54 68 65 |f statem|ent. The|
|000063b0| 20 63 6f 64 65 20 69 6e | 73 69 64 65 20 74 68 65 | code in|side the|
|000063c0| 20 62 72 61 63 65 73 20 | 69 73 20 65 78 65 63 75 | braces |is execu|
|000063d0| 74 65 64 20 69 66 20 74 | 68 65 20 63 6f 6e 64 69 |ted if t|he condi|
|000063e0| 74 69 6f 6e 20 69 73 20 | 74 72 75 65 2c 20 6f 74 |tion is |true, ot|
|000063f0| 68 65 72 77 69 73 65 20 | 74 68 65 20 63 6f 6d 70 |herwise |the comp|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.