Monthly Archives: March 2006

Northwind Database Client Server Project

Here is a project I wrote last semester for a client/server systems class. Basically the professor assigned us a table from the Northwind Database. Our first assignment was to take that table, export it to a text file, then create a program to parse that text file and create a random access binary file. We were then to create a GUI that will read, write, and modify records from that binary file. I decided to write my project assignments in Python since that is my programming language of choice.

We spent half the semester working on this part of the project instead of learning anything related to client/server systems. Creating the GUI was extremely easy using Qt3 Designer and pyuic, so most of my work went into the reading and writing of the binary file.

Finally about 3/4 of the way though the semester we were assigned to modify our program to read, write, and modify the binary file over the network. The server contained the binary file, and the client connected to the server to get information from the binary file. This part of the program was actually fun to implement.

Our very last assignment was to merge our client and server with another students. I partnered with Eric Gaumer since he was also working in python. The following code is the result of our work. We took my GUI added the features his client needed and then added his server code to mine.

Simply start the server, then when you start the client enter the ip address where the server is located.

Code:

http://www.mattweber.org/files/nwdb.tar.gz

Note: PyQT and PyKDE are required to run this code.

Homework: Generate All Permutations

Here is a homework question from my Problem Solving Strategies class, along with my answer written as a python generator.

Design and code a decrease and conquer algorithm for generating all permutations of N elements in an array. Use the decrease-by-one method given in class where the parameters are: a prefix string, the number of elements whose permutations are to be concatenated with the prefix string, and the set of those elements. Turn in the code and the results for running it with a 4 element set containing A, B, C, and D.

def AllPermutations(elements, numElem=None, prefix=[]):
     if not numElem: numElem = len(elements)
     if numElem == 0:
         yield prefix
     else:
         for index in xrange(numElem):
             newPrefix = prefix[:]
             newPrefix.append(elements[index])
             newElements = elements[:index] + elements[index+1:]
             for perms in AllPermutations(newElements, numElem - 1, newPrefix):
                 yield perms

 if __name__ == ‘__main__‘:
     for perm in AllPermutations(list(’ABCD‘)):
         print perm

Files:
http://www.mattweber.org/files/perms.py