Class 10 Lecture Notes


Published on

Course notes from class 10 - Logic and Problem-solving course

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • 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.
  • Class 10 Lecture Notes

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

      Clipping is a handy way to collect important slides you want to go back to later.