Chapter 02 - Primitive Data and Definite Loops

Chapter 02 - Primitive Data and Definite Loops -...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &KDSWHU 3ULPLWLYH 'DWD DQG 'HILQLWH /RRSV &RS\ULJKW E\ 6WXDUW 5HJHV DQG 0DUW\ 6WHSS 7KH IRU /RRS 7UDFLQJ IRU /RRSV SULQW 9HUVXV SULQWOQ 1HVWHG IRU /RRSV 0DQDJLQJ &RPSOH[LW\ 6FRSH 3VHXGRFRGH $ 'HFUHPHQWLQJ IRU /RRS &ODVV &RQVWDQWV &DVH 6WXG\ $ &RPSOH[ )LJXUH 3UREOHP 'HFRPSRVLWLRQ DQG 3VHXGRFRGH /LQH 3DWWHUQ 7DEOH ,QLWLDO 6WUXFWXUHG 9HUVLRQ $GGLQJ D &ODVV &RQVWDQW )XUWKHU 9DULDWLRQV %DVLF 'DWD &RQFHSWV 3ULPLWLYH 7\SHV ([SUHVVLRQV /LWHUDOV $ULWKPHWLF 2SHUDWRUV 3UHFHGHQFH 0L[LQJ 7\SHV DQG &DVWLQJ 9DULDEOHV $VVLJQPHQW 'HFODUDWLRQ 9DULDWLRQV 6WULQJ &RQFDWHQDWLRQ ,QFUHPHQW 'HFUHPHQW 2SHUDWRUV 9DULDEOHV DQG 0L[LQJ 7\SHV ,QWURGXFWLRQ 1RZ WKDW \RX NQRZ VRPHWKLQJ DERXW WKH EDVLF VWUXFWXUH RI -DYD SURJUDPV \RX DUH UHDG\ WR OHDUQ KRZ WR VROYH SUREOHPV WKDW DUH IDLUO\ FRPSOH[ <RX ZLOO VWLOO EH UHVWULFWHG WR SURJUDPV WKDW SURGXFH RXWSXW EXW ZH ZLOO EHJLQ WR H[SORUH VRPH RI WKH DVSHFWV RI SURJUDPPLQJ WKDW UHTXLUH SUREOHP VROYLQJ VNLOOV 7KH ILUVW KDOI RI WKH FKDSWHU ILOOV LQ WZR LPSRUWDQW DUHDV )LUVW LW H[DPLQHV H[SUHVVLRQV KRZ WR H[SUHVV VLPSOH FRPSXWDWLRQV LQ -DYD SDUWLFXODUO\ WKRVH LQYROYLQJ QXPHULF GDWD 6HFRQG LW GLVFXVVHV SURJUDP HOHPHQWV FDOOHG YDULDEOHV WKDW FDQ FKDQJH LQ YDOXH DV WKH SURJUDP H[HFXWHV 7KH VHFRQG KDOI RI WKH FKDSWHU LQWURGXFHV \RXU ILUVW FRQWURO VWUXFWXUH WKH IRU ORRS <RX XVH WKLV VWUXFWXUH WR UHSHDW DFWLRQV LQ D SURJUDP 7KLV LV XVHIXO ZKHQHYHU \RX ILQG D SDWWHUQ LQ D FRPSOH[ WDVN OLNH WKH FUHDWLRQ RI D FRPSOH[ ILJXUH EHFDXVH \RX FDQ XVH D IRU ORRS WR UHSHDW DQ DFWLRQ WKDW FUHDWHV D SDUWLFXODU SDWWHUQ 7KH FKDOOHQJH LV ILQGLQJ HDFK SDWWHUQ DQG ILJXULQJ RXW ZKDW UHSHDWHG DFWLRQV ZLOO UHSURGXFH LW ,Q H[SORULQJ WKLV ZH ZLOO H[DPLQH D YDULDWLRQ RI SULQWOQ NQRZQ DV SULQW WKDW DOORZV XV WR EUHDN XS D FRPSOH[ OLQH RI RXWSXW LQWR VHYHUDO SLHFHV RI RXWSXW 7KH IRU ORRS LV D IOH[LEOH FRQWURO VWUXFWXUH WKDW FDQ EH XVHG IRU PDQ\ WDVNV EXW LQ WKLV FKDSWHU ZH XVH LW IRU GHILQLWH ORRSV ZKHUH \RX NQRZ H[DFWO\ KRZ PDQ\ WLPHV \RX ZDQW WR SHUIRUP D SDUWLFXODU WDVN ,Q &KDSWHU ZH ZLOO GLVFXVV KRZ WR ZULWH LQGHILQLWH ORRSV ZKHUH \RX GRQ W NQRZ LQ DGYDQFH KRZ PDQ\ WLPHV WR SHUIRUP D WDVN 63 %DVLF 'DWD &RQFHSWV 3URJUDPV PDQLSXODWH LQIRUPDWLRQ DQG LQIRUPDWLRQ FRPHV LQ PDQ\ IRUPV -DYD LV D VWURQJO\ W\SHG ODQJXDJH ZKLFK PHDQV WKDW -DYD UHTXLUHV XV WR EH H[SOLFLW DERXW ZKDW NLQG RI LQIRUPDWLRQ ZH LQWHQG WR PDQLSXODWH (YHU\WKLQJ WKDW ZH PDQLSXODWH LQ D -DYD SURJUDP ZLOO EH RI D FHUWDLQ W\SH DQG ZH ZLOO FRQVWDQWO\ ILQG RXUVHOYHV WHOOLQJ -DYD ZKDW W\SHV RI GDWD ZH LQWHQG WR XVH $ GHFLVLRQ ZDV PDGH HDUO\ LQ WKH GHVLJQ RI -DYD WR KDYH WZR GLIIHUHQW NLQGV RI GDWD SULPLWLYH GDWD DQG REMHFWV 7KH GHVLJQHUV DGPLW WKDW WKLV GHFLVLRQ ZDV PDGH SXUHO\ RQ WKH EDVLV RI SHUIRUPDQFH WR PDNH -DYD SURJUDPV UXQ IDVWHU 7KHLU GHFLVLRQ LV XQIRUWXQDWH EHFDXVH LW PHDQV WKDW ZH KDYH WR OHDUQ WZR VHWV RI UXOHV DERXW KRZ GDWD ZRUNV %XW WKLV LV RQH RI WKRVH WLPHV ZKHQ \RX VLPSO\ KDYH WR SD\ WKH SULFH LI \RX ZDQW WR XVH DQ LQGXVWULDO VWUHQJWK SURJUDPPLQJ ODQJXDJH 7R PDNH RXU OLYHV D OLWWOH HDVLHU ZH ZLOO VWXG\ WKH SULPLWLYH GDWD W\SHV ILUVW LQ WKLV FKDSWHU DQG WKHQ WXUQ RXU DWWHQWLRQ WR REMHFWV LQ WKH QH[W FKDSWHU 3ULPLWLYH 7\SHV 7KHUH DUH HLJKW SULPLWLYH GDWD W\SHV LQ -DYD RI ZKLFK IRXU DUH FRQVLGHUHG IXQGDPHQWDO 7KH RWKHU IRXU W\SHV DUH YDULDWLRQV WKDW H[LVW IRU SURJUDPV WKDW KDYH VSHFLDO UHTXLUHPHQWV 7KH IRXU W\SHV ZH ZLOO H[SORUH DUH OLVWHG LQ WKH IROORZLQJ WDEOH &RPPRQO\ 8VHG 3ULPLWLYH 7\SHV LQ -DYD 7\SH int double 'HVFULSWLRQ ([DPSOHV LQWHJHUV ZKROH QXPEHUV 42 -3 18 20493 0 7.35 14.9 -19.83423 UHDO QXPEHUV char 'a' 'X' '!' VLQJOH FKDUDFWHUV boolean true false ORJLFDO YDOXHV 7KH W\SH QDPHV LQW GRXEOH FKDU DQG ERROHDQ DUH -DYD NH\ZRUGV WKDW ZH ZLOO XVH LQ RXU SURJUDPV WR OHW WKH FRPSLOHU NQRZ WKDW ZH LQWHQG WR XVH WKDW W\SH RI GDWD ,W PD\ VHHP RGG WR KDYH RQH W\SH IRU LQWHJHUV DQG DQRWKHU W\SH IRU UHDO QXPEHUV ,VQ W HYHU\ LQWHJHU D UHDO QXPEHU" 7KH DQVZHU LV \HV EXW WKHVH DUH IXQGDPHQWDOO\ GLIIHUHQW W\SHV RI QXPEHUV 7KH GLIIHUHQFH LV VR JUHDW WKDW ZH PDNH WKLV GLVWLQFWLRQ HYHQ LQ (QJOLVK :H GRQ W DVN +RZ PXFK VLVWHUV GR \RX KDYH" RU +RZ PDQ\ GR \RX ZHLJK" :H UHDOL]H WKDW VLVWHUV FRPH LQ GLVFUHWH LQWHJHU TXDQWLWLHV VLVWHUV VLVWHU VLVWHUV VLVWHUV DQG VR RQ DQG ZH XVH WKH ZRUG PDQ\ IRU LQWHJHU TXDQWLWLHV +RZ PDQ\ VLVWHUV GR \RX KDYH" 6LPLODUO\ ZH UHDOL]H WKDW ZHLJKW FDQ YDU\ E\ WLQ\ DPRXQWV SRXQGV YHUVXV SRXQGV YHUVXV SRXQGV DQG VR RQ DQG ZH XVH WKH ZRUG PXFK IRU WKHVH UHDO YDOXHG TXDQWLWLHV +RZ PXFK GR \RX ZHLJK" ,Q SURJUDPPLQJ WKLV GLVWLQFWLRQ LV HYHQ PRUH LPSRUWDQW EHFDXVH LQWHJHUV DQG UHDOV DUH UHSUHVHQWHG LQ D GLIIHUHQW ZD\ LQ WKH FRPSXWHU V PHPRU\ ,QWHJHUV DUH VWRUHG H[DFWO\ ZKLOH UHDOV DUH VWRUHG DV DSSUR[LPDWLRQV ZLWK D OLPLWHG QXPEHU RI GLJLWV RI DFFXUDF\ :H ZLOO VHH WKDW VWRULQJ YDOXHV DV DSSUR[LPDWLRQV FDQ OHDG WR URXQG RII HUURUV ZKHQ \RX XVH UHDO YDOXHV 64 7KH QDPH GRXEOH IRU UHDO YDOXHV LVQ W YHU\ FOHDU ,W V DQ DFFLGHQW RI KLVWRU\ WKDW ZH KDYH WKLV QDPH LQ PXFK WKH VDPH ZD\ WKDW ZH VWLOO WDON DERXW GLDOLQJ D QXPEHU RQ RXU WHOHSKRQHV HYHQ WKRXJK PRGHUQ WHOHSKRQHV GRQ W KDYH D GLDO 7KH & SURJUDPPLQJ ODQJXDJH LQWURGXFHG D W\SH FDOOHG IORDW IRU VWRULQJ UHDO QXPEHUV VKRUW IRU IORDWLQJ SRLQW QXPEHU %XW IORDWV KDG OLPLWHG DFFXUDF\ DQG DQRWKHU W\SH ZDV LQWURGXFHG FDOOHG GRXEOH VKRUW IRU GRXEOH SUHFLVLRQ GRXEOH WKH SUHFLVLRQ RI D VLPSOH IORDW $V PHPRU\ KDV EHFRPH FKHDSHU SHRSOH KDYH PRYHG PRUH WRZDUGV XVLQJ GRXEOH DV WKH GHIDXOW IRU IORDWLQJ SRLQW YDOXHV ,Q KLQGVLJKW LW PLJKW KDYH EHHQ EHWWHU WR XVH WKH ZRUG IORDW IRU ZKDW LV QRZ FDOOHG GRXEOH DQG WKHQ XVHG D ZRUG OLNH KDOI IRU WKH YDOXHV ZLWK OHVV DFFXUDF\ EXW LW V WRXJK WR FKDQJH KDELWV WKDW DUH VR LQJUDLQHG 6R SURJUDPPLQJ ODQJXDJHV ZLOO FRQWLQXH WR XVH WKH ZRUG GRXEOH IRU IORDWLQJ SRLQW QXPEHUV DQG SHRSOH ZLOO VWLOO WDON DERXW GLDOLQJ SHRSOH RQ WKH SKRQH HYHQ LI WKH\ YH QHYHU WRXFKHG D WHOHSKRQH GLDO ([SUHVVLRQV :KHQ ZULWLQJ SURJUDPV ZH ZLOO RIWHQ QHHG WR LQFOXGH YDOXHV DQG FDOFXODWLRQV 7KH WHFKQLFDO WHUP IRU WKHVH LV H[SUHVVLRQV ([SUHVVLRQ $ VLPSOH YDOXH RU D VHW RI RSHUDWLRQV WKDW SURGXFHV D YDOXH 7KH VLPSOHVW H[SUHVVLRQ LV D VSHFLILF YDOXH OLNH RU :H FDOO WKHVH OLWHUDO YDOXHV RU OLWHUDOV 0RUH FRPSOH[ H[SUHVVLRQV LQYROYH FRPELQLQJ VLPSOH YDOXHV 6XSSRVH IRU H[DPSOH WKDW \RX ZDQW WR NQRZ KRZ PDQ\ ERWWOHV RI ZDWHU \RX KDYH ,I \RX KDYH WZR SDFNV IRXU SDFNV DQG LQGLYLGXDO ERWWOHV WKHQ \RX FRXOG FRPSXWH WKH WRWDO QXPEHU RI ERWWOHV ZLWK WKH IROORZLQJ H[SUHVVLRQ (2 * 6) + (4 * 4) + 2 1RWLFH WKDW ZH XVH WKH DVWHULVN WR UHSUHVHQW PXOWLSOLFDWLRQ DQG WKDW ZH XVH SDUHQWKHVHV WR JURXS SDUWV RI WKH H[SUHVVLRQ 7KH FRPSXWHU GHWHUPLQHV WKH YDOXH RI DQ H[SUHVVLRQ E\ HYDOXDWLQJ LW (YDOXDWLRQ 7KH SURFHVV RI REWDLQLQJ WKH YDOXH RI DQ H[SUHVVLRQ 7KH YDOXH REWDLQHG ZKHQ DQ H[SUHVVLRQ LV HYDOXDWHG LV FDOOHG WKH UHVXOW &RPSOH[ H[SUHVVLRQV DUH IRUPHG XVLQJ RSHUDWRUV 2SHUDWRU $ VSHFLDO V\PERO OLNH + RU * XVHG WR LQGLFDWH DQ RSHUDWLRQ WR EH SHUIRUPHG RQ RQH RU PRUH YDOXHV 7KH YDOXHV XVHG LQ WKH H[SUHVVLRQ DUH FDOOHG RSHUDQGV )RU H[DPSOH FRQVLGHU WKH IROORZLQJ VLPSOH H[SUHVVLRQV 65 3 + 29 4 * 5 7KH RSHUDWRUV KHUH DUH WKH + DQG * DQG WKH RSHUDQGV DUH VLPSOH QXPEHUV 3 | operand 4 | operand + | operator * | operator 29 | operand 5 | operand :KHQ \RX IRUP FRPSOH[ H[SUHVVLRQV WKHVH VLPSOHU H[SUHVVLRQV FDQ LQ WXUQ EHFRPH RSHUDQGV IRU RWKHU RSHUDWRUV )RU H[DPSOH FRQVLGHU WKH IROORZLQJ H[SUHVVLRQ (3 + 29) - (4 * 5) :KLFK KDV WZR OHYHOV RI RSHUDWRUV (3 + 29) (4 * 5) | | | | | | | operand operator operand | operand operator operand | | | | | +------------------+ | +------------------+ operand operator operand 7KH SOXV RSHUDWRU KDV VLPSOH RSHUDQGV RI DQG DQG WKH WLPHV RSHUDWRU KDV VLPSOH RSHUDQGV RI DQG EXW WKH PLQXV RSHUDWRU KDV RSHUDQGV WKDW DUH HDFK SDUHQWKHVL]HG H[SUHVVLRQV ZLWK RSHUDWRUV RI WKHLU RZQ 7KXV FRPSOH[ H[SUHVVLRQV FDQ EH EXLOW IURP VPDOOHU H[SUHVVLRQV $W WKH ORZHVW OHYHO \RX KDYH VLPSOH QXPEHUV 7KHVH DUH XVHG DV RSHUDQGV WR PDNH PRUH FRPSOH[ H[SUHVVLRQV ZKLFK LQ WXUQ FDQ EH XVHG DV RSHUDQGV LQ HYHQ PRUH FRPSOH[ H[SUHVVLRQV 7KHUH DUH PDQ\ WKLQJV \RX FDQ GR ZLWK H[SUHVVLRQV 2QH RI WKH VLPSOHVW WKLQJV \RX FDQ GR LV WR SULQW WKH YDOXH RI DQ H[SUHVVLRQ XVLQJ D SULQWOQ VWDWHPHQW )RU H[DPSOH LI \RX VD\ System.out.println(42); System.out.println(2 + 2); \RX ZLOO JHW WKH IROORZLQJ WZR OLQHV RI RXWSXW 42 4 1RWLFH WKDW IRU WKH VHFRQG SULQWOQ WKH FRPSXWHU HYDOXDWHV WKH H[SUHVVLRQ DGGLQJ SULQWV WKH UHVXOW LQ WKLV FDVH DQG DQG <RX ZLOO VHH PDQ\ GLIIHUHQW RSHUDWRUV DV \RX SURJUHVV WKURXJK WKH ERRN DOO RI ZKLFK FDQ EH XVHG WR IRUP H[SUHVVLRQV ([SUHVVLRQV FDQ EH DUELWUDULO\ FRPSOH[ ZLWK DV PDQ\ RSHUDWRUV DV \RX OLNH )RU WKDW UHDVRQ ZKHQ ZH WHOO \RX $Q H[SUHVVLRQ FDQ EH XVHG KHUH ZH ZLOO RIWHQ SRLQW RXW WKDW ZH PHDQ DUELWUDU\ H[SUHVVLRQV WR HPSKDVL]H WKDW \RX FDQ XVH FRPSOH[ H[SUHVVLRQV DV ZHOO DV VLPSOH YDOXHV 66 /LWHUDOV 7KH VLPSOHVW H[SUHVVLRQV UHIHU WR YDOXHV GLUHFWO\ XVLQJ ZKDW DUH NQRZQ DV OLWHUDOV $Q LQWHJHU OLWHUDO FRQVLGHUHG WR EH RI W\SH LQW LV D VHTXHQFH RI GLJLWV ZLWK RU ZLWKRXW D OHDGLQJ VLJQ 3 482 -29434 0 92348 +9812 $ IORDWLQJ SRLQW OLWHUDO FRQVLGHUHG WR EH RI W\SH GRXEOH ZLOO LQFOXGH D GHFLPDO SRLQW DV LQ 298.4 0.284 207. .2843 -17.452 -.98 1RWLFH WKDW 207. LV FRQVLGHUHG D GRXEOH HYHQ WKRXJK LW FRLQFLGHV ZLWK DQ LQWHJHU EHFDXVH RI WKH GHFLPDO SRLQW /LWHUDOV RI W\SH GRXEOH FDQ DOVR EH H[SUHVVHG LQ VFLHQWLILF QRWDWLRQ D QXPEHU IROORZHG E\ e IROORZHG E\ DQ LQWHJHU DV LQ 2.3e4 1e-5 3.84e92 2.458e12 7KH ILUVW QXPEHU DERYH UHSUHVHQWV WLPHV WR WKH WK SRZHU ZKLFK HTXDOV WKRXVDQG (YHQ WKRXJK WKLV KDSSHQV WR FRLQFLGH ZLWK DQ LQWHJHU LW LV FRQVLGHUHG WR EH D YDOXH RI W\SH GRXEOH EHFDXVH LW LV H[SUHVVHG LQ VFLHQWLILF QRWDWLRQ 7KH VHFRQG QXPEHU UHSUHVHQWV WLPHV WR WKH SRZHU ZKLFK LV HTXDO WR 7KH WKLUG YDOXH UHSUHVHQWV WLPHV WR WKH QG SRZHU 7KH IRXUWK UHSUHVHQWV WLPHV WR WKH WK SRZHU &KDUDFWHU OLWHUDOV RI W\SH FKDU DUH HQFORVHG LQ VLQJOH TXRWDWLRQ PDUNV DQG FDQ LQFOXGH MXVW RQH FKDUDFWHU 'a' 'm' 'X' '!' '3' '\\' $OO RI WKHVH DUH RI W\SH FKDU 1RWLFH WKDW WKH ODVW H[DPSOH XVHV DQ HVFDSH VHTXHQFH WR UHSUHVHQW WKH EDFNVODVK FKDUDFWHU <RX FDQ HYHQ UHIHU WR WKH VLQJOH TXRWDWLRQ FKDUDFWHU XVLQJ DQ HVFDSH VHTXHQFH '\'' 5HPHPEHU WKDW WKH SULPLWLYH W\SH ERROHDQ VWRUHV ORJLFDO LQIRUPDWLRQ /RJLF GHDOV ZLWK MXVW WZR SRVVLELOLWLHV WUXH DQG IDOVH 7KHVH WZR ZRUGV DUH NH\ZRUGV LQ -DYD WKDW DUH WKH WZR OLWHUDO YDOXHV RI W\SH ERROHDQ true false $ULWKPHWLF 2SHUDWRUV 7KH EDVLF DULWKPHWLF RSHUDWRUV DUH DV IROORZV 67 $ULWKPHWLF 2SHUDWRUV LQ -DYD 2SHUDWRU 0HDQLQJ DGGLWLRQ VXEWUDFWLRQ PXOWLSOLFDWLRQ GLYLVLRQ UHPDLQGHU RU PRG 7KH DGGLWLRQ DQG VXEWUDFWLRQ RSHUDWRUV VKRXOG EH IDPLOLDU WR \RX 7KH DVWHULVN DV D PXOWLSOLFDWLRQ RSHUDWRU PLJKW EH D VXUSULVH IRU QRQSURJUDPPHUV EXW GRHVQ W WDNH ORQJ WR JHW XVHG WR 'LYLVLRQ LV DOVR IDLUO\ IDPLOLDU DOWKRXJK DV ZH OO VHH -DYD KDV WZR GLIIHUHQW GLYLVLRQ RSHUDWLRQV 7KH UHPDLQGHU RU PRG RSHUDWLRQ LV WKH RQH WKDW LV PRVW OLNHO\ WR EH XQIDPLOLDU WR \RX 'LYLVLRQ SUHVHQWV D SUREOHP ZKHQ WKH RSHUDQGV DUH LQWHJHUV :KHQ \RX GLYLGH E\ IRU H[DPSOH \RX GR QRW JHW DQ LQWHJHU UHVXOW 7KHUHIRUH LQWHJHU GLYLVLRQ LV H[SUHVVHG DV WZR GLIIHUHQW LQWHJHUV D TXRWLHQW DQG D UHPDLQGHU 119 --5 = 23 (quotient) with 4 (remainder) ([DPSOH 5HVXOW ,Q WHUPV RI WKH DULWKPHWLF RSHUDWRUV 119 / 5 evaluates to 23 119 % 5 evaluates to 4 /RQJ GLYLVLRQ FDOFXODWLRQV DUH SHUIRUPHG OLNH WKLV 31 _______ 34 ) 1079 102 ---59 34 -25 +HUH GLYLGLQJ E\ \LHOGV ZRXOG EH GHVFULEHG OLNH WKLV 1079 / 34 evaluates to 31 1079 % 34 evaluates to 25 ZLWK D UHPDLQGHU RI 8VLQJ DULWKPHWLF RSHUDWRUV WKH SUREOHP ,W WDNHV D ZKLOH WR JHW XVHG WR LQWHJHU GLYLVLRQ )RU WKH GLYLVLRQ RSHUDWRU / WKH NH\ WKLQJ WR NHHS LQ PLQG LV WKDW LW WUXQFDWHV DQ\WKLQJ DIWHU WKH GHFLPDO SRLQW 6R LI \RX LPDJLQH FRPSXWLQJ DQ DQVZHU RQ D FDOFXODWRU MXVW WKLQN RI LJQRULQJ DQ\WKLQJ DIWHU WKH GHFLPDO SRLQW 19 / 5 is 3.8 on a calculator, so 19 / 5 evaluates to 3 207 / 10 is 20.7 on a calculator, so 203 / 10 evaluates to 20 3 / 8 is 0.375 on a calculator, so 3 / 8 evaluates to 0 68 7KH UHPDLQGHU RSHUDWRU LV XVXDOO\ UHIHUUHG WR DV WKH PRG RSHUDWRU RU VLPSO\ PRG 7KH PRG RSHUDWRU OHWV \RX NQRZ KRZ PXFK ZDV OHIW XQDFFRXQWHG IRU E\ WKH WUXQFDWHG GLYLVLRQ RSHUDWRU <RX KDYH WR WKLQN LQ WHUPV RI ZKDW WKH WUXQFDWHG GLYLVLRQ RSHUDWRU JLYHV DV D UHVXOW DQG WKHQ \RX FDQ GHWHUPLQH ZKDW LV OHIW RYHU )RU H[DPSOH JLYHQ WKH H[DPSOHV DERYH ZH G FRPSXWH WKH PRG UHVXOWV DV IROORZV Mod First What does division How much is Problem divide account for? left over? Answer? -----------------------------------------------------------------------19 % 5 19 / 5 is 3 3 * 5 is 15 19 - 15 is 4 4 207 % 10 207 / 10 is 20 20 * 10 is 200 207 - 200 is 7 7 3 % 8 3 / 8 is 0 0 * 8 is 0 3 - 0 is 3 3 ,Q HDFK FDVH ZH ILJXUH RXW KRZ PXFK RI WKH QXPEHU LV DFFRXQWHG IRU E\ WKH WUXQFDWHG GLYLVLRQ RSHUDWRU 7KH PRG RSHUDWRU JLYHV \RX DQ\ H[FHVV WKH UHPDLQGHU 3XWWLQJ WKH WDEOH DERYH LQWR D IRUPXOD \RX FDQ WKLQN RI WKH PRG RSHUDWRU DV EHKDYLQJ DV IROORZV x % y = x - (x / y) * y <RX FDQ JHW D UHVXOW RI IRU WKH PRG RSHUDWRU 7KLV KDSSHQV ZKHQ RQH QXPEHU JRHV HYHQO\ LQWR DQRWKHU )RU H[DPSOH HDFK RI WKH IROORZLQJ H[SUHVVLRQV HYDOXDWHV WR EHFDXVH WKH VHFRQG QXPEHU JRHV HYHQO\ LQWR WKH ILUVW QXPEHU 28 % 7 95 % 5 44 % 2 7KH PRG RSHUDWRU KDV PDQ\ XVHIXO DSSOLFDWLRQV LQ FRPSXWHU SURJUDPV +HUH DUH MXVW D IHZ LGHDV WHVWLQJ ZKHWKHU D QXPEHU LV HYHQ RU RGG QXPEHU LV IRU HYHQV QXPEHU ILQGLQJ LQGLYLGXDO GLJLWV RI D QXPEHU H J QXPEHU LV WKH ILQDO GLJLW ILQGLQJ WKH ODVW IRXU GLJLWV RI D VRFLDO VHFXULW\ QXPEHU QXPEHU LV IRU RGGV )RU IORDWLQJ SRLQW YDOXHV YDOXHV RI W\SH GRXEOH WKH GLYLVLRQ RSHUDWRU GRHV ZKDW ZH FRQVLGHU QRUPDO GLYLVLRQ 6R HYHQ WKRXJK WKH H[SUHVVLRQ HYDOXDWHV WR WKH H[SUHVVLRQ HYDOXDWHV WR 7KH UHPDLQGHU RSHUDWRU FDQ EH XVHG ZLWK GRXEOHV DV ZHOO DV ZLWK LQWV DQG LW KDV D VLPLODU PHDQLQJ <RX FRQVLGHU KRZ PXFK LV OHIW RYHU ZKHQ \RX WDNH DZD\ DV PDQ\ ZKROH YDOXHV DV \RX FDQ )RU H[DPSOH WKH H[SUHVVLRQ HYDOXDWHV WR EHFDXVH \RX FDQ WDNH DZD\ IRXU V IURP OHDYLQJ \RX ZLWK OHIW RYHU 3UHFHGHQFH -DYD H[SUHVVLRQV DUH OLNH FRPSOH[ QRXQ SKUDVHV LQ (QJOLVK 6XFK SKUDVHV DUH VXEMHFW WR DPELJXLW\ DV LQ WKH PDQ RQ WKH KLOO E\ WKH ULYHU ZLWK WKH WHOHVFRSH ,V WKH ULYHU E\ WKH KLOO RU E\ WKH PDQ" ,V WKH PDQ KROGLQJ WKH WHOHVFRSH RU LV WKH WHOHVFRSH RQ WKH KLOO RU LV WKH WHOHVFRSH LQ WKH ULYHU" <RX GRQ W NQRZ KRZ WR JURXS WKH YDULRXV SDUWV WRJHWKHU <RX FDQ JHW WKH VDPH NLQG RI DPELJXLW\ LI SDUHQWKHVHV DUHQ W XVHG WR JURXS WKH SDUWV RI D -DYD H[SUHVVLRQ )RU H[DPSOH WKH H[SUHVVLRQ KDV WZR RSHUDWRUV :KLFK LV SHUIRUPHG ILUVW" <RX FRXOG LQWHUSUHW WKLV WZR ZD\V 69 2 + 3 * 4 \---/ 5 * 4 \-----/ 20 2 + 3 * 4 \---/ 2 + 12 \-----/ 14 7KH ILUVW RI WKHVH HYDOXDWHV WR ZKLOH WKH VHFRQG HYDOXDWHV WR 7R GHDO ZLWK WKH DPELJXLW\ -DYD KDV UXOHV RI SUHFHGHQFH WKDW GHWHUPLQH KRZ WR JURXS WKH YDULRXV SDUWV WRJHWKHU 3UHFHGHQFH 7KH ELQGLQJ SRZHU RI DQ RSHUDWRU ZKLFK GHWHUPLQHV KRZ WR JURXS SDUWV RI DQ H[SUHVVLRQ 5XOHV RI SUHFHGHQFH DUH DSSOLHG ZKHQ WKH JURXSLQJ RI RSHUDWRUV LQ DQ H[SUHVVLRQ LV DPELJXRXV $Q RSHUDWRU ZLWK ORZ SUHFHGHQFH LV HYDOXDWHG DIWHU RSHUDWRUV RI KLJKHU SUHFHGHQFH :LWKLQ D JLYHQ OHYHO RI SUHFHGHQFH WKH RSHUDWRUV DUH HYDOXDWHG LQ RQH GLUHFWLRQ XVXDOO\ OHIW WR ULJKW )RU DULWKPHWLF H[SUHVVLRQV WKHUH DUH WZR OHYHOV RI SUHFHGHQFH 7KH PXOWLSOLFDWLYH RSHUDWRUV KDYH D KLJKHU OHYHO RI SUHFHGHQFH WKDQ WKH DGGLWLYH RSHUDWRUV 6R WKH H[SUHVVLRQ LQWHUSUHWHG DV 2 + 3 * 4 \---/ 2 + 12 \-----/ 14 LV :LWKLQ WKH VDPH OHYHO RI SUHFHGHQFH DULWKPHWLF RSHUDWRUV DUH HYDOXDWHG IURP OHIW WR ULJKW 7KLV RIWHQ GRHVQ W PDNH D GLIIHUHQFH LQ WKH ILQDO UHVXOW EXW RFFDVLRQDOO\ LW GRHV &RQVLGHU IRU H[DPSOH WKH H[SUHVVLRQ 40 - 25 - 9 ZKLFK HYDOXDWHV DV IROORZV 40 - 25 - 9 \-----/ 15 - 9 \-------/ 6 <RX ZRXOG JHW D GLIIHUHQW UHVXOW LI WKH VHFRQG PLQXV ZHUH HYDOXDWHG ILUVW <RX FDQ DOZD\V RYHUULGH SUHFHGHQFH ZLWK SDUHQWKHVHV )RU H[DPSOH LI \RX UHDOO\ ZDQW WKH VHFRQG PLQXV WR EH HYDOXDWHG ILUVW \RX FDQ IRUFH WKDW WR KDSSHQ E\ LQWURGXFLQJ SDUHQWKHVHV 40 - (25 - 9) ZKLFK HYDOXDWHV DV IROORZV 70 40 - (25 - 9) \------/ 40 16 \--------/ 24 :LWK DULWKPHWLF ZH DOVR KDYH ZKDW DUH NQRZQ DV XQDU\ SOXV DQG PLQXV ZLWK D VLQJOH RSHUDQG )RU H[DPSOH ZH FDQ ILQG WKH QHJDWLRQ RI E\ DVNLQJ IRU -8 7KHVH XQDU\ RSHUDWRUV KDYH D KLJKHU OHYHO RI SUHFHGHQFH ZKLFK DOORZV \RX WR IRUP H[SUHVVLRQV OLNH WKH IROORZLQJ 12 * -8 ZKLFK HYDOXDWHV WR :H ZLOO VHH PDQ\ RSHUDWRUV LQ WKH QH[W IHZ FKDSWHUV 7KH IROORZLQJ LV D SUHFHGHQFH WDEOH WKDW KDV WKH DULWKPHWLF RSHUDWRUV $V ZH OHDUQ DERXW PRUH RSHUDWRUV ZH OO XSGDWH WKLV WDEOH WR LQFOXGH WKHP DV ZHOO 7KH WDEOH LV RUGHUHG IURP KLJKHVW SUHFHGHQFH WR ORZHVW SUHFHGHQFH )RU H[DPSOH WKH WDEOH LQGLFDWHV WKDW -DYD ZLOO ILUVW JURXS SDUWV RI DQ H[SUHVVLRQ XVLQJ WKH XQDU\ RSHUDWRUV WKHQ LW ZLOO JURXS XVLQJ WKH PXOWLSOLFDWLYH RSHUDWRUV DQG RQO\ WKHQ ZLOO LW JURXS XVLQJ WKH DGGLWLYH RSHUDWRUV -DYD 2SHUDWRU 3UHFHGHQFH 'HVFULSWLRQ 2SHUDWRUV +, XQDU\ RSHUDWRUV PXOWLSOLFDWLYH RSHUDWRUV *, /, % +, DGGLWLYH RSHUDWRUV %HIRUH ZH OHDYH WKLV WRSLF OHW V ORRN DW D FRPSOH[ H[SUHVVLRQ DQG VHH KRZ LW LV HYDOXDWHG VWHS E\ VWHS &RQVLGHU WKH IROORZLQJ H[SUHVVLRQ 13 * 2 - 209 / 10 % 5 + 2 * 2 ,W KDV D WRWDO RI VL[ RSHUDWRUV WZR PXOWLSOLFDWLRQV RQH GLYLVLRQ RQH PRG RQH VXEWUDFWLRQ DQG RQH DGGLWLRQ 7KH PXOWLSOLFDWLRQV GLYLVLRQ DQG PRG ZLOO EH SHUIRUPHG ILUVW EHFDXVH WKH\ KDYH KLJKHU SUHFHGHQFH DQG WKH\ ZLOO EH SHUIRUPHG IURP OHIW WR ULJKW RUGHU EHFDXVH WKH\ DUH DOO DW WKH VDPH OHYHO RI SUHFHGHQFH 13 * 2 + 239 / 10 % 5 \----/ 26 + 239 / 10 % 5 \------/ 26 + 23 % 5 \-------/ 26 + 3 26 + 3 - 2 * 2 - 2 * 2 - 2 * 2 - 2 * 2 \---/ 4 1RZ ZH HYDOXDWH WKH DGGLWLYH RSHUDWRUV IURP OHIW WR ULJKW 71 26 + 3 4 \-------------/ 29 4 \-----------------/ 25 0L[LQJ 7\SHV DQG &DVWLQJ :H RIWHQ ILQG RXUVHOYHV PL[LQJ YDOXHV RI GLIIHUHQW W\SHV DQG ZDQWLQJ WR FRQYHUW IURP RQH W\SH WR DQRWKHU -DYD KDV VLPSOH UXOHV WKDW DYRLG FRQIXVLRQ DQG SURYLGHV D PHFKDQLVP IRU UHTXHVWLQJ WKDW D YDOXH EH FRQYHUWHG IURP RQH W\SH WR DQRWKHU :H RIWHQ ILQG RXUVHOYHV PL[LQJ LQWV DQG GRXEOHV :H PLJKW IRU H[DPSOH DVN -DYD WR FRPSXWH 7KLV H[SUHVVLRQ LQFOXGHV WKH LQW OLWHUDO DQG WKH GRXEOH OLWHUDO ,Q WKLV FDVH -DYD FRQYHUWV WKH LQW LQWR D GRXEOH DQG SHUIRUPV WKLV FRPSXWDWLRQ HQWLUHO\ ZLWK GRXEOH YDOXHV ,I -DYD HQFRXQWHUV DQ LQW ZKHUH LW ZDV H[SHFWLQJ D GRXEOH LW DOZD\V FRQYHUWV WKH LQW WR D GRXEOH 7KLV EHFRPHV SDUWLFXODUO\ LPSRUWDQW ZKHQ \RX IRUP H[SUHVVLRQV WKDW LQYROYH GLYLVLRQ ,I WKH WZR RSHUDQGV DUH ERWK RI W\SH LQW WKHQ -DYD ZLOO XVH LQWHJHU WUXQFDWHG GLYLVLRQ ,I HLWKHU RI WKH WZR RSHUDQGV LV RI W\SH GRXEOH KRZHYHU WKHQ LW ZLOO GR UHDO YDOXHG QRUPDO GLYLVLRQ )RU H[DPSOH HYDOXDWHV WR EXW DOO RI WKH IROORZLQJ HYDOXDWH WR 23.0 / 4 23. / 4 23 / 4.0 23 / 4. 23. / 4. 23.0 / 4.0 6RPHWLPHV \RX ZDQW -DYD WR JR WKH RWKHU ZD\ FRQYHUWLQJ D GRXEOH LQWR DQ LQW <RX FDQ DVN -DYD IRU WKLV FRQYHUVLRQ ZLWK D FDVW 7KLQN RI LW DV FDVWLQJ D YDOXH LQ D GLIIHUHQW OLJKW <RX UHTXHVW D FDVW E\ SXWWLQJ WKH QDPH RI WKH W\SH \RX ZDQW WR FDVW WR LQ SDUHQWKHVHV LQ IURQW RI WKH WKLQJ \RX ZDQW WR FDVW )RU H[DPSOH LI \RX VD\ (int) 4.75 \RX ZLOO JHW WKH LQW YDOXH :KHQ \RX FDVW D GRXEOH YDOXH WR DQ LQW LW VLPSO\ WUXQFDWHV DQ\WKLQJ DIWHU WKH GHFLPDO SRLQW ,I \RX ZDQW WR FDVW WKH UHVXOW RI DQ H[SUHVVLRQ \RX KDYH WR EH FDUHIXO WR XVH SDUHQWKHVHV )RU H[DPSOH VXSSRVH WKDW \RX KDYH VRPH ERRNV WKDW DUH IHHW ZLGH DQG \RX ZDQW WR NQRZ KRZ PDQ\ RI WKHP ZRXOG ILW LQ D ERRNVKHOI WKDW LV IHHW ZLGH <RX FRXOG GR D VWUDLJKW GLYLVLRQ RI EXW WKDW HYDOXDWHV WR D GRXEOH UHVXOW WKDW LV EHWZHHQ DQG $PHULFDQV XVH WKH SKUDVH DQG FKDQJH DV D ZD\ WR H[SUHVV WKH LGHD WKDW LW LV ODUJHU WKDQ EXW QRW DV ELJ DV ,Q WKLV FDVH ZH GRQ W FDUH DERXW WKH FKDQJH :H ZDQW WR FRPSXWH WKH SDUW <RX PLJKW IRUP WKH IROORZLQJ H[SUHVVLRQ (int) 2.5 / 0.15 8QIRUWXQDWHO\ WKLV H[SUHVVLRQ HYDOXDWHV WR WKH ZURQJ DQVZHU EHFDXVH WKH FDVW LV DSSOLHG WR ZKDWHYHU FRPHV ULJKW DIWHU LW ZKLFK LV WKH YDOXH 6R WKLV FDVWV LQWR WKH LQWHJHU GLYLGHV E\ DQG HYDOXDWHV WR DQG FKDQJH ZKLFK LVQ W DQ LQWHJHU DQG LVQ W WKH ULJKW DQVZHU <RX ZDQW WR IRUP W...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern