ISP 121 - PowerPoint PPT Presentation

About This Presentation
Title:

ISP 121

Description:

Algorithms and Computer Programming ... Computers require precise instructions to perform an operation The instructions cannot be ambiguous An algorithm is an ... – PowerPoint PPT presentation

Number of Views:83
Avg rating:3.0/5.0
Slides: 23
Provided by: cwh32
Learn more at: https://qrc.depaul.edu
Category:

less

Transcript and Presenter's Notes

Title: ISP 121


1
ISP 121
  • Algorithms
  • and
  • Computer Programming

2
Why Know Simple Programming?
  • You can create powerful macros in Access / Excel
    / Word / ??? to manipulate data
  • You can create interactive web pages, such as the
    DePaul QRC mapping tool
  • You can write simple programs to analyze data and
    write the next article exposing cheaters in your
    school district

3
What is an Algorithm?
  • Computers require precise instructions to perform
    an operation
  • The instructions cannot be ambiguous
  • An algorithm is an ordered sequence of
    instructions that is guaranteed to solve a
    specific problem

4
What is an Algorithm?
  • Algorithms consist of three basic types of
    operations or instructions
  • Sequential operations, e.g. Add 1 cup of butter
    Subtract the amount of the check from the current
    account balance Set the value of x to 1
  • Conditional operations, e.g. If the mixture is
    too dry, then add ½ cup water If the current
    account balance lt 0, then account overdrawn

5
What is an Algorithm?
  • Algorithms consist of three basic types of
    operations or instructions
  • Iterative operations, e.g. Repeat the previous
    two steps until the mixture has thickened Repeat
    the following five steps until there are no more
    checks to be processed Repeat steps 1,2 and 3
    until the value of y is equal to 1

6
Example
  • Add two values
  • 32542
  • 42892

How would you describe this operation to someone
who has never seen carry arithmetic?
7
Average Miles Per Gallon (1)
  • Step 1 Get values for gallons used, starting
    mileage, ending mileage
  • Step 2 Set the value of distance driven to
    (ending mileage starting mileage)
  • Step 3 Set the value of average miles per gallon
    to (distanced driven / gallons used)
  • Step 4 Print the value of average miles per
    gallon
  • Step 5 Stop

8
Average Miles Per Gallon(2)
  • Step 1 Get values for gallons used, starting
    mileage, ending mileage
  • Step 2 Set the value of distance driven to
    (ending mileage starting mileage)
  • Step 3 Set the value of average miles per gallon
    to (distanced driven / gallons used)
  • Step 4 Print the value of average miles per
    gallon (more on next slide)

9
Average Miles Per Gallon(2)
  • Step 5 If average miles per gallon is greater
    than 25.0 then
  • Print the message You are getting good gas
    mileage.
  • Else
  • Print the message You are NOT getting good gas
    mileage.
  • Step 6 Stop

10
Average Miles Per Gallon (3)
  • Step 1 Repeat step 2 to step 8 until Response is
    No
  • Step 2 Get values for gallons used, starting
    mileage, ending mileage
  • Step 3 Set the value of distance driven to
    (ending mileage starting mileage)
  • Step 4 Set the value of average miles per gallon
    to (distanced driven / gallons used)
  • Step 5 Print the value of average miles per
    gallon

11
Average Miles Per Gallon (3)
  • Step 6 If average miles per gallon is greater
    than 25.0 then
  • Print the message You are getting good gas
    mileage.
  • Else
  • Print the message You are NOT getting good gas
    mileage.
  • Step 7 Print the message Do you want to do this
    again, Yes or No?
  • Step 8 Get a value for Response from the user
  • Step 9 Stop

12
HTML
  • Hyper-Text Markup Language
  • All web pages are made (to varying degrees) from
    HTML
  • Each HTML command tells the web browser what to
    do next, such as start a new paragraph, display
    an image, or insert a link

13
ltHTMLgt Begins every HTML document ltHEADgt Beg
ins the head section ltTITLEgtDePaul
University lt/TITLEgt Title that appears on
browser title bar lt/HEADgt Ends the head
section ltBODYgt Begins the body section This is
the first line.ltBRgt Text followed by line
Break ltPgtStart a new paragraph.lt/Pgt Begins a new
paragraph ltH1gtFirst Headinglt/H1gt Level 1 heading
(biggest) ltH2gtA second level headinglt/H2gt Level 2
heading (little smaller) ltHRgt Inserts a
horizontal rule (straight line) ltBgtThis line is
bold.lt/BgtltBRgt Bold text ltIgtThis line is
italicizedlt/IgtltBRgt Italicized text ltIMG
SRC\images\banner.gifgt Insert an image
here ltA HREFhttp//www.cs.depaul.edugt
DePaul CS Pagelt/Agt Link to another web
page lt/BODYgt Close the body section lt/HTMLgt E
nds every HTML document
14
JavaScript
  • JavaScript can be added to an HTML document to
    provide dynamic features
  • JavaScript can be added to the head or body of
    HTML code (but we will concentrate on examples in
    body), can assign values to variables, can
    perform decision statements, and can perform loop
    statements

15
Example - JavaScript in Body
lthtmlgt ltheadgt lt/headgt ltbodygt ltscript
type"text/javascript"gt document.write("This
message is written when the page
loads") lt/scriptgt lt/bodygt lt/htmlgt
16
Example - JavaScript in Body
lthtmlgt ltheadgt lt/headgt ltbodygt ltscript
type"text/javascript"gt alert("This message is
written inside an Alert box") lt/scriptgt lt/bodygt lt
/htmlgt
17
Example - Using a Variable
lthtmlgt ltbodygt ltscript type"text/javascript"gt var
name name prompt(Please enter a
name) document.write(name) lt/scriptgt lt/bodygt lt/h
tmlgt
18
Example - Using an If
lthtmlgt ltbodygt ltscript type"text/javascript"gt var
d new Date() var time d.getHours() if (time
lt 12) document.write("ltbgtGood
morninglt/bgt") lt/scriptgt ltpgtThis example
demonstrates the If statement.lt/pgt ltpgtIf the
time on your browser is less than 12, you will
get a "Good morning" greeting.lt/pgt lt/bodygt lt/htmlgt
19
Example - Using an IfElse
lthtmlgt ltbodygt ltscript type"text/javascript"gt var
d new Date() var time d.getHours() if (time lt
12) document.write("ltbgtGood
morninglt/bgt") else document.write("ltbgtGoo
d afternoonlt/bgt") lt/scriptgt ltpgtThis example
demonstrates the If...Else statement.lt/pgt ltpgtIf
the time on your browser is less than 12, you
will get a "Good morning" greeting. Otherwise you
will get a "Good day" greeting.lt/pgt lt/bodygt lt/html
gt
20
Logical Operators
  • You can use the following logical operators in IF
    and WHILE statements
  • !
  • gt
  • gt
  • lt
  • lt

21
Example - Using a While to Count
lthtmlgt ltbodygt ltscript type"text/javascript"gt var
i 0 while (i lt 5) document.write("The
number is " i) document.write("ltbrgt")
i lt/scriptgt ltpgtExplanationlt/pgt ltpgtltbgtilt/bgt
equal to 0.lt/pgt ltpgtWhile ltbgtilt/bgt is less than ,
or equal to, 5, the loop will continue to
run.lt/pgt ltpgtltbgtilt/bgt will increase by 1 each time
the loop runs.lt/pgt lt/bodygt lt/htmlgt
22
Example - Using a While to Prompt
lthtmlgt ltbodygt ltscript type"text/javascript"gt var
answer answer prompt(Do you understand quantum
physics?) while (answer no) document.write
(It is actually based on quantum
things.") answer prompt(Now do you understand
quantum physics?) document.write(Congrats!) lt
/scriptgt lt/bodygt lt/htmlgt
Write a Comment
User Comments (0)
About PowerShow.com