Introduction to Algorithmic Processes CMPSC 201C Fall 2000 - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Introduction to Algorithmic Processes CMPSC 201C Fall 2000

Description:

Sections 1, 2, 7, 8, 11, and 12 in 111 Forum (Nidhi and Anand) ... typedef enum{false, true} bool; must be inserted before the declaration. ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 20
Provided by: CenterforA152
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Algorithmic Processes CMPSC 201C Fall 2000


1
Introduction to Algorithmic ProcessesCMPSC
201CFall 2000
2
Administrative Issues
  • Homework due Wed. 9/20 by 500 in 202 Pond.
  • Exam 1 - Tuesday 9/26 at 630 - 745 PM
  • Sections 1, 2, 7, 8, 11, and 12 in 111 Forum
  • (Nidhi and Anand)
  • Sections 3, 4, 5, 6, 9, and 10 in 102 Forum
  • (John and Pyush)

3
Schedule
  • Mon. 9/25 No Lecture, Recitation - review
  • Tues. 9/26 Exam
  • Wed. 9/27 Guest lecture (you may be tested on
    material!)
  • Fri. 9/29 Recitation - MATLAB
  • Mon. 10/2 Lecture - Chapter 4
  • Wed. 10/4 Lecture - Chapter 4
  • Fri. 10/6 Recitation - MATLAB
  • Mon. 10/9 No lecture of recitation.

4
If you miss the exam
  • You will be permitted to take a comprehensive
    make-up exam at the end of the semester if you
    bring proof of why you missed the exam.
  • If you are sick, see a doctor before the exam and
    get an excuse!

5
Exam
  • 40 multiple choice and True/False questions worth
    5 points.
  • No calculators, books, notes, etc. will be
    permitted.
  • Exams will be on scantrons-- bring a pencil.
  • IDs will be checked!
  • Know your section number!

6
Practice Exam
  • Will be on I-drive and web pages by Friday 9/29.
  • From Spring 2000 (the answers have not been
    checked!)
  • Also read book and answer questions in chapters.

7
Questions????
8
Variables of type bool
  • If you want a variable that is either equal to
    true or false (1 or 0), you can declare it as a
    bool type.
  • Ex Suppose you were writing a program that
    sorted a list of numbers. You may use a flag
    called sorted to indicate when the list is in
    order. You perform the sort when this flag is
    false and stop when it becomes true.
  • bool sorted

9
Variables of type bool
  • Then in the code you can set this variable equal
    to true or false using an assignment statement.
  • sorted true

10
Variables of type bool
  • Are often used in conditions or loops.
  • Ex
  • while (!sorted)
  • perform the sort procedure
  • when some condition is met set sorted
  • equal to true (sorted true)

11
Problems
  • Some compilers do not recognize bool data type.
    Then the line
  • typedef enumfalse, true bool
  • must be inserted before the declaration.

12
Increment and Decrement
  • Increment and decrement- i, i
  • i is the same as i i1
  • likewise
  • i-- is the same as i i-1
  • Used as a shorthand in writing code.

13
Pre and Post Increment
  • However you also have pre-increment and
    post-increment (i and i) as well as pre- and
    post decrement (--i and i--)
  • When used alone, they are equivalent. For
    example as part of a loop
  • while ( i lt somenumber)
  • do something
  • i

14
Pre and Post Increment
  • However, when used as part of an assignment
    statement, different effects occur
  • a b does not give the same results as
  • a b
  • Suppose b 5,
  • then a b would store value of 5 in a and
    change b to 6 (b b1)
  • whereas a b changes b to 6 first then
    stores the value of 6 in the variable a.

15
Pre and Post Increment
  • a b
  • is equivalent to writing two statements
  • a b
  • b b1
  • similarly
  • a b
  • is equivalent to writing
  • b b1
  • a b

16
Pre and Post Increment
  • In both cases b is changed. The difference is
    when it is changed.
  • a b b is modified after storing
  • the value in a.
  • a b b is modified before
  • storing the value in a.

17
Pre and Post Increment
  • Although a nice shorthand for writing code, using
    the increment operator can become confusing when
    you (or someone else) tries to modify the code
    later.
  • Think about this expression
  • someVar a --b/c

18
Test Hints
  • Read code carefully! Look at what is written,
    not necessarily what you expect the code to do.
  • Look for short cuts to eliminate some of the
    choices.

19
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com