Top Banner
Introduction to Programming Lesson 1
26

98-361 Lesson01 Slides

Feb 24, 2018

Download

Documents

mypartyzany
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 1/26

Introduction to ProgrammingLesson 1

Page 2: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 2/26

Objectives

Skills/Concepts MTA Exam Objectives

Understanding ComputerProgramming

Understand computer storageand data types (1.1)

Understanding Decision

Structures

Understand computer decision

structures (1.)

Understanding !epetitionStructures

Identi"y t#e appropriate met#od"or #and$ing repetition (1.%)

Understanding &'ception

and$ing

Understand error #and$ing (1.)

Page 3: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 3/26

*$gorit#ms

• *$gorit#m re"ers to a met#od "orso$ving prob$ems.

• Common tec#ni+ues "or representing

an a$gorit#ms, – -$oc#art

 – Decision /ab$es.

Flowcharts and Decision Tables

0ore precise t#an natura$$anguages

Less "orma$ and easier touse t#an programming

$anguages

Page 4: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 4/26

-$oc#arts

• * oc#art is a grap#ica$representation o" an a$gorit#m.

Common Flowchart Smbols

Start or end o" an a$gorit#m

Process or computationa$ operation

Input or out operation

Decision ma2ing operation

Direction o" t#e o o" contro$

Page 5: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 5/26

-$oc#art &'amp$e

• * oc#art t#at compares to numbers,

Start

Input '

Input y

3 4 y5

Output'

Stop

Output

y

6o

 7es

Page 6: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 6/26

Decision /ab$e

• Use"u$ "or $arge number o" conditions

• Compact and readab$e "ormat

• * decision tab$e to ca$cu$atingdiscount,

!"antit #$%

 & ' ' '

!"antit #(%

 7 7 6 6

!"antit #$%%

 7 7 7 6

Disco"nt 89 1:9 189 :9

Page 7: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 7/26

Introducing C;

• 0icroso"t .6&/ -rameor2 – *n &'ecution &nvironment

 – !eusab$e C$ass Libraries

 – Language Compi$ers

•  /#e C; Programming Language – Part o" t#e .6&/ -rameor2

 – ig#<$eve$ Language

 – Program needs to be compi$ed be"ore t#ey can bee'ecuted.

 – Case sensitive

Page 8: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 8/26

Page 9: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 9/26

&$ements o" a C; Program

• Se$ect common e$ements o" a C;program,

Data Tpes  /ypes o" data in a program. Common data types are int(integers)= c#ar (sing$e c#aracter va$ue)= oat (oatingpoint va$ues).

)ariables Provides temporary storage during program e'ecution.int number > 1:?

Constants Data @e$ds #ose va$ue cannot be [email protected] int i > 1:?

Arras * co$$ection o" items in #ic# eac# item can be accessedby a uni+ue inde'.intAB numbers > 1= = %= = 8 ?

Operators Symbo$s t#at speci"y #ic# operation to per"orm onoperands be"ore returning a resu$t.

Methods 0et#ods are code b$oc2s containing a series o" statements.0et#ods can receive input via arguments and can return ava$ue to t#e ca$$er.

Page 10: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 10/26

Decision Structures

 /#e i"Statement  /#e i"<e$seStatement

 /#e sitc#Statement

Page 11: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 11/26

 /#e i" Statement

•  /#e i*  statement i$$ e'ecute a givense+uence o" statements on$y i" t#ecorresponding Eoo$ean e'pression

eva$uates to true.

Page 12: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 12/26

 /#e i"<e$se Statement

•  /#e i*+else statement a$$os your program to per"orm oneaction i" t#e Eoo$ean e'pression eva$uates to true and adiFerent action i" t#e Eoo$ean e'pression eva$uates to "a$se.

Page 13: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 13/26

 /#e sitc# Statement

•  /#e switch statement a$$os mu$ti<aybranc#ing. In many cases= using a sitc#statement can simp$i"y a comp$e' combination o"i"<e$se statements.

Page 14: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 14/26

!epetition Structures

 /#e #i$e Loop

 /#e do<#i$e Loop

 /#e "or Loop

 /#e "oreac# Loop

!ecursion

Page 15: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 15/26

 /#e #i$e Loop

•  /#e while $oop repeated$y e'ecutesa b$oc2 o" statements unti$ aspeci@ed Eoo$ean e'pression

eva$uates to "a$se.

Page 16: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 16/26

 /#e do<#i$e Loop

•  /#e do+while $oop repeated$ye'ecutes a b$oc2 o" statements unti$a speci@ed Eoo$ean e'pression

eva$uates to "a$se. /#e do+while $oop tests t#e condition at t#ebottom o" t#e $oop.

Page 17: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 17/26

 /#e "or Loop

•  /#e *or $oop combines t#e t#reee$ements o" iterationGt#einitia$iHation e'pression= t#e

termination condition e'pression=and t#e counting e'pressionGinto amore readab$e code.

Page 18: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 18/26

 /#e "oreac# Loop

•  /#e *oreach $oop is an en#ancedversion o" t#e "or $oop "or iteratingt#roug# co$$ections suc# as arrays

and $ists.

Page 19: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 19/26

!ecursion

• !ecursion is a programmingtec#ni+ue t#at causes a met#od toca$$ itse$" in order to compute a

resu$t.

Page 20: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 20/26

&'ception and$ing

• *n e'ception is an une'pected error conditiont#at occurs during program e'ecution.

• #en e'ception occurs= t#e runtime creates ane'ception object and Jt#rosK it.

• Un$ess you Jcatc#K t#e e'ception= t#e programe'ecution i$$ terminate.

• &'ceptions are an object o" t#e System.&'ceptionc$ass or one o" its derived c$asses.

 – &'amp$e, Divide,-eroException e'ceptionobject is t#ron #en t#e program attempts todivide by Hero.

 – &'amp$e, File'otFo"ndException e'ception

object is t#ros #en t#e program cannot @nda iven @$e.

Page 21: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 21/26

Un#and$ed &'ceptions

• #at #appens #en t#e @$ec,data.t't is not "ound in t#is code5

Page 22: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 22/26

and$ing &'ceptions it# try<catc#

• P$ace t#e code t#at t#ros t#ee'ceptions inside a tr b$oc2.

• P$ace t#e code t#at #and$es ane'ception inside a catch b$oc2.

•  7ou can #ave more t#an one catc#b$oc2s "or eac# try b$oc2. &ac# catc#

b$oc2 #and$es a speci@c e'ceptiontype.

• * try b$oc2 must #ave at $east a

catc# b$oc2 or a @na$$y b$oc2

Page 23: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 23/26

&'ception and$ing Samp$e

Page 24: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 24/26

 /#e @na$$y E$oc2

•  /#e .nall b$oc2 is used in association it# t#etry b$oc2.

•  /#e .nall b$oc2 is a$ays e'ecuted regard$ess o"#et#er an e'ception is t#ron.

•  /#e .nall b$oc2 is o"ten used to rite c$ean<upcode.

Page 25: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 25/26

try<catc#<@na$$y &'amp$e

Page 26: 98-361 Lesson01 Slides

7/25/2019 98-361 Lesson01 Slides

http://slidepdf.com/reader/full/98-361-lesson01-slides 26/26

!ecap

• *$gorit#ms – -$oc#art= decision tab$e

• C; Programming Language –

Mariab$es= constants= data types= arrays=operators= met#ods

• Decision Structures – i"= i"<e$se= sitc#

• !epetition Structures – #i$e= do<#i$e= "or= "oreac#= recursion

• &'ception and$ing – try<catc#= try<@na$$y= try<catc#