t_09.4up - Engineering Computation Tutoral 09 Problem...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering Computation: Tutoral 09 Problem Solving with Computing, using the Python Language Questions from Week 08? Programming Exercises from Zelle textbook 1 pg. 291 - 293 # 1, 7, 8, 11, 13. 2 What’s in your toolbox? Print statement, string literals Basic calculator, integer division Variables Built-in functions Math library functions Straight-line programs Branching programs Python lists For loops Nested for loops Strings While loops Converting between number system using Python Matplotlib Program Design File Processing Graphics Functions Scope of Variables Comments Complex Conditions Testing and Debugging Exception Handling Common Loop Patterns Boolean Operators Unit Testing 3 Today’s Topics: 1 Classes 2 Objects 4 Real World Examples Classes In biological classification, all mammals belong to the class Mammalia. All members of class Mammalia have certain things in common: have hair and nurse their young. All members of class Aves have feathers, no diaphragm, and no rib cage. Some can fly, some can’t. All sedans and coupes are Cars. We could say they belong to the class Car. All cars have a steering wheel and four wheels. 5 Real World Examples Objects We could say: Object ”Fido” is an object of Class ”Mammalia” Object ”Big Bird” is an object of Class ”Aves” Object ”your car” is an object of Class ”Car” 6 Objects in Object Oriented Programming. Objects 1 A data type that knows stuff and can do stuff. 2 A collection of related information. 3 A set of operations to manipulate that information. Note: Objects are sometimes referred to as ”instances of classes” An instance of a class is an object. These are two ways of saying the same thing. 7 Examples of Objects you have seen and used. from graphics import * p1 = Point (100 ,100) p2 = Point (45 ,60) c1 = C i r c l e (p1 , 30) l1 = Line (p1 , p2 ) w1 = GraphWin () p1 and p2 are objects of Class Point. c1 is an Object of Class Circle. l1 is an object of Class Line. w1 is an object of Class GraphWin. 8 Methods 1 Methods are what an object can do. 2 They are functions that work on an object. Examples of Methods you have seen and used. # p1 can get the value of i t ’ s X f or you . p1 . getX () # c1 can f i l l i t s e l f with a colour . c1 . s e t F i l l ( ’ red ’ ) # l1 can draw i t s e l f in the window w1 . l1 . draw (w1) # w1 can c l o s e i t s e l f . w1 . c l o s e () 9 Classes 1 A class is often referred to as a blue-print for an object . 2 Defines the data that objects of the class can have. 3 Defines the methods that Objects of the class will have. 10 Similarly, we can write our own classes, and use them... # This code won ’ t run . . . yet :- ) myCar = Car (” green ” , Mazda) f l u f f y = Cat (” Persian ”) jeremy = Human(”Jeremy”) My car is of Class Car....
View Full Document

This document was uploaded on 09/14/2011.

Page1 / 12

t_09.4up - Engineering Computation Tutoral 09 Problem...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online