Introducere in c++

download Introducere in c++

of 170

  • date post

    14-Nov-2014
  • Category

    Documents

  • view

    13
  • download

    6

Embed Size (px)

Transcript of Introducere in c++

Introducere in programare

&$3,72/8/ ,QWURGXFHUH

Introducere in programare

&DOFXODWRDUHOH HOHFWURQLFH DX DSUXW vQ MXUXO DQXOXL 7RWXL XQHOH PDLQL mecanice de calculat au fost propuse anterior: 3DVFDOUHDOL]DQXPDLDGXQDUHLVFGHUH /HLEQLW]UHDOL]DLvQPXO LUH %DEEDJHPDLQDQDOLWLF

&KLDU L vQ DFHVWH DSDUDWH SULPLWLYH XQHOH GLQ FRPSRQHQWHOH XQXL DUKLWHFWXUL PRGHUQH SRW IL JVLWH 'H H[HPSOX XQ UHJLVWUX WHPSRUDU GH PHPRULH FDUH PHQ LQH variabilele aflate n curs de procesare. Acest registru este cunoscut sub denumirea de UHJLVWUX DFXPXODWRU &DOFXODWRDUHOH HOHFWURQLFH DX IRVW LQL LDO SURSXVH VXE IRUPD XQXL DSDUDW DEVWUDFW FDUH SRDWH UHDOL]D VDX VLPXOD RULFH WLS GH PDLQ PHFDQLF )RUPD WHRUHWLFDIRVWLQWURGXVGHAlan Turing pe la mijlocul anului 1930. &D L vQ FD]XO PXOWRU DOWH WHKQRORJLL GH]YROWDUHD SUDFWLF D XQHL PDLQL FDUH V respecte acest model, a fost LQIOHQ DW GH DO GRLOHD U]ERL PRQGLDO $FHVW OXFUX D IRVW posibil deoarece se dorea calcularea traiectoriilor de rachete (&ROORVXV L Eniac) sau GHFRGDUHDFRGXOXL(QLJPDIRORVLWGH*HUPDQLDSHQWUXSURWHF LDPHVDMHORU Primul program stocat electronic a fost folosit n 1948. n primii ani de dezvoltare FRPSXWHUHOHLLPSDFWXOORUXOWHULRUvQYLD DXPDQDXIRVWPXOWVXEHYDOXDWH(GH QRWRULHWDWHGHFODUD LDOXLBill *DWHVIRQGDWRUXO0LFURVRIWFXPFQXYHGHFXPDUSXWHDIL YUHRGDWQHYRLHGHPDLPXOWGHKo RAM. Q DQLL D DSUXW SDVWLOD GH VLOLFLX L WHKQRORJLD 9/6, Very large Scale ,QWHJUDWLRQ FD WHKQLF GH SURGXF LH IDSW FH DGXV OD FRPSXWHUH LHIWLQH L UDSLGH $FHVW OXFUX D FRQGXV OD FUHWHUHD L GLYHUVLILFDUHD UDSLG D FDWHJRULLORU GH XWLOL]DWRUL FDUH L SXWHDXSHUPLWHVOHDFKL]L LRQH]H 3HULRDGD FDUH HVWH FDUDFWHUL]DW GH SULQ DSDUL LD microsistemelor pe 8 EL L FDUH GHL HUDX VFXPSH SHUPLWHDX DFFHVXO VHSDUDW GH PDLQIUDPH OD SRVLELOLW LOH VLVWHPXOXLGHFDOFXO QDFHDVW SHULRDG HVWH GHPQ GH UHPDUFDW DSDUL LD vQ D OXL ,FDUHSRDWHILFRQVLGHUDWXQSXQFWGHUHIHULQ vQGRPHQLX'LQDFHVWPRPHQWVRIWXO DvQFHSXWVILHGH]YROWDWQXQXPDLSHQWUXFDOFXOHH[WUHPGHFRPSOH[HFLLSHQWUXMRFXUL HGLWRDUHGHWH[WHSURJUDPHGHED]HGHGDWHLDOWHIDFLOLW LFHUXWHGHSLD 7RW vQ DFHDVW SHULRDG IRU DW L GH UXSHUHD GH PDLQIUDPH D SRUQLW L GH]YROWDUHDVLVWHPHORUGHRSHUDUHORFDOH&30LDSRL'26 6LVWHPXO GH RSHUDUH 06'26 D IRVW UHDOL]DW SULQ DGDSWDUHD OD QRLOH LQVWUXF LXQL PDLQ D XQXL PLFURNHUQHO GH 81,; OD FDUH VDX DGXJDW IXQF LLOH QHFHVDUH FRQWUROXOXL SHULIHULFHORUFDUHvQFHSXVHUVILHDWDDWHFDOFXODWRDUHORUSHUVRQDOH 'LQ SkQ vQ GHL vQF IRDUWH VFXPSH DX vQFHSXW V DSDU SH SLD DUKLWHFWXULGLQFHvQFHPDLSXWHUQLFHSHEL LLDUDULDORUGHIRORVLUHVDH[WLQVIRDUWH PXOWLvQDOWHGRPHQLL 1XHVWHGHQHJOLMDWQLFLLPSDFWXOSURGXVGHLQWHUIH HOHYL]XDOHLGHFRQWURDOHOHSULQ]RQH active ale ecranului. Aceste controale care sunt activate din PRXVH sunt caracteristice sistemului de operare WINDOWS.

1

7RW vQ DFHDVW SHULRDG GLQ UD LXQL HFRQRPLFH L SUDFWLFH VD SURGXV GLVSDUL LD PLFURFDOFXODWRDUHORUDFHVWHDILLQGPXOWGHSLWHGHFHULQ HOHSLH LL 'LQ VH SRDWH VSXQH F VD LQWUDW vQWUR QRX HU vQ DFHVW GRPHQLX SULQ LHIWLQLUHDGUDPDWLFDKDUGZDUHXOXLLDSDUL LDUH HOHORUGHFDOFXODWRDUH 2GDWFXLHIWLQLrea arhitecturilor de calcul s-a putut GLYHVULILFDLPDLPXOWDULDGH XWLOL]DUHDORU$FHVWOXFUXDDYXWFDUH]XOWDWRFUHWHUHDSUH XOXLVRIWXOXL &RQFHSWXOGHUH HDSHUPLWHDWUDQVIHUXULUDSLGHGHGDWHDFURUFDQWLWDWHDvQFHSXW VILHGLQFHvQFHPDLPDUH ,QL LDO PDMRULWDWHD UH HOHORU GH FDOFXODWRDUH HUDX vQFKLVH vQ VHQVXO F QX FRPXQLFDX vQWUH HOH $SRL vQ XOWLPD SHULRDG WHUPHQXO GH VLVWHP GHVFKLV FDSW GLQ SXQFWGHYHGHUHSUDFWLFRUVSkQGLUHGLQFHvQFHPDLPDUHODQLYHOJOREDO'LQDFHVWSXQFW GHYHGHUHUH HOHGHWLSArpanet , Internet DPGVXQWUHSUH]HQWDWLYH QXOWLPLLDQLvQVXLFRQFHSWXOGHWUDQVPLVLHGHLQIRUPD LHLQWHUXPDQWLQGHVVH VFKLPEH7HOHYL]LXQHDGLJLWDOHVWHGHMDLPSOHPHQWDWLDUSUH XOSHULIHULFHORUGHGLFDWHD VF]XW H[WUDRUGLQDU DVWIHO vQFkW VH SUHFRQL]HD] GH]YROWDUHD FDOFXODWRUXOXL DVWIHO vQFkW HO VQXPDLILHVWULFWRULHQWDWVSUHDSOLFD LLGHGLFDWHFLVILHROHJWXUGLQDPLFGHRULFHWLS (audio, video, teleworking) a individului cu societatea. 9RPSUH]HQWDFkWHYDGLQDSOLFD LLOHPDLFXQRVFXWHDOHFDOFXODWRDUHORUvQGLYHUVHGRPHQLL ,QGXVWULHFRQWUROLDXWRPDWL]DUH microcontrolere, CAM (Computer Aided Manufactory); Economie: gestiune, transferul banilor, "banii electronici" . 0HGLFLQGLDJQR]DXWRPDWFHUFHWDUHDHOHFWURQLFODGLYHUVHQLYHOHDOH RUJDQLVPXOXLXPDQDQDOL]DFRGXOXLJHQHWLFGLDJQR]DXWRPDWUH HOHQHXUDOH VWD LLJUDILFHVLVWHPHH[SHUW 3LFWXU QRL UDPXUL DOH SLFWXULL IRORVLQG FRPSXWHUXO UHVWDXUDUH KRORJUDILH UH HOH neurale, procesoare analogice. 0X]LF L WHOHYL]LXQH SUHOXFUUL GH LPDJLQL L VXQHWH SUDFWLF GH RULFH QDWXU SURFHVRDUHDQDORJLFHVWD LLJUDILFHDUKLWHFWXUL00; Proiectare : programele de tip CAD (Computer Aided Design)

Introducere in programare

-

Se mai pot da exemple n mulWHGRPHQLLvQVHVWHFHUWF OD RUD DFWXDO YLD D L VRFLHWDWHDXPDQQXPDLSRWILFRQFHSXWHIUFDOFXODWRU

2

3URJUDPDUHDLOLPEDMHGHSURJUDPDUH

Introducere in programare

Prin SURJUDPDUHVHvQ HOHJHvQPRGJHQHULFWUDQVSXQHUHDXQRURSHUD LLUHSHWLWLYH DVXSUD XQXL VHW GH GDWH vQWUXQ OLPEDM LQWHOLJLELO GH FWUH XQ VLVWHP GH FDOFXO FDUH XUPHD]XOWHULRUVOHH[HFXWH$FHVWOXFUXHVWHUHDOL]DWvQGRXHWDSH HWDS vQ FDUH HVWH LPSOLFDW RPXO L DQXPH FHD GH WUHFHUH GH OD SUREOHPD UHDO OD transpunerea ntr-un limbaj de programare. R D GRXD HWDS DXWRPDW FDUH WUDQVSXQH FRGXOVXUV vQLUXLUHD GH LQVWUXF LXQL specifice limbajului respectiv ntr-un FRGGLUHFWH[HFXWDELOinteligibil sistemului GHFDOFXOOXFUXGHFDUHVHRFXSSURJUDPHVSHFLDOL]DWHQXPLWHFRPSLODWRDUH.

5ROXOSURJUDPULL HVWH FD ILH GDW R DQXPLW RSHUD LXQH VDX VXLW GH RSHUD LXQL UHSHWLWLYH FDUH VH DSOLF DVXSUD XQRU VHWXUL GH GDWH PHUHX GLIHULWH V ILH VFULV XQ SURJUDP FDUH V FHDU VHWXO GH GDWH GHLQWUDUHFHOH FDUH WUHEXLH V ILH SUHOXFUDWH V H[HFXWH DVXSUD ORU VXLWD VWDQGDUG GH RSHUD LXQL L V OLYUH]H GDWHOHGHLHLUH DGLF rezultatele). Q DFHVWH FRQGL LL SURJUDPXO WUHEXLH V ILH FRPSXV GLQ PDL PXOWH LQVWUXF LXQL Q primul rnd cele care UH]HUYGHFODUR]RQGHPHPRULHFDILLQGVSHFLDOGHGLFDWQXPDL SHQWUXDQXPLWHGDWHR]RQGHPHPRULHvQFDUHVHYRUFLWLGDWHOHGHLQWUDUHR]RQGH PHPRULHvQFDUHVHYRUSVWUDGDWHOHLQWHUPHGLDUH(cele care apar n decursul calculelor GDUGHFDUHXWLOL]DWRUXOQXDUHQHYRLHLGHDVHPHQLSHFHOHGHLHLUH3URJUDPXOWUHEXLH VFRQ LQLQVWUXF LXQLFDUHVFLWHDVFGHODXWLOL]DWRUGDWHOHGHLQWUDUHXUPDWHvQVIkULW GH LQVWUXF LXQLOH GH FDOFXO SURSULX ]LV FD vQ ILQDO V FRQ LQ LQVWUXF LXQLOH GH DILDUH D UH]XOWDWHORUGDWHOHGHLHLUH $UKLWHFWXUDXQXLVLVWHPGHFDOFXO Ca REVHUYD LH de ED]: un sistem de calcul este pur L simplu versiunea mult GH]YROWDW a unui calculator de buzunar L deci nu trebuie V ne DWHSWP de la el ca vreo GDW V IDF altceva dect l-a pus cineva, un programator prin intermediul unui program, V IDF. ,QWHOLJHQ DDSDUHQWa unui sistem de calcul provine din cantitatea de LQWHOLJHQ XPDQLQYHVWLWn respectivul program aflat n H[HFX LH Hilar, am putea spune F omul vQFHDUF V IDF pe cineva GXS chipul L DVHPQDUHD lui dar rezultatul este o copie SDOLG FDUH altfel este extrem de XWLO Din aceste lucruri GHULY vestitul principiu de aur al primilor programatori GIGO (Garbage In Garbage Out), care ntr-o traducere SUR]DLF vQVHDPQ: gunoi bagi gunoi VFR L L care are meritul, n DIDU de cel umoristic, de a atrage DWHQ LD oricui care se va apuca de programare F din nefericire calculatorul face numai ce i se LQGLF prin diverse metode V IDF. De aici UH]XOW R SULP DWHQ LRQDUH YDODELO aprope tot timpul n cazul GHSDQULL(H[HFX LHLSDVFXSDVn scopul JVLULLeventualelor defecte n IXQF LRQDUHunui SURJUDP &$87 17, (52$5($ 7$ '( 352*5$0$725 , $32, ' 9,1$ PE CALCULATOR. Desigur H[LVWun procent cam de 5% din VLWXD LLn care un program scris corect este executat JUHLW lucru care apare ca rezultat al LQWHUIHUHQ HL unor programe neautorizate, cum ar fi YLUXLL FX programul aflat n H[HFX LH n cazul n care nu este

3

valabil acest lucru problema este mai FRPSOH[putnd fi implicate GHIHF LXQLaleatorii ale SU LL KDUGZDUH Oricum ar fi aceste lucruri LQWU n sfera de DF LXQH a unui inginer de sistem, Ldeci nu sunt luate aprioric n FRQVLGHUD LHfiind de obicei rare. Pentru a putea vQ HOHJHarhitectura vom FXWDanumite analogii ntre un om Lun sistem de calcul. 6 DQDOL]P ce se vQWkPSO FX un om n momentul n care vede o formulare de genul : 2*2= . 'HLni se pare ceva evident, cu WR LLDPvQY DWpe de rost tabla vQPXO LULL V vQFHUFPacum o descompunere a SDLORUFDUHsunt H[HFXWD L n primul rnd PHPRUPn memoria WHPSRUDUsau de VFXUWGXUDWRSHUDQ]LLdatele asupra FURUDvom executa o RSHUD LXQHapoi UHDOL]PRSHUD LXQHDGHvQPXO LUHrezultnd 4, care este SkQODcomunicarea lui YHUEDOsau prin scris tot n memoria WHPSRUDU6H REVHUYFoperanzii 2,2 LRSHUD LXQHDDXfost preluate de pe un suport extern si anume cel scris, rezultatul putnd fi UHWXUQDWtrimis FWUHHPL WRUXOunei cereri de lucru GXS cum am spus tot pe DFHOLsistem extern de stocare. $FHVWH[HPSOXQXDIRVWGDWIUXQVFRSLDQXPHUROXOOXLHVWHSULQWUHDOWHOHGHD Y RELQXL FX QLYHOXO H[WUHP GH VF]XW OD FDUH VH IDFH DQDOL]D L GHVFRPSXQHUHD XQHL SUREOHPHUHDOHvQPRPHQWXOvQFDUHGRUHVFVRWUDQVSXQvQWUXQOLPEDMGHSURJUDPDUH i acum VDQDOL]PDUKLWHFWXUDEORF(structura IXQF LRQDODunui sistem de calcul. 'XS FXP VH REVHUY GLQ ILJ ntr-un sistem de calcul H[LVW - un dispozitiv de stocare n PDV rolul caietului pe care scrim /citim n cazul nostru. Acest dispozitiv este materializat prin Hard Disk (HDD) FUXLD i se mai 0HPRULH 'LVSR]LWLY spune Lsuport fix de date L)ORSS\'LVN 7HPSRUDUm ,QWUDUH (FDD) FUXLD i se mai spune L suport 5$0 ,H LUH mobil de date . )LJ$UKLWHFWXUDXQXL - o memorie WHPRUDU 5$0 5DQGRP VLVWHPGHFDOFXO Acces Memory) care MRDF H[DFW rolul memoriei de VFXUWGXUDWumane. - dispozitive de Intrare sau de ,HLUH prin care sistemul SULPHWH sau UHWXUQHD] GDWH n cazul unui sistem de calcul acestea sunt tastatura L PRXVH FD dispozitive de intrare L monitorul sau imprimanta ca dispozitive de LHLUH A mai Umas de OPXULWproblema microprocesorului care este inima unui sistem de calcul L DUH rolul de a coordona ntregul sistem. Desigur F DFHDVW coordonare se UHDOL]HD]WRWprin intermediul unor programe care H[LVWn ceea cea am putea numi, prin analogie cu omul, partea de reflexe FRQGL LRQDWH aceste program