CSE 231 LAB 10 TOPICS TO COVER 1

CSE 231 LAB 10

TOPICS TO COVER 1. 2. PROBLEM SOLVING CLASSES

PROBLEM SOLVING VS PROGRAMMING “Solve a problem” ? 1. The solution is not just a single word or number. 2. Goal is to provide the necessary steps to get an answer 3. It’s all about the journey, rather than the destination! Principles 1. Understand the problem: Can you think of a picture or a diagram that might help you understand the problem. 2. 3. 4. Devise a plan: Solve a simpler problem. Carry out the plan. Review/extend.

PROBLEM SOLVING VS PROGRAMMING • Example – how do you calculate a GPA? • The answer is not a number, but a procedure. • Correct solution = we always get the right answer when we follow the steps • In other words… If we work through the steps, and the final answer is wrong, then there was a mistake in our solution.

CONSIDER … • Since you woke up this morning, what “problems” did you have to work out? Did you follow a sequence of steps that you figured out in the past? • If you had to describe the computer with one word, what would it be? • I’ve got some “information” on a little piece of paper. describe or characterize this information? • Some aspects are important, others are not How would you

CLASSES • This lab has nothing to do with classes • I want you to start thinking about them, because they can be a hard concept to grasp, and even harder to code.

CLASSES • Classes are data types like dict or tuple • Characteristics: • • Internal structure - data Methods - to manipulate data • Method examples: • • • my_list. sort() my_list. pop() my_set. add(1) • You know how you can. add(number) to a set, but not a dictionary? • You can. pop() from a list but not a string? • Those are methods specific to that class

CLASS AND INSTANCE D = set({1, 2, 3, 4}) Creates an instance from set class set() is the constructor of the class set • Class is like a cookie cutter • Instance is like a cookie

SPYDER DEMO • Class Card • Class Deck
- Slides: 9