1 / 7

Problem Solving

Problem Solving. Problem Solving Approach. Break it down into smaller, manageable pieces Procedural approach: Break it down into a sequence of steps Consider tasks to be accomplished. Problem Solving Approach. Break it down into smaller, manageable pieces Procedural approach:

joanna
Download Presentation

Problem Solving

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

  2. Problem Solving Approach • Break it down into smaller, manageable pieces • Procedural approach: • Break it down into a sequence of steps • Consider tasks to be accomplished

  3. Problem Solving Approach • Break it down into smaller, manageable pieces • Procedural approach: • Break it down into a sequence of steps • Consider tasks to be accomplished • Object-oriented approach: • Consider data (objects) that needs to managed • Tasks organized around the data

  4. Compound Data Types • Create your own data type • Can contain any data • Can create methods to apply to type • Create solution focusing on data • Known as classes

  5. Example • Grid in Battleship Game • Created module for functions that manipulate a grid. • Needed multiple grids. • But really want to put data (grid) with function that manipulate grid (methods) • Put grid inside a class

  6. Grid as a Class class Grid: def __init__(self) : self.grid = [[B,B,B,B], [B,B,B,B],\ [B,B,B,B], [B,B,B,B]] defprint_grid(self) : … defhas_overlap(self,index,row,col,dir) : …

  7. Using Class Grid g1 = grid.Grid() # creates an instance with its own listg2 = grid.Grid() # creates a 2nd instance with its own list index =0; row=0; col=0; dir=‘h’g1.add_vessel(index,row,col,dir) g2.add_vessel(0,1,2,’v’)# Each grid has aircraft carrier in different position!

More Related