engineering 1020

9
Engineering 1020 Introduction to Programming Peter King [email protected] www.engr.mun.ca/~peter Winter 2010

Upload: katen

Post on 08-Jan-2016

48 views

Category:

Documents


4 download

DESCRIPTION

Engineering 1020. Introduction to Programming Peter King [email protected] www.engr.mun.ca/~peter Winter 2010. ENGI 1020: Examples. Lecture example from last class *. ENGI 1020: Examples. IDE Integrated Development Environment Eclipse Teaching Machine - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Engineering 1020

Engineering 1020

Introduction to Programming

Peter [email protected]

www.engr.mun.ca/~peter

Winter 2010

Page 2: Engineering 1020

ENGI 1020: Examples

• Lecture example from last class *

Page 3: Engineering 1020

ENGI 1020: Examples

• IDE– Integrated Development Environment

• Eclipse• Teaching Machine

– Editing, compiling and debugging all under one roof

– Multiple source files open at once

Page 4: Engineering 1020

ENGI 1020: Examples

• Debugging– After you hit 'build', the real fun starts

– Start at the top• 1 error tends to lead to another

– Think logically• What's missing?• Typing error?• Wrong type?

– Fresh eyes

Page 5: Engineering 1020

ENGI 1020: Examples

• Ex #1– In pre-calculus physics the distance an object travels

is given by the formula:

s = ut + 1/2at2

where u is the initial speed, a is a constant acceleration and t is the time.

Create a function to compute s plus a main function to that tests it by calling it with some values.

Page 6: Engineering 1020

ENGI 1020: Examples

• #1– What's the contract?

• What data are we agreeing to return?– #returns

• What data do we require?– #params– @pre

• What should we call the function?

Page 7: Engineering 1020

ENGI 1020: Examples

• #2– Create a function to compute the area of a circle

given its radius (note that a value for PI is not built in to C++ so use 3.14159) plus a main function to that tests it by calling it with some values.

Page 8: Engineering 1020

ENGI 1020: Examples

• #2– What's the contract?

• What data are we agreeing to return?– #returns

• What data do we require?– #param– @pre

• What should we call the function?

Page 9: Engineering 1020

ENGI 1020: Examples

• #3– Lets do a simple example, but with more

utilization of variables.

– Write a function that returns the square of a number.

– Write a main function that calls our function once, and then again with the result of the first call

– The output would look like:• The square of 2 is 4• The square of the square of 2 is 16