Download presentation
Presentation is loading. Please wait.
Published byEthelbert Malone Modified over 9 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.