engineering 1020
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 PresentationTRANSCRIPT
Engineering 1020
Introduction to Programming
Peter [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
– Editing, compiling and debugging all under one roof
– Multiple source files open at once
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
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.
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?
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.
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?
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