none
Array Project Ideas

    General discussion

  • I am in the middle of teaching arrays to my Programming one students, and I am drawing a blank for project ideas. All I have is different versions of "Load an array with random values, add up all of the items, list each item as even or odd, find the average of the items" and so on.

    What I am hoping for is a more exciting as a project idea. The game of battle ship isn't bad, but it is a little involved for these students.

    Maybe something in the 25 line range.

    If you could work up some sample code, that would be ideal.

    Any ideas?
    • Changed type litdevModerator Thursday, March 18, 2010 10:16 PM A discussion on array teaching ideas
    Wednesday, March 17, 2010 12:43 AM

All replies

  • Back in the 80s I had fun with a program I found in a magazine.  Essentially, the computer would permute the list 123456789, then the player had to sort the list again by typing in a sequence of digits, each digit indicating the length of the prefix of the list that should be rotated.

    For example,

    461927863
    [4]
    916427863
    [9]
    368724619
    [3]
    863724619
    [8]
    164273689
    ...
    and so on until
    123456789

    Not challenging for the player, but plenty to play with when learning about arrays.

    -- Rafe
    Wednesday, March 17, 2010 7:25 AM
  • Given a dictionary of words (http://dotnetperls-controls.googlecode.com/files/enable1.txt), load it up in an array and find words that are anagrams of a given word. 

    Next step would be to use "?" as a wildcard char to find all words matching a pattern (e.g, ???tion)
    Wednesday, March 17, 2010 7:28 AM
    Moderator
  • What if you teach Sorting algorithms at the same time?
    I think Bubble sort would be very easy to start with.
    Then you can progress to the more complicated ones.

    Wednesday, March 17, 2010 7:39 AM
  • Play with apps putting 2 dimensional array content to display. It's rather easy and effects are easily visible.
    i.e. populate with random values and then convert each cell to different color.
    If you assume each color is RGB - you can easily switch to 3 dimensional arrays.

    Another app is multiplication table generator.

    third idea from the top of my head is something like very simple minesweeper or gomoku (http://en.wikipedia.org/wiki/Gomoku) game. Gomoku should be two players game because writing computer AI may be time consuming.
    Grzesio
    Wednesday, March 17, 2010 7:52 AM
  • CC, I would think that a MasterMind style game would be easy and a good demonstration of using arrays. It could show array cell referencing and both single and two dimensional array structures.
    Saturday, March 20, 2010 11:34 AM
  • Sorry for taking so long to comment. The last couple of weeks have been crazy busy.

    All of these interesting ideas; but they won't work for my audience. All but two of my students are taking the class only to meet the technology requirement, or are seniors looking to do the absolute minimum. All of your kind suggestions were good, but either required a fair amount of programming for the user interface (like Go) or the basic algorithm was overly complicated and would require too much explanation to get the point across (like MasterMind).

    This afternoon I did manage to think up a project idea that will foot the bill. A text based version of the game Simon.

    Import code: QXQ571

    The code is still a little over the top and complex at 85 lines and requiring two arrays. But, I plan to give students most of the code, and require them to fill in the blanks (like writing the matching code), and improve the interface (like saving the high score).

    Thanks for all of the suggestions. And if my idea sparks anything more brain storms, please share.

     

    Saturday, March 27, 2010 8:41 PM
  • ...or the basic algorithm was overly complicated and would require too much explanation to get the point across (like MasterMind).

    CC, nothing overtly complicated about mastermind. I wrote you a textwindow based version in 46 lines which may or may not be of use to you.

    It uses a 1D array for the computer choice and a 2D array for the player's guesses.

    Import code: JBH373  (or http://smallbasic.com/program/?JBH373 )

     

    Sunday, March 28, 2010 12:46 AM
  • That is a very elegant program. Outside of arrays though, I would also have to explain in detail the following items for them to work up a solution of their own:

    • Using GetSubText as a tool to randomly choose the letters for the pegs
    • The need to convert the user input to upper case
    • How the guess is processed, and what each position being displays means
    • The concatenation to redisplay the players choice
    • The compound if statement you use to decide if the player has won.

    That is five new techniques I would have to explain outside of the general use of arrays. Yes, I could remove most of those stumbling blocks from the program, and substitute them for simpler processes, but then the program would be more like 150 rather then 46. And all of this is assuming I can get across the basic idea behind master-mind in the first place. An idea as esoteric as exact match verses color match would be a trick to explain when English is the native language to only one of my students.

    Developing project ideas has to to be the most challenging part of being a CS teacher. With each new topic I need 1 to 5 project ideas that drive the topic home without introducing too many new ideas. And if the project is too complex, frustration sets in and I find them surfing the net rather then trying to solve the problem.

     

    Sunday, March 28, 2010 4:14 AM
  • All valid points CC, which would have, if you'd stated them initially, have helped us come up with more relevant examples rather than having the ones submitted just be negated.

    Note that I used the 'convert to uppercase' option as it was something you used in your program and had assumed you'd already covered that aspect. 

    Sunday, March 28, 2010 2:21 PM
  • How about a scorecard for bowling?
    Sunday, March 28, 2010 7:15 PM
  • DW:

    Fair enough on both counts. I could have gone into more detail in my original post, and having used it myself I should have omitted the uppercase move from my lists not too's.

    Rushworks:

    This is another good example of the use for arrays, but it is a little too utilitarian for the students. Games are always best. Barring that, anything where there is wow factor, like a recent project where the students built an analogue clock.

     

    The Simon Says game is good, but I am still hoping for better. Something that changes the array as the program runs. And even better if the data needs to be saved from one run of the program to another.

    By the way, I'm not terribly fond of the file access methods. Not having to manage opening and closing is good. Being able to read a file all at once, or by specifying a line is good. What I would like to see is something in between these two. Reading the next line, or appending to the end of the file. Just some straight forward sequential access. The lack of an append is very limiting.

    Once again, thanks for the assistance everyone.

    Sunday, March 28, 2010 9:08 PM
  • CC, maybe you are approaching arrays from the wrong angle.

    Arrays themselves are simply data structures. They exist in order to keep complex data structures in a manageable format and make them easy to access using indeces. The problem I see is that you're trying to create a very basic example of something designed to be more complex.

    The best way to show the power and effectiveness of arrays is to write a program without arrays that contains a lot of tedious typing, then show how using an array makes the process much simpler.

    This could be a Simon game, or a Mastermind game, or a Sudoku game, or a calendar grid with events, or whatever game your students are at the understanding level to comprehend (maybe just a 12x12 times-table grid).  The non-array version would probably have lots and lots of If..Then statements and lots of typing. Then show the same program with an array, probably using a loop or two, and they will soon see which one is easier to type in.

    You also commented on my Mastermind example that you would need to introduce the GetSubText command. Indeed, I would say that this is a good step towards understanding and teaching arrays. Introduce the concept that a text string is simply a 1D array, and that each letter is contained within a specific indecy identified by its string position. A simple wordsearch game could quite easily be built on such principles.

    PS. SmallBasic does have an append (unless it's part of Fremy's extension, I can't tell): file.appendContents

    (If appendContents is a Fremy command, just use a File.InsertLine() with a very high line number, say 999999, and it will always append the new line to the file.)

    Monday, March 29, 2010 3:20 PM
  • When I was learning programming they taught us arrays by doing something like this: FFV947 vs typing out a silly amount of variables! I am guessing your students would have made some games before or something similar, maybe you could just get them to go back to a previous game and see if they can make it better by using an array to store more data.
    Monday, March 29, 2010 10:16 PM
  • Back in the 80s I had fun with a program I found in a magazine.  Essentially, the computer would permute the list 123456789, then the player had to sort the list again by typing in a sequence of digits, each digit indicating the length of the prefix of the list that should be rotated.

    For example,

    461927863
    [4]
    9164 27863
    [9]
    368724619
    [3]
    863 724619
    [8]
    16427368 9
    ...
    and so on until
    123456789

    Not challenging for the player, but plenty to play with when learning about arrays.

    -- Rafe


    This is fantastic! I love the idea! I can't wait to see if these things will work. Thanks!

     

     

    steve barbarich , choosehottubsdirect.com


    Monday, February 14, 2011 6:07 AM
  • How about creating a pop-up menu, when the mouse is in a certain location a pop up menu appears and the user can select a choice from a list, here is some code with if statements but could be written better with arrays.

    GraphicsWindow.Width = 150
    GraphicsWindow.Height = 90
    GraphicsWindow.Show ()
    GraphicsWindow.CanResize = "False"
    GraphicsWindow.BrushColor = "black"
    GraphicsWindow.DrawRectangle (15,15,120,60)
    GraphicsWindow.DrawText (19,17,"50/10/5 Discount")
    GraphicsWindow.DrawText (19,37,"50/15/5 Discount")
    GraphicsWindow.DrawText (19,57,"50/20/5 Discount")
    GraphicsWindow.MouseMove = selectshade
    Sub selectshade
      if GraphicsWindow.MouseX >=15 and GraphicsWindow.MouseX <=135 And GraphicsWindow.MouseY >=15 And GraphicsWindow.MouseY <=35 Then
        GraphicsWindow.BrushColor = "gray"
        GraphicsWindow.FillRectangle (16,16,118,18)
        GraphicsWindow.brushColor = "White"
        GraphicsWindow.DrawText (19,17,"50/10/5 Discount")
        GraphicsWindow.FillRectangle (16,36,118,18)
        GraphicsWindow.FillRectangle (16,56,118,18)
        GraphicsWindow.brushColor = "black"
        GraphicsWindow.DrawText (19,37,"50/15/5 Discount")
        GraphicsWindow.DrawText (19,57,"50/20/5 Discount")
      EndIf
     
      if GraphicsWindow.MouseX >=15 and GraphicsWindow.MouseX <=135 And GraphicsWindow.MouseY >=35 And GraphicsWindow.MouseY <=55 Then
        GraphicsWindow.BrushColor = "gray"
        GraphicsWindow.FillRectangle (16,36,118,18)
        GraphicsWindow.brushColor = "White"
        GraphicsWindow.DrawText (19,37,"50/15/5 Discount")
        GraphicsWindow.FillRectangle (16,16,118,18)
        GraphicsWindow.FillRectangle (16,56,118,18)
        GraphicsWindow.brushColor = "black"
        GraphicsWindow.DrawText (19,17,"50/10/5 Discount")
        GraphicsWindow.DrawText (19,57,"50/20/5 Discount")
      EndIf
     
      if GraphicsWindow.MouseX >=15 and GraphicsWindow.MouseX <=135 And GraphicsWindow.MouseY >=55 And GraphicsWindow.MouseY <=75 Then
        GraphicsWindow.BrushColor = "gray"
        GraphicsWindow.FillRectangle (16,56,118,18)
        GraphicsWindow.brushColor = "White"
        GraphicsWindow.DrawText (19,57,"50/20/5 Discount")
        GraphicsWindow.FillRectangle (16,16,118,18)
        GraphicsWindow.FillRectangle (16,36,118,18)
        GraphicsWindow.brushColor = "black"
        GraphicsWindow.DrawText (19,17,"50/10/5 Discount")
        GraphicsWindow.DrawText (19,37,"50/15/5 Discount")
      EndIf
     
      GraphicsWindow.MouseDown = SelectedDiscount
     
    EndSub

    Sub SelectedDiscount
      if GraphicsWindow.MouseX >=15 and GraphicsWindow.MouseX <=135 And GraphicsWindow.MouseY >=15 And GraphicsWindow.MouseY <=35 Then
        dx= "one"
        TextWindow.Write (dx)
      EndIf
      if GraphicsWindow.MouseX >=15 and GraphicsWindow.MouseX <=135 And GraphicsWindow.MouseY >=35 And GraphicsWindow.MouseY <=55 Then
        dx= "two"
        TextWindow.Write (dx)
      EndIf
        if GraphicsWindow.MouseX >=15 and GraphicsWindow.MouseX <=135 And GraphicsWindow.MouseY >=55 And GraphicsWindow.MouseY <=75 Then
          dx= "three"
        TextWindow.Write (dx)
      EndIf
    EndSub

    Tuesday, February 15, 2011 7:49 PM