Download
problem solving n.
Skip this Video
Loading SlideShow in 5 Seconds..
Problem Solving PowerPoint Presentation
Download Presentation
Problem Solving

Problem Solving

101 Views Download Presentation
Download Presentation

Problem Solving

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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!