1 / 9

Engineering 1020

Engineering 1020. Introduction to Programming Peter King peter.king@mun.ca 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

katen
Download Presentation

Engineering 1020

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Engineering 1020 Introduction to Programming Peter King peter.king@mun.ca www.engr.mun.ca/~peter Winter 2010

  2. ENGI 1020: Examples • Lecture example from last class *

  3. ENGI 1020: Examples • IDE • Integrated Development Environment • Eclipse • Teaching Machine • Editing, compiling and debugging all under one roof • Multiple source files open at once

  4. 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

  5. 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.

  6. 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?

  7. 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.

  8. 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?

  9. 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

More Related