Chuong 1 tong quan ve lap trinh va nnlt

  • Published on
    27-Jun-2015

  • View
    909

  • Download
    0

Embed Size (px)

Transcript

<ul><li> 1. Lp Trnh My Tnh Gii thiu v lp trnh my tnh Phn tch, thit k v pht trin h thng Phn loi</li></ul> <p> 2. 6 Giai on phn tch v thit kh thng Thnh phn d n phn mm: Ngi s dng. B phn qun l d n. B phn k thut. Qu trnh phn tch v thit k h thng c chia thnh 6 giai on nh sau: Chng 1 - Tng quan v lp trnh v NNLT 2 3. 1. Tm hi u vn : phn tch hin trng, a gii php, khuyn ngh.2. Phn tch : thu thp d liu, phn tch v bo co.3. Thit k : thit k s b, thit k chi tit, bo co.4. Pht trin : ln k hoch theo di tin , thit lp cu hnh phn cng, phn mm, lp trnh v kim tra h thng.5. Ci t : chuyn sang h thng mi. o to nhn lc.6. Bo tr : kim tra h thng, thu nhn phn hi t pha ngi dng, nh k nh gi hot ng h thng.- Tng quan v lp trnh v NNLTChng 1 3 4. Lp trnh Mt chng trnh (program) l tp cc culnh (instruction) vit bng mt ngn nglp trnh dng ra lnh cho my tnhthc hin cc thao tc x l d liu thnhthng tin. Lp trnh l tin trnh to thnh mtchng trnh. Chng 1 - Tng quan v lp trnh v NNLT 4 5. Cc bc lp trnh Xc nh v lm r vn ( clarification ) :xc nh u vo, kt xut, cc yu cu x lcn thit. Ln phng n gii quyt ( design ) : sdng cc cng c m hnh ho ln s vn cn gii quyt. Vit chng trnh ( coding ): s dng mtngn ng lp trnh vit chng trnh. Chng 1 - Tng quan v lp trnh v NNLT 5 6. Cc bc lp trnh Kim tra chng trnh ( test ): kim tra vsa cha cc li logic (bug) trong chng trnh(debug). Vit ti liu v bo tr chng trnh( document, maintenance ): vit hng dns dng, gii thch chng trnh, hng dncch chy chng trnh.Chng 1 - Tng quan v lp trnh v NNLT6 7. Ngn ng lp trnh Mt ngn ng nhn to bao gm cc tvng c nh v mt tp cc quy tc (gil syntax-c php) dng lp ra cc chlnh cho my tnh. Hu ht cc chng trnh u c vitbng cch s dng mt trnh bin tp vnbn hoc trnh x l son ra m ngun(source code)Chng 1 - Tng quan v lp trnh v NNLT7 8. Ngn ng lp trnh M ngun s c bin dch (compile) hocthng dch (interprete) sang ngn ng my(machine code) cho my tnh c th hiu v thchin. C nhiu loi ngn ng lp trnh, v hu ht ccnh khoa hc v my tnh u ng rngkhng c mt ngn ng duy nht no c khnng p ng cho cc yu cu ca tt c cclp trnh vin.Chng 1 - Tng quan v lp trnh v NNLT8 9. NNLT - Phn loi NNLT Bc cao Cc ngn ng lp trnh bc cao(BASIC, C, Pascal, Ada, Cobol, ) cho php lptrnh vin c th din t chng trnh bng cct kha v c php bt chc ngn ng t nhinca con ngi Cc ngn ng ny c gi l "bc cao" vchng gii phng cho cc lp trnh vin khi phiquan tm n vn tng lnh s c mytnh thc hin nh th no.Chng 1 - Tng quan v lp trnh v NNLT9 10. NNLT Phn loi NNLT Bc cao Mi cu lnh trong ngn ng lp trnh bc cao tng ngvi mt s ch lnh ca ngn ng my. C th vit cc chng trnh nhanh hn nhiu so vi khidng ngn ng bc thp, nh hp ng (assemblylanguage). Tuy nhin, vic dch sang ngn ng my c hiu sutthp, khng hon ton ti u cho nn cc chng trnhvit theo cc ngn ng bc cao chy chm hn ccchng trnh vit theo ngn ng bc thp.Chng 1 - Tng quan v lp trnh v NNLT10 11. Phn loi NNLT Bc thp Cc ngn ng lp trnh bc thp (hpng) cho php lp trnh vin m ha ccch lnh vi hiu sut cao nht c th c. Ngi lp trnh phi thng tho mt cchchi tit v cc kh nng chnh xc ca hmy tnh v b vi x l ca n. Lp trnh bng hp ng cng mt nhiuthi gian hn. Chng 1 - Tng quan v lp trnh v NNLT 11 12. 5GLs artificial intelligence4GLsORACLE, SEQUEL, INGRES, ... HIGH-LEVELFortran, COBOL, C, C++, LANGUAGES LISP, Pascal, Java, ... ASSEMBLER LANGUAGESMACHINE CODE Chng 1 - Tng quan v lp trnh v NNLT 12 13. Chuyn NN bc cao thnh NNbc thp - Compiler Chng trnh ngun vit bng NNLT bc caophi c dch thnh NN my my tnh cth hiu v thc thi lnh. Dch bng trnh bin dch (compiler): b dchchuyn ton b chng trnh vit bng NN bccao thnh NN my trc khi my tnh c ththc hin chng trnh. VD: COBOL, FORTRAN, C, Pascal l cc ngn ngs dng c ch bin dch Chng 1 - Tng quan v lp trnh v NNLT 13 14. Interpreter Dch bng trnh thng dch (interpreter): b dch chuyn tng dng lnh trong chng trnh vit bng NN bc cao thnh NN my v thc hin tng lnh ngay khi dch xong lnh . VD: BASIC l ngn ng s dng c chthng dch Chng 1 - Tng quan v lp trnh v NNLT 14 15. Lp trnh hng i tng Object-oriented programming (OOP) lphng php lp trnh cho php kt hpd liu vi cc cu lnh x l d liu trong mt i tng. Cc i tng c th c s dng li vit cc chng trnh khc nhau. Chng 1 - Tng quan v lp trnh v NNLT 15 16. Lp trnh trc quan Visual programming l phng php vitcc chng trnh bng cch kt hp cci tng sn c thng qua cc thao tctrc quan. Cho php vit chng trnh d dng,nhanh chng hn.VD: Visual Basic, Visual J, Visual C++,Chng 1 - Tng quan v lp trnh v NNLT16 17. Lp trnh trn Internet S dng cc ngn ng lp trnh: HTML HyperText Markup Language: ngn ngnh du siu vn bn. XML eXtensible Markup Language: VRML Virtual Reality Markup Language: Java ActiveX K thut khc: COM, DCOM, RMI, RPC... Chng 1 - Tng quan v lp trnh v NNLT 17 18. V d ghi dng ch Chao cac ban ra mn hnh. PASCAL program GhiChu; uses CRT; beginwrite(Chao cac ban); end. C #include void main (void) { printf(Chao cac ban); }Chng 1 - Tng quan v lp trnh v NNLT18 19. Tham kho t Web C th tham kho cch vit chng trnh in ra ch Hello world ca hn 200 ngn ng lp trnh khc nhau ti a ch http://www2.latech.edu/~acm/HelloWorld.shtmlChng 1 - Tng quan v lp trnh v NNLT19 20. My tnh v con ngi My tnhCon ngiTc tnh ton Cc nhanh Chm hoc rt chm bn Hng thng, hng nm, Ch trong vi ngy, hiu sut hiu sut khng h thay gim dn nu lm vic lin tc iKh nng chu nh hngt b nh hng nh hng nhiu, c bit lca cc yu t khch quancc yu t mi trngKh nng suy lun, giiKhng cTtquyt vn Kh nng phn ng viKhng cTtnhng tnh hung bt ngChng 1 - Tng quan v lp trnh v NNLT20 21. Bi ton v vic gii quyt bi tonbng my tnh AB Bi ton: Hy tnh gi tr ca biu thc an (n nguyn dng) khibit gi tr ca a v n. Li gii trn my tnh B1. a =?, n=? B2. if n =0 th a, kq=1, End. B3. else (n&gt;0) B3.1. Nh gi tr ca a. B3.2. Nh s php nhn c thc hin (0). B3.3. Nu s php nhn cha bng n-1, sang bc B3.4, ngc li sang bc B3.7. B3.4. Nhn kt qu nh vi a v nh kt qu mi. B3.5. Tng s php nhn thc c hin ln 1. B3.6. Tr v B3.3. B3.7. Kt qu tnh c chnh l con s nh. B4. Kt thcChng 1 - Tng quan v lp trnh v NNLT21 22. Cc phng php gii quyt biton trn my tnh Trc tip Gin tip: cha tm ra li gii chnh xc ca bi ton. Th sai Vt cn Ngu nhin M cung Heuristic Tr tu nhn toChng 1 - Tng quan v lp trnh v NNLT22 23. Phng php trc tip K thut lp trnh trn my tnh 3 loi: Li gii chnh xc bng cng thc ton hc e.g., tnh tng n s nguyn dng u tin Li gii gn ng (cng thc tnh gn ng) e.g., sin, cos Li gii khng tng minh ( quy) e.g., CnmChng 1 - Tng quan v lp trnh v NNLT23 24. Phng php gin tip Th sai Trong khi cha ngh ra mt cch tht hayth c vic rt tng cng rm cho n khirt c ci kim. 3 nguyn l: Vt cn Ngu nhin M cung May ri. S lng php th ln Chng 1 - Tng quan v lp trnh v NNLT 24 25. Phng php gin tip Heuristic Nguyn l: vt cn thng minh Ti u cc b (Greedy) Hng ch Th t V d: bi ton tm ng Chng 1 - Tng quan v lp trnh v NNLT 25 26. Phng php gin tip tr tunhn to Th sai, Heuristic: tr thng minh ca con ngi Tr tu nhn to: tr thng minh ca my tnh(bt chc con ngi) V d: bi ton nc B5: 5 lt, B8: 8 lt. Ch ra cch ong c c 2 lt nc Gii: a ra cc lut my tnh t tm li gii: Lut 1: B8 rng -&gt; y B8 Lut 2: B5 y -&gt; ht nc trong B5 Lut 3: Nu B5 cha y -&gt; nc trong bnh B8 sang B5 cho n khi B5 y. Chng 1 - Tng quan v lp trnh v NNLT 26 27. Thut ton vs. thut gii Thut ton: Mt dy hu hn cc bckhng mp m v c th thc thi c , qutrnh hnh ng theo cc bc ny phi dngv cho c kt qu nh mong mun . Cc tnh cht ca thut ton: Xc nh (khng mp m, thc thi c) Hu hn (hu hn, dng) E.g., Tnh tng cc s nguyn dng l. ng (kt qu mong mun) u vo/ u ra Tnh hiu qu Tnh tng qut Chng 1 - Tng quan v lp trnh v NNLT 27 28. Cc phng php biu din thutton Ngn ng t nhin S dng quy tc phn cp (1.1, 1.1.1) Di dng, khng th hin r cu trc ca thut ton S khi (flowchart) Dng hnh v, k hiu M gi (pseudo-code) Vay mn cc c php ca mt ngn ng lp trnhno (Pascal, C) Mt phn ca ngn ng t nhinChng 1 - Tng quan v lp trnh v NNLT28 29. Thut ton quy B cc tnh cht hu hn, xc nh, ngn ca thut ton-&gt; thut ton quy. T tng: a bi ton hin ti v mt bi ton ng dng(cng loi, cng tnh cht) nhng cp thp hn-&gt; ln ngc gii bi ton cp cao hn. V d: Tnh n! 0!=1 (phn dng) n!=n*(n-1)! (phn quy)Chng 1 - Tng quan v lp trnh v NNLT29 30. Thut gii Nhn xt: C nhiu bi ton cha c li gii kiu thut tonhoc khng bit c tn ti hay khng! C nhiu bi ton c thut ton gii nhngkhng chp nhn c v: Thi gian gii qu ln Cc iu kin cho thut ton kh p ng C nhng bi ton gii theo nhng cch vi phmthut ton nhng vn chp nhn c. Thut gii: b tnh xc nh v tnh ng nca thut ton Chng 1 - Tng quan v lp trnh v NNLT 30 31. Thut gii Heuristic Tnh cht: Thng tm c li gii tt (cha chc: l tt nht) Chi ph thp: d dng v nhanh chng T nhin, gn gi vi cch suy ngh ca con ngi. Nguyn l: Vt cn thng minh Gii hn khng gian tm kim Tm kim c bit da vo c th ca bi tan Tham lam (Greedy) Ly tiu chun ti u (trn phm vi ton cc) ca bi ton lm tiu chun chn la hnh ng cho phm vi cc b ca tng giai on trong qu trnh tm kim li gii Th t Thc hin hnh ng da trn mt cu trc th t hp l ca khng gian kho st nhm nhanh chng t c mt li gii ttChng 1 - Tng quan v lp trnh v NNLT31</p>