VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ17²¿·Ö
°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·ҳ£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡
thousand¡¡means¡¡adding¡¡a¡¡number¡¡that¡¡is¡¡less¡¡than¡¡the¡¡roundoff¡£¡¡The¡¡answer¡¡is¡¡that¡¡I¡¡cannot¡¡¡¡
add¡¡1£»000¡¡to¡¡10¡£2£»¡¡because¡¡the¡¡1£»000¡¡is¡¡not¡¡significant¡¡with¡¡respect¡¡to¡¡the¡¡number¡¡10¡£2¡£¡¡But¡¡I¡¡¡¡
can¡¡add¡¡1£»000¡¡to¡¡10£»164£»818£»¡¡to¡¡get¡¡10£»165£»818£»¡¡because¡¡the¡¡most¡¡significant¡¡value¡¡is¡¡a¡¡single¡¡¡¡
whole¡¡number¡£¡¡
¡¡¡¡¡¡¡¡¡¡Relating¡¡this¡¡back¡¡to¡¡numeric¡¡types£»¡¡it¡¡means¡¡integer¡based¡¡numbers¡¡have¡¡a¡¡most¡¡signifi
cant¡¡single¡¡whole¡¡number¡£¡¡Adding¡¡1¡£5¡¡and¡¡1¡£2¡¡as¡¡whole¡¡numbers¡¡results¡¡in¡¡3£»¡¡as¡¡illustrated¡¡in¡¡¡¡
Figure¡¡2¡15¡£¡¡
¡¡¡¡¡¡¡¡¡¡Let¡¯s¡¡extend¡¡this¡¡concept¡¡of¡¡significant¡¡digits¡¡to¡¡a¡¡floating¡point¡¡number¡¡type£»¡¡Single£»¡¡and¡¡¡¡
consider¡¡the¡¡example¡¡shown¡¡in¡¡Figure¡¡2¡16¡£¡¡The¡¡£û0£ý¡¡construct¡¡in¡¡the¡¡Console¡£WriteLine£¨£©¡¡method¡¡¡¡
is¡¡replaced¡¡by¡¡the¡¡second¡¡argument¡£¡¡If¡¡there¡¡were¡¡a¡¡third¡¡argument£»¡¡it¡¡would¡¡be¡¡placed¡¡in¡¡the¡¡¡¡
resultant¡¡string¡¡with¡¡£û1£ý£»¡¡a¡¡fourth¡¡would¡¡be¡¡replaced¡¡with¡¡£û2£ý£»¡¡and¡¡so¡¡on¡£¡¡
¡¡¡¡¡¡¡¡¡¡As¡¡shown¡¡in¡¡Figure¡¡2¡16£»¡¡if¡¡you¡¡want¡¡to¡¡keep¡¡the¡¡precision¡¡of¡¡adding¡¡a¡¡small¡¡number¡¡to¡¡a¡¡¡¡
large¡¡number£»¡¡you¡¡will¡¡need¡¡to¡¡switch¡¡number¡¡types¡¡to¡¡Double¡£¡¡But¡¡even¡¡Double¡¡has¡¡limits¡¡and¡¡¡¡
can¡¡remember¡¡only¡¡15¡¡to¡¡16¡¡digits¡¡of¡¡precision¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡If¡¡you¡¡want¡¡even¡¡more¡¡precision£»¡¡you¡¡could¡¡use¡¡Decimal£»¡¡but¡¡Decimal¡¡is¡¡more¡¡suitable¡¡for¡¡¡¡
financial¡¡calculations¡£¡¡With¡¡financial¡¡calculations£»¡¡you¡¡will¡¡run¡¡into¡¡the¡¡problem¡¡of¡¡having¡¡very¡¡¡¡
large¡¡numbers¡¡added¡¡to¡¡small¡¡numbers¡£¡¡Imagine¡¡being¡¡Bill¡¡Gates¡¡and¡¡having¡¡a¡¡few¡¡billion¡¡in¡¡¡¡
your¡¡bank¡¡account¡£¡¡When¡¡the¡¡bank¡¡calculates¡¡the¡¡interest£»¡¡you¡¡will¡¡want¡¡to¡¡know¡¡how¡¡many¡¡¡¡
pennies¡¡you¡¡have¡¡accumulated£»¡¡because¡¡pennies£»¡¡when¡¡added¡¡over¡¡a¡¡long¡¡period¡¡of¡¡time£»¡¡make¡¡¡¡
a¡¡big¡¡difference¡£¡¡In¡¡fact£»¡¡some¡¡programmers¡¡have¡¡¡°stolen¡±¡¡money¡¡from¡¡banks¡¡by¡¡collecting¡¡the¡¡¡¡
fractional¡¡pennies¡¡and¡¡accumulating¡¡them¡£¡¡
¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡you¡¯ve¡¡seen¡¡some¡¡of¡¡the¡¡plexities¡¡involved¡¡when¡¡working¡¡with¡¡numbers£»¡¡let¡¯s¡¡¡¡
finish¡¡the¡¡calculator¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡68¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
46¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fractional¡¡number¡¡one¡¡and¡¡a¡¡half¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡AddFractionalNumbersToWhole£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡total¡¡As¡¡Integer¡¡=¡¡CType£¨1¡£5£»¡¡Integer£©¡¡£«¡¡_¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CType£¨1¡£2£»¡¡Integer£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡£¨total¡¡¡¡2¡£7£©¡¡Then¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Oops£»¡¡something¡¡went¡¡wrong¡¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Using¡¡Ctype£¨£©¡¡means¡¡to¡¡cast¡¡a¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡an¡¡Integer¡£¡¡This¡¡results¡¡in¡¡a¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡roundoff¡¡where¡¡1¡£2¡¡=¡¡1¡¡and¡¡1¡£5¡¡=¡¡2¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Had¡¡DirectCast£¨£©¡¡been¡¡used£»¡¡a¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡pilation¡¡error¡¡would¡¡result£»¡¡since¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡converting¡¡a¡¡Double¡¡to¡¡an¡¡Integer¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡requires¡¡coercion¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡2¡15¡£¡¡Adding¡¡fractions¡¡using¡¡the¡¡Integer¡¡data¡¡type¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Declaring¡¡a¡¡number¡¡with¡¡a¡¡decimal¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡A¡¡really¡¡small¡¡number¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡£¨¡£0£©¡¡automatically¡¡creates¡¡a¡¡floating
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡point¡¡value¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡AddFractionalNumbers£¨£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡value¡¡As¡¡Single¡¡=¡¡10000¡£0¡¡£«¡¡0¡£000001¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Value¡¡£¨£û0£ý£©¡¨£»¡¡value£©¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡console¡¡displays¡¡the¡¡number¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡variable¡¡value¡¡is¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡10£»000¡¡because¡¡the¡¡small¡¡number¡¡is¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡addition¡¡of¡¡a¡¡big¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡insignificant¡¡from¡¡the¡¡perspective¡¡of¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡number¡¡to¡¡a¡¡small¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Single¡£¡¡Single¡¡can¡¡remember¡¡only¡¡7¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡number¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡digits¡£¡¡10000¡£000001¡¡is¡¡10¡¡digits¡¡of¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡precision¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡2¡16¡£¡¡Adding¡¡fractions¡¡using¡¡the¡¡Single¡¡data¡¡type¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡69¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡A¡¡PT¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡AN¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡47¡¡
Finishing¡¡the¡¡Calculator¡¡
The¡¡original¡¡declaration¡¡of¡¡the¡¡Add£¨£©¡¡method¡¡for¡¡the¡¡calculator¡¡worked£»¡¡but¡¡had¡¡some¡¡serious¡¡¡¡
limitations¡¡on¡¡what¡¡kinds¡¡of¡¡numbers¡¡could¡¡be¡¡added¡£¡¡To¡¡finish¡¡the¡¡calculator£»¡¡we¡¡need¡¡to¡¡¡¡
declare¡¡the¡¡Add£¨£©¡¡method¡¡using¡¡a¡¡different¡¡type£»¡¡and¡¡then¡¡add¡¡the¡¡remaining¡¡operations¡£¡¡
¡¡¡¡¡¡¡¡¡¡We¡¡could¡¡use¡¡one¡¡of¡¡three¡¡types¡¡to¡¡declare¡¡the¡¡Add£¨£©¡¡method£º¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Long£º¡¡Solves¡¡the¡¡problem¡¡of¡¡adding¡¡two¡¡very¡¡large¡¡numbers¡¡like¡¡2¡¡billion£»¡¡but¡¡has¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡problem¡¡that¡¡you¡¡cannot¡¡add¡¡fractional¡¡numbers¡¡like¡¡1¡£5¡¡plus¡¡1¡£5¡£¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡Double£º¡¡Solves¡¡the¡¡problem¡¡of¡¡adding¡¡two¡¡very¡¡large¡¡or¡¡small¡¡numbers£»¡¡and¡¡can¡¡be¡¡used¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡add¡¡fractional¡¡numbers¡£¡¡Generally¡¡speaking£»¡¡Double¡¡is¡¡a¡¡good¡¡choice£»¡¡but¡¡can¡¡suffer¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡from¡¡significance¡¡problems¡¡if¡¡a¡¡very¡¡large¡¡number¡¡is¡¡manipulated¡¡by¡¡a¡¡very¡¡small¡¡number¡£¡¡
¡¡¡¡¡¡¡¡¡¡o¡¡Decimal£º¡¡A¡¡generally¡¡good¡¡approach¡¡and¡¡suitable¡¡for¡¡all¡¡types¡¡of¡¡precision£»¡¡but¡¡also¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡slowest¡¡when¡¡adding£»¡¡subtracting£»¡¡or¡¡performing¡¡other¡¡mathematical¡¡operations¡£¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡simplest¡¡all¡around¡¡numeric¡¡data¡¡type¡¡to¡¡use¡¡is¡¡Double£»¡¡as¡¡it¡¡provides¡¡good¡¡precision¡¡¡¡
and¡¡is¡¡relatively¡¡fast¡£¡¡The¡¡plete¡¡implementation¡¡of¡¡the¡¡calculator¡¡is¡¡as¡¡follows£º¡¡
Public¡¡Class¡¡Operations¡¡
¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Add£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡
Double£©¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡£«¡¡number2¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Divide£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡
Double£©¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡/¡¡number2¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Multiply£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡
Double£©¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡*¡¡number2¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡Subtract£¨ByVal¡¡number1¡¡As¡¡Double£»¡¡ByVal¡¡number2¡¡As¡¡_¡¡
Double£©¡¡As¡¡Double¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡number1¡¡number2¡¡
¡¡¡¡¡¡¡¡End¡¡Function¡¡
End¡¡Class¡¡
¡¡¡¡¡¡¡¡¡¡The¡¡four¡¡operations¡¡are¡¡methods¡¡with¡¡different¡¡identifiers£»¡¡but¡¡identical¡¡method¡¡signa
tures£»¡¡making¡¡it¡¡easy¡¡to¡¡remember¡¡how¡¡to¡¡use¡¡each¡¡method¡£¡¡Each¡¡of¡¡the¡¡operations¡¡would¡¡have¡¡¡¡
an¡¡appropriate¡¡set¡¡of¡¡tests¡¡verifying¡¡the¡¡correctness¡¡of¡¡the¡¡implementation¡£¡¡The¡¡tests¡¡are¡¡not¡¡¡¡
reproduced¡¡here£»¡¡but¡¡they¡¡are¡¡implemented¡¡in¡¡the¡¡sample¡¡source¡¡code¡£¡¡I¡¡advise¡¡you¡¡to¡¡take¡¡a¡¡¡¡
quick¡¡look¡¡at¡¡the¡¡tests¡¡to¡¡make¡¡sure¡¡you¡¡understand¡¡the¡¡individual¡¡pieces¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Page¡¡70¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
48¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡2¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡N¡¡U¡¡M¡¡B¡¡E¡¡R¡¡¡¡¡¡A¡¡N¡¡D¡¡¡¡¡¡V¡¡A¡¡L¡¡U¡¡E¡¡¡¡¡¡T¡¡Y¡¡P¡¡E¡¡S¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡Important¡¡Stuff¡¡to¡¡Remember¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡this¡¡chapter£»¡¡you¡¡learned¡¡about¡¡developing¡¡a¡¡class¡¡library¡¡that¡¡is¡¡used¡¡to¡¡perform¡¡some¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡calculations¡£¡¡The¡¡following¡¡are¡¡the¡¡key¡¡points¡¡to¡¡remember£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Organization¡¡of¡¡your¡¡thoughts£»¡¡projects£»¡¡and¡¡features¡¡makes¡¡all¡¡the¡¡difference¡¡when¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡writing¡¡software¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡writing¡¡software£»¡¡stay¡¡focused¡£¡¡It¡¡is¡¡very¡¡easy¡¡to¡¡drift¡¡around¡¡in¡¡software¡¡development£»¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡because¡¡software¡¡lets¡¡you¡¡stray¡¡easily¡£¡¡A¡¡successful¡¡developer¡¡will¡¡always¡¡be¡¡organized¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡and¡¡focused¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Software¡¡is¡¡designed¡¡using¡¡an¡¡architecture¡¡that¡¡could¡¡be¡¡implemented¡¡top¡down¡¡or¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bottom¡up¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Within¡¡an¡¡architecture£»¡¡individual¡¡pieces¡¡are¡¡called¡¡ponents£»¡¡and¡¡they¡¡fit¡¡together¡¡to¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡create¡¡a¡¡plete¡¡application¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡You¡¡write¡¡tests¡¡because¡¡you¡¡cannot¡¡verify¡¡the¡¡functionality¡¡of¡¡a¡¡ponent¡¡based¡¡on¡¡its¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡identifier£»¡¡parameters£»¡¡or¡¡return¡¡value¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡implementing¡¡ponents£»¡¡you¡¡develop¡¡tests¡¡before£»¡¡during£»¡¡and¡¡after¡¡writing¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡source¡¡code¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡A¡¡test¡¡is¡¡a¡¡piece¡¡of¡¡source¡¡code¡¡that¡¡calls¡¡a¡¡ponent¡¡using¡¡targeted¡¡input¡¡data£»¡¡and¡¡the¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡results¡¡from¡¡the¡¡ponent¡¡are¡¡verified¡¡with¡¡targeted¡¡responses¡£¡¡If¡¡the¡¡results¡¡do¡¡not¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡match¡¡the¡¡targeted¡¡responses£»¡¡the¡¡ponent¡¡has¡¡failed¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡CLR¡¡offers¡¡many¡¡different¡¡data¡¡types£»¡¡with¡¡the¡¡major¡¡distinction¡¡being¡¡between¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡value¡¡and¡¡reference¡¡types¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡The¡¡CLR¡¡has¡¡many¡¡different¡¡number¡¡types£»¡¡but¡¡all¡¡number¡¡types¡¡are¡¡value¡¡types¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡Numbers¡¡can¡¡overflow¡¡or¡¡underflow¡£¡¡You¡¡should¡¡activate¡¡a¡¡piler¡¡setting¡¡to¡¡make¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡sure¡¡that¡¡the¡¡CLR¡¡will¡¡catch¡¡those¡¡situations¡£¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡o¡¡¡¡When¡¡deciding¡¡on¡¡a¡¡specific¡¡number¡¡type£»¡¡a¡¡large¡¡part¡¡of¡¡the¡¡decision¡¡is¡¡based¡¡on¡¡how¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡much¡¡precision¡¡is¡¡desired¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Some¡¡Things¡¡for¡¡You¡¡to¡¡Do¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡following¡¡are¡¡some¡¡things¡¡to¡¡consider¡¡related¡¡to¡¡what¡¡you¡¯ve¡¡learned¡¡in¡¡this¡¡chapter£º¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡1¡£¡¡When¡¡you¡¡write¡¡code£»¡¡how¡¡should¡¡you¡¡organize¡¡your¡¡code£¿¡¡For¡¡example£»¡¡do¡¡you¡¡enforce¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡certain¡¡naming¡¡conventions¡¡for¡¡your¡¡classes£¿¡¡Do¡¡you¡¡enforce¡¡the¡¡use¡¡of¡¡code¡¡ments£¿¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2¡£¡¡In¡¡the¡¡development¡¡munity£»¡¡there¡¡is¡¡a¡¡discussion¡¡of¡¡whether¡¡organization¡¡of¡¡your¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡software¡¡should¡¡involve¡¡formal¡¡structures¡¡or¡¡should¡¡be¡¡ad¡¡hoc¡£¡¡Think¡¡about¡¡how¡¡software¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡should¡¡be¡¡organized¡£¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡3¡£¡¡In¡¡general£»¡¡how¡¡would¡¡you¡¡test¡¡whether¡¡or¡¡not¡¡a¡¡ponent¡¡that¡¡uses¡¡a¡¡database¡¡worked¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡