t_09.4up

# t_09.4up - Questions from Week 08 Engineering Computation...

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

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

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

View Full Document
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 g r a p h i c s import * p1 = Point (100 ,100) p2 = Point (45 ,60) c1 = C i r c l e ( p1 , 30) l 1 = 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 o r you . p1 . getX () # c1 can f i l l i t s e l f with a c o l o u r . c1 . s e t F i l l ( ’ red ’ ) # l 1 can draw i t s e l f in the window w1 . l 1 . 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. Fluffy is of Class Cat. Jeremy is of Class Human.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern