+ All Categories
Home > Documents > Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber...

Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber...

Date post: 03-Aug-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
36
APS105 Winter 2012 Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012
Transcript
Page 1: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

APS105Winter 2012

Jonathan Deberjdeber -at- cs -dot- toronto -dot- edu

Lecture 35April 13, 2012

Page 2: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

2

Today

• Exam Info/Tips

• Review

• Big Picture

Page 3: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Exam Info

• Check Registrar’s website for timing/location

• 2.5 hours

• No external aids

• Cumulative (emphasis on later topics)

3

Page 4: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Office Hours

• I will have some during the exam period

4

Page 5: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Exam Tips

• Read the whole thing first

• Read every question carefully

• Make things easy for the marker

5

Page 6: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’re Asking

• More than just “what does the function do?”

• Do we want a complete program?

• Do we want a code snippet/fragment?

• Do we want an example of using a function?

6

Page 7: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Question !

7

Write your student number in the space provided at the bottom of each odd-numbered page.

Failure to do so will result in a 2 mark deduction.

Page 8: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Buggy Code Question

8

"#$%&'$()*+,,#-"#$./0%%%%&'$()1-2*+,,#2/34

1

2

“!"#$” is misspelled “!"#”1)

Format string in single quotes, should be in double quotes

2)

Page 9: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Pointers Point!

9

&6

5$6

#%&'#'(')*#%&'+,'('-#*

&6 5 &6 5

Wrong Wrong

Page 10: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Approaching Coding Questions• Read it carefully

• What am I being asked to do?

• Figure out the pseudocode

• How do I go about doing it?

• Write the code

• How do I translate the pseudocode into C code?

• Re-read the question

• Does my code do what it was supposed to?10

Page 11: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

How to Handwrite Code

• We realize that there is no compiler on paper

• However, consistent or egregious syntax errors are a problem

11

&'$()1-78.7;%"9,:+/3

&'$()1-78.7%"9,:+/3

<=$,+%0%$1%>?%5@;AB%C%A4%0)':+43

Page 12: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

How to Handwrite Code

• Some symbols are hard to draw ( 0%4 and D)

• Indenting

• Tell us what you’re doing

• Leave lots of space

12

Page 13: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

13

Page 14: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

13

Page 15: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

14

Function Reference Sheet

• We will provide a reference page with documentation for some built-in functions

• You are free to use other (non-prohibited) functions as well

• You do not have to use every function on the sheet

Page 16: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Exam Period Tips

• Figure out a study schedule

• What material for what course on what day

• Don’t completely ignore exams that are later

• Schedule breaks

15

Page 17: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Review

16

Page 18: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered

• What’s a computer?

• What does it mean to program it?

• How to we take an English problem and translate it to a program?

17

Page 19: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

18Source: http://cm.bell-labs.com/cm/cs/who/dmr/picture.html

Page 20: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered

• What’s a computer?

• What does it mean to program it?

• How to we take an English problem and translate it to a program?

• How do we write a program?

• What are the parts of a program?

• Variables, expressions, statements

19

Page 21: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered• Types

• $(),%.#:E,+,%F=9'

• Arithmetic operators

• Style

• Reading/writing data

• &'$()1-/, GF9(1-/, conversion specifiers

• Booleans (E##, and Boolean operators)

• Relational and comparison operators20

Page 22: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered• $1, +,G+%$1, and +,G+

• <=$,+ and 1#' loops

• Arrays

• Functions (parameters, return values, scope)

• H9)=;=, Random Numbers

• Helper Functions

• Pointers

• Pointer Arithmetic21

Page 23: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered• Strings

• Literals, arrays, pointers

• .&/#%012 (including functions you should never use)

• Reading/writing (including functions you should never use)

• Arrays of pointers

• Dynamic memory

• 3455"678, 9/::78, /:455"678

• Dynamically allocated arrays, .#;:"978

• Dynamic memory bugs22

Page 24: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered• IJKK• Multi-file programs

• Structures (and &<,:$:9)

• Pointers to .&/=6&s

• Dot and arrow operators

• Commenting, testing, and debugging

23

Page 25: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

24Image: Naval Historical Center

Grace Hopper’s Lab Notebook

Page 26: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered• Dynamic memory bugs

• IJKK• Structures (and &<,:$:9)

• Pointers to .&/=6&s

• Dot and arrow operators

• Commenting, testing, and debugging

• Recursion

25

Page 27: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips
Page 28: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered• Dynamic memory bugs

• IJKK• Structures (and &<,:$:9)

• Pointers to .&/=6&s

• Dot and arrow operators

• Commenting, testing, and debugging

• Recursion

• Linked lists27

Page 29: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

What We’ve Covered• 6&<,:12 character functions

• Searching

• Sequential

• Binary

• Sorting

• Maintain sorted order while adding

• Simple sorts (bubble, selection, insertion)

• Complex sort (merge sort)28

Page 30: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Building on the Foundation

29

Page 31: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Real Programs

30

• “Real” programs are built from the same tools

• Much more complicated

• More languages (maybe)

• More libraries

• More data structures

• More algorithms

• Could be millions of lines of code

Page 32: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Web Browser

• Read a (long) string containing the page’s HTML

• Process the string, and build up data structures in memory

• Traverse those data structures, and figure out what to draw

• Draw the page on screen with calls to OS drawing functions

31

Page 33: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Image Editing

• An image is just an array of pixels

• Editing it is just changing those pixels

32

Page 34: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Operating System

• Data structures hold info about memory, files, etc.

• Implement a bunch of functions that provide an interface

• Other software can call them

• Hardware can trigger them

• Wait for some bit of hardware or software to request something, and process that request

33

Page 35: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Closing Thoughts

• Computers do exactly what you tell them

• To work with them, we need to think algorithmically

• Computing is built out of abstractions

34

Page 36: Lecture 35 - dgp.toronto.edujdeber/aps105h/201201/lectures/Lecture35/A… · Jonathan Deber jdeber -at- cs -dot- toronto -dot- edu Lecture 35 April 13, 2012 . 2 Today •Exam Info/Tips

Thank You!

35


Recommended