SlideShare a Scribd company logo
Class 10 – Arrays
Agenda Lateral Thinking Warm-up Exam Results, Issues Discussion: SAAD - Problem Solving with Code Discussion/Demo: Intro to Arrays Intro to Assignment 7: Daily Agenda Intro to Project 2: Battleship Team Formation Task assignment Project Work and Wrap-up
System Analysis & Design Problem Solving with Code Tools IPO (outside   in) Pseudocode (linear, integrative) Flowchart (linear, integrative) Models & Approaches SDLC 3-tier (n-tier) MVC (OOP)
SAAD – 3-tier (n-tier) Presentation Logic Data
SAAD - MVC Model View Controller
Intro to Arrays What is an array? A collection of related data Similar to a set of mailboxes at a site The site is the array, each mailbox represents an element The mailbox may contain a specific value or object The contents can be strings, integers, or even another array Addressed using brackets or parentheses (zero-based) Can be examined iteratively or uniquely
Arrays Illustrated Single Dimension Array=days_of_week(7) 2-Dimensional (table) Array=address_book(4,7) Mon Tues Wed Thurs Fri Sat Sun fname lname addr city prov post Email joe smith 123 My Street Halifax NS B1B 1B1 [email_address] jane jones 1 Main Dr Dartmouth NS B7B 7B7 [email_address] pat white 21 Goode Dr. Halifax NS B1A 2C3 [email_address] sam davis 19 Smith Dr. Timberlea NS B9G 2K8 [email_address]
Creating and Accessing Arrays Single Dimension a = Array.new  # an empty array a = []  # same as above  puts a  => nil (no output) a[0]=“hello”  # assigns the value a[1]=“ world” puts a[0] + a[1] puts a x = [1,”green”,”martian”]
Array Properties and Methods Properties  a=[“hello”, 1, “world”,2,”!”] a.last  => “!” a.first  => “hello” a[0].class  => String a[1].class  => Fixnum a.at(1)  =>  1 a.length  =>  5
Array Properties and Methods Methods a.push (“my friend”) => [   “hello”, 1, “world”,2,”!”,”my friend”] a.pop  => [   “hello”, 1, “world”,2,”!”] a.sort  => [1,2, “!”,”hello”,”world”] a.reverse = [“!”,2,”world”,1,”hello”] a.sort!  => applied to array (permanent change) a.delete_at(2)  => [   “hello”, 1, 2,”!”] a.each do |variable|  end  => iterates through the array
Creating and Accessing Arrays Practice Handout: Exercise 10-1, Creating and Accessing an Array
2-Dimensional Arrays Creating x=Array.new(4) {Array.new(7)} a=[[1,"green"],[2,"red"],[3,"blue"]] Accessing & Assigning myval= a[1][0]  => “green” x[2][4]=“Halifax” a[1][1]=“orange”
Iterating Through Arrays Using  each rows=5 cols=5 countr=0 mtrx=Array.new(rows) {Array.new(cols)} mtrx.each do |myvar| myvar.each.do |ovar| ovar=countr countr=countr+1 end end
Iterating Through Arrays Using  for rows=5 cols=5 countr=0 for x in (0..rows-1) for y in (0..cols-1) mtrx[x][y]=countr countr=countr+1 end end
Assignment 7: Daily Agenda Use a 2D Array to hold details Prompt for time (hour only) Prompt for appointment Prompt for location Assign inputs to elements Continue to prompt until user types in a blank in the time slot Sort the Agenda and then generate Daily Agenda by iterating through the array
Project 2: Battleship Simple Version 8 x 8 grid (A-H, 1-8) 2 ships each player Each ship assigned to a particular grid location 10 shots each player A shot to the location of a vessel sinks it Draw grid and results after each shot “ ~” is unknown, “!” is sunk, “0” is a miss  If two of the ships of any player are sunk, the other player wins, end game If after ten shots one player has more ships than the other, he/she wins, otherwise it’s a tie.
Wrap-up Summary Arrays Analysis & Design Assignment Project Next Week Brief intro to Classes Business Problems with Fishbone Diagram Project Time*
Practice/ Set-up Use this time to attempt the assignment to prepare you for the project, OR Begin to set up your team and the tasks, OR See me about any issues with grades, etc. OR Do any research you need to get the assignment or project completed. GREAT TIP SITE: http://www.techotopia.com/index.php/Understanding_Ruby_Arrays

More Related Content

Similar to Class 10 Lecture Notes (20)

python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
jonycse
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
Vysakh Sreenivasan
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
Skills Matter
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Groovy
GroovyGroovy
Groovy
Zen Urban
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
aztack
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
GauravPandey43518
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
Abhishek Tirkey
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
Wes Oldenbeuving
 
[Start] Scala
[Start] Scala[Start] Scala
[Start] Scala
佑介 九岡
 
7li7w devcon5
7li7w devcon57li7w devcon5
7li7w devcon5
Kerry Buckley
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
Tanwir Zaman
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
JavaScript Array Interview Questions PDF By ScholarHat
JavaScript Array Interview Questions PDF By ScholarHatJavaScript Array Interview Questions PDF By ScholarHat
JavaScript Array Interview Questions PDF By ScholarHat
Scholarhat
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
Java Intro
Java IntroJava Intro
Java Intro
backdoor
 
R workshop
R workshopR workshop
R workshop
Revanth19921
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
alexstorer
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
python beginner talk slide
python beginner talk slidepython beginner talk slide
python beginner talk slide
jonycse
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
Vysakh Sreenivasan
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
carliotwaycave
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
aztack
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
GauravPandey43518
 
C++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptxC++ STL (quickest way to learn, even for absolute beginners).pptx
C++ STL (quickest way to learn, even for absolute beginners).pptx
Abhishek Tirkey
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
JavaScript Array Interview Questions PDF By ScholarHat
JavaScript Array Interview Questions PDF By ScholarHatJavaScript Array Interview Questions PDF By ScholarHat
JavaScript Array Interview Questions PDF By ScholarHat
Scholarhat
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
Java Intro
Java IntroJava Intro
Java Intro
backdoor
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
alexstorer
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

More from Stephen Parsons (18)

Atlantic Woodworkers Website Strategy
Atlantic Woodworkers Website StrategyAtlantic Woodworkers Website Strategy
Atlantic Woodworkers Website Strategy
Stephen Parsons
 
Chairs Report to LSCRS 2012 AGM
Chairs Report to LSCRS 2012 AGMChairs Report to LSCRS 2012 AGM
Chairs Report to LSCRS 2012 AGM
Stephen Parsons
 
Program Renewal for NSCC Schools 2010-11
Program Renewal for NSCC Schools 2010-11Program Renewal for NSCC Schools 2010-11
Program Renewal for NSCC Schools 2010-11
Stephen Parsons
 
Class 7 lecture notes
Class 7 lecture notesClass 7 lecture notes
Class 7 lecture notes
Stephen Parsons
 
Class 6a ruby math
Class 6a   ruby mathClass 6a   ruby math
Class 6a ruby math
Stephen Parsons
 
Class 6 truth tables and boolean math
Class 6   truth tables and boolean mathClass 6   truth tables and boolean math
Class 6 truth tables and boolean math
Stephen Parsons
 
Class 5 - Set Theory and Venn Diagrams
Class 5 - Set Theory and Venn DiagramsClass 5 - Set Theory and Venn Diagrams
Class 5 - Set Theory and Venn Diagrams
Stephen Parsons
 
Class 4 IPO and Intro to Ruby
Class 4 IPO and Intro to RubyClass 4 IPO and Intro to Ruby
Class 4 IPO and Intro to Ruby
Stephen Parsons
 
Class 3 Binary & Hexadecimal
Class 3 Binary & HexadecimalClass 3 Binary & Hexadecimal
Class 3 Binary & Hexadecimal
Stephen Parsons
 
Class 2 Math I
Class 2 Math IClass 2 Math I
Class 2 Math I
Stephen Parsons
 
Class 1 introduction to logic & problem solving
Class 1   introduction to logic & problem solvingClass 1   introduction to logic & problem solving
Class 1 introduction to logic & problem solving
Stephen Parsons
 
Portfolio Of A Community
Portfolio Of A CommunityPortfolio Of A Community
Portfolio Of A Community
Stephen Parsons
 
Cause & effect analysis part 2
Cause & effect analysis part 2Cause & effect analysis part 2
Cause & effect analysis part 2
Stephen Parsons
 
Cause & effect analysis part 1
Cause & effect analysis part 1Cause & effect analysis part 1
Cause & effect analysis part 1
Stephen Parsons
 
Class 11 lecture notes
Class 11 lecture notesClass 11 lecture notes
Class 11 lecture notes
Stephen Parsons
 
Class 9 Lecture Notes
Class 9 Lecture NotesClass 9 Lecture Notes
Class 9 Lecture Notes
Stephen Parsons
 
Class 8 Lecture Notes
Class 8 Lecture NotesClass 8 Lecture Notes
Class 8 Lecture Notes
Stephen Parsons
 
Deck Project Phase II
Deck Project Phase IIDeck Project Phase II
Deck Project Phase II
Stephen Parsons
 
Atlantic Woodworkers Website Strategy
Atlantic Woodworkers Website StrategyAtlantic Woodworkers Website Strategy
Atlantic Woodworkers Website Strategy
Stephen Parsons
 
Chairs Report to LSCRS 2012 AGM
Chairs Report to LSCRS 2012 AGMChairs Report to LSCRS 2012 AGM
Chairs Report to LSCRS 2012 AGM
Stephen Parsons
 
Program Renewal for NSCC Schools 2010-11
Program Renewal for NSCC Schools 2010-11Program Renewal for NSCC Schools 2010-11
Program Renewal for NSCC Schools 2010-11
Stephen Parsons
 
Class 6 truth tables and boolean math
Class 6   truth tables and boolean mathClass 6   truth tables and boolean math
Class 6 truth tables and boolean math
Stephen Parsons
 
Class 5 - Set Theory and Venn Diagrams
Class 5 - Set Theory and Venn DiagramsClass 5 - Set Theory and Venn Diagrams
Class 5 - Set Theory and Venn Diagrams
Stephen Parsons
 
Class 4 IPO and Intro to Ruby
Class 4 IPO and Intro to RubyClass 4 IPO and Intro to Ruby
Class 4 IPO and Intro to Ruby
Stephen Parsons
 
Class 3 Binary & Hexadecimal
Class 3 Binary & HexadecimalClass 3 Binary & Hexadecimal
Class 3 Binary & Hexadecimal
Stephen Parsons
 
Class 1 introduction to logic & problem solving
Class 1   introduction to logic & problem solvingClass 1   introduction to logic & problem solving
Class 1 introduction to logic & problem solving
Stephen Parsons
 
Portfolio Of A Community
Portfolio Of A CommunityPortfolio Of A Community
Portfolio Of A Community
Stephen Parsons
 
Cause & effect analysis part 2
Cause & effect analysis part 2Cause & effect analysis part 2
Cause & effect analysis part 2
Stephen Parsons
 
Cause & effect analysis part 1
Cause & effect analysis part 1Cause & effect analysis part 1
Cause & effect analysis part 1
Stephen Parsons
 

Class 10 Lecture Notes

  • 1. Class 10 – Arrays
  • 2. Agenda Lateral Thinking Warm-up Exam Results, Issues Discussion: SAAD - Problem Solving with Code Discussion/Demo: Intro to Arrays Intro to Assignment 7: Daily Agenda Intro to Project 2: Battleship Team Formation Task assignment Project Work and Wrap-up
  • 3. System Analysis & Design Problem Solving with Code Tools IPO (outside  in) Pseudocode (linear, integrative) Flowchart (linear, integrative) Models & Approaches SDLC 3-tier (n-tier) MVC (OOP)
  • 4. SAAD – 3-tier (n-tier) Presentation Logic Data
  • 5. SAAD - MVC Model View Controller
  • 6. Intro to Arrays What is an array? A collection of related data Similar to a set of mailboxes at a site The site is the array, each mailbox represents an element The mailbox may contain a specific value or object The contents can be strings, integers, or even another array Addressed using brackets or parentheses (zero-based) Can be examined iteratively or uniquely
  • 7. Arrays Illustrated Single Dimension Array=days_of_week(7) 2-Dimensional (table) Array=address_book(4,7) Mon Tues Wed Thurs Fri Sat Sun fname lname addr city prov post Email joe smith 123 My Street Halifax NS B1B 1B1 [email_address] jane jones 1 Main Dr Dartmouth NS B7B 7B7 [email_address] pat white 21 Goode Dr. Halifax NS B1A 2C3 [email_address] sam davis 19 Smith Dr. Timberlea NS B9G 2K8 [email_address]
  • 8. Creating and Accessing Arrays Single Dimension a = Array.new # an empty array a = [] # same as above puts a => nil (no output) a[0]=“hello” # assigns the value a[1]=“ world” puts a[0] + a[1] puts a x = [1,”green”,”martian”]
  • 9. Array Properties and Methods Properties a=[“hello”, 1, “world”,2,”!”] a.last => “!” a.first => “hello” a[0].class => String a[1].class => Fixnum a.at(1) => 1 a.length => 5
  • 10. Array Properties and Methods Methods a.push (“my friend”) => [ “hello”, 1, “world”,2,”!”,”my friend”] a.pop => [ “hello”, 1, “world”,2,”!”] a.sort => [1,2, “!”,”hello”,”world”] a.reverse = [“!”,2,”world”,1,”hello”] a.sort! => applied to array (permanent change) a.delete_at(2) => [ “hello”, 1, 2,”!”] a.each do |variable| end => iterates through the array
  • 11. Creating and Accessing Arrays Practice Handout: Exercise 10-1, Creating and Accessing an Array
  • 12. 2-Dimensional Arrays Creating x=Array.new(4) {Array.new(7)} a=[[1,"green"],[2,"red"],[3,"blue"]] Accessing & Assigning myval= a[1][0] => “green” x[2][4]=“Halifax” a[1][1]=“orange”
  • 13. Iterating Through Arrays Using each rows=5 cols=5 countr=0 mtrx=Array.new(rows) {Array.new(cols)} mtrx.each do |myvar| myvar.each.do |ovar| ovar=countr countr=countr+1 end end
  • 14. Iterating Through Arrays Using for rows=5 cols=5 countr=0 for x in (0..rows-1) for y in (0..cols-1) mtrx[x][y]=countr countr=countr+1 end end
  • 15. Assignment 7: Daily Agenda Use a 2D Array to hold details Prompt for time (hour only) Prompt for appointment Prompt for location Assign inputs to elements Continue to prompt until user types in a blank in the time slot Sort the Agenda and then generate Daily Agenda by iterating through the array
  • 16. Project 2: Battleship Simple Version 8 x 8 grid (A-H, 1-8) 2 ships each player Each ship assigned to a particular grid location 10 shots each player A shot to the location of a vessel sinks it Draw grid and results after each shot “ ~” is unknown, “!” is sunk, “0” is a miss If two of the ships of any player are sunk, the other player wins, end game If after ten shots one player has more ships than the other, he/she wins, otherwise it’s a tie.
  • 17. Wrap-up Summary Arrays Analysis & Design Assignment Project Next Week Brief intro to Classes Business Problems with Fishbone Diagram Project Time*
  • 18. Practice/ Set-up Use this time to attempt the assignment to prepare you for the project, OR Begin to set up your team and the tasks, OR See me about any issues with grades, etc. OR Do any research you need to get the assignment or project completed. GREAT TIP SITE: http://www.techotopia.com/index.php/Understanding_Ruby_Arrays

Editor's Notes

  • #6: Model: The model contains the core information for an application. This includes the data and validation rules as well as data access and aggregation logic. View: The view encapsulates the presentation of the application, and in ASP.NET this is typically the HTML markup. Controller: The controller contains the control-flow logic. It interacts with the Model and Views to control the flow of information and execution of the application.