Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

July, 2008

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    The Four Digit Problem

    • 8 Comments

    So I was remembering a piece of code I had to write once. Honestly I don’t remember exactly why I had to write it. I think it may have been part of a set of patterned data for some test software though. In any case the problem was to generate a four digit random number with no duplicated digits. Now there are lots of ways to do this. A simple brute force way is below.

        Function Digit4() As Integer
    
            Dim i(4) As Integer
            i(0) = r.Next(1, 9)
            Do
                i(1) = r.Next(0, 9)
            Loop Until i(1) <> i(0)
            Do
                i(2) = r.Next(0, 9)
            Loop Until i(2) <> i(0) And i(2) <> i(1)
            Do
                i(3) = r.Next(0, 9)
            Loop Until i(3) <> i(0) And i(3) <> i(1) And i(3) <> i(2)
            Return i(0) * 1000 + i(1) * 100 + i(2) * 10 + i(3)
        End Function

    Yes I left out the comments to save space. (That’s my story and I’m sticking to it) The way it works is to pick a single random digit, then pick a second one looping back to pick a new one if by some chance the digit drawn is the same as the one previously checked. This is done again except that the next one has two numbers to compare against and the final number has three numbers to compare against. It works (I tested it) but it doesn’t scale well.

    The task I would assign students is to come up with at least two other ways to solve this problem that are more scalable and then compare them all for performance. I might hint at the word “recursion” which I’ve been thinking a lot about lately. This sample code is in Visual Basic because that is my hack something together language of choice. Converting it to other languages is another exercise left to the student.

    Two notes: The best part about this post is all the discussion in the comments so don't miss them. Second is that the "solution" I entered is what students often come up with and not what I would use is a real application. I wanted to get some discussion going and that seems to have happened.

    Edit: 12/2/2009 Bart Massey of Portland State University has a very helpful reply post called Random non-repeating sequences that I highly recommend. I appreciate his letting me know about it as I think it is an interesting solution that is well explained. So please go read it.
  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Teaching Flowcharts – Have the Computer Draw One

    • 4 Comments

    Last week the Microsoft Visual Studio Middle School Toy was announced and I wrote about it in my blog. Today I wanted to give people a taste of what one of the features – the Visual Programming Flow Chart - looks like. It’s really pretty simple to use. Point the mouse at a function/method name and right click for the context menu like this and select Generate flow chart

    genflow

    The result will look something like this:

    Capture

    The color bars on the right let the user change the color coding for different things like loops, if statements, Try statements, etc. The resulting image can be saved as a JPEG file. This lets the user include it as documentation if they want.

    This is not a super serious professional tool BTW. It seems to do a pretty good job for the student level modules I’ve tried it with though. I can see where it could be very useful for students because it shows what the logic of the code actually is rather than what the student might think it is. Note that right now it only works with C# – sorry about that. I’ve already started bugging people about Visual Basic support. :-)

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Microsoft Visual Studio Middle School Power Toy 1.0

    • 7 Comments

    The Microsoft Visual Studio Middle School Power Toy 1.0 was originally created by Microsoft China to help meet the curriculum needs for teaching programming in that country. According to regulations/policies of China’s Ministry of Education (MOE) almost all Chinese high school students need to learn computer programming. Bring that up at the next meeting you attend where the need for programming/computer science is questioned! But I digress. This week the English language version of these tools were made available.

    The Power Toy is a set of five tools that add into Visual Studio to help beginners. These tools are a free download. Three of the five work equally well with both Visual Basic and C#. Two of them (the assistant class designer and flow chart creator) only work with C# at least for now. The following descriptions comes from the download page. I plan to have individual posts on each of these tools in the very near future.

    • The Visual Sort Designer Control is a supplementary teaching tool developed to help middle school students learn the basic concepts, algorithms, and implementations of popular computer sorting algorithms. It supports bubble and insertion sorting. The control generates initial values automatically and demonstrates intermediate states in the sorting process. It also generates sorting source code for both Visual Basic and C#.
    • The Visual Search Designer Control is a teaching tool developed to help middle school students learn the basic concepts, algorithms, and implementations of popular data search algorithms. It supports binary and sequential searches. The control generates initial values automatically and demonstrates intermediate states in the searching process. It also generates source code for both Visual Basic and C#.
    • The Visual Declarative Designer is an intuitive variable declaration tool designed for novice programmers. During the coding process the student can declare variables of various types and generate the corresponding source code. Visual Variable Declarative Designer provides a visual approach to variable declaration. Teachers in the Information Technology (IT) field can use this designer to teach students the basic concepts of variable declaration and naming, variable types, access modifiers, and initial values.
    • The Assistant Class Designer is a visual class designer intended for novice programmers such as middle school students. During the design process, students can easily add classes, properties, methods and events. The designer also generates source code that can be inserted into a project and modified as needed. By using this class designer and code generator, complicated classes can be easily created and configured. The Assistant Class Designer provides an intuitive approach to designing classes and helps students to understand key object-oriented programming concepts such as classes, encapsulation, inheritance, and polymorphism.
    • Visual Programming Flow Chart is a supplementary teaching tool designed to help students understand program control flow. It generates flow charts for functions and saves them in the JPG picture format. This tool is easily activated from the Visual Studio Integrated Development Environment (IDE) by simply right-clicking on a function name and choosing “Generate flow chart…” from the context menu. The resulting flowchart can be customized by changing its colors and other effects. This visual tool provides an intuitive way to explore source code, to examine its control flow, and to identify logic errors.
Page 1 of 8 (22 items) 12345»