On Mon, 19 Feb 2001, Student X wrote: > Dear Dr. Moura, > > I have serious problems with both programming questions > in assignment 2. > > question 4) The only real task here is to use seekp and seekg > properly. I looked through several books, and only found seekg(offset, > mode) and seekp(offset,mode) which move to the offset position as > indicated by the mode in the text files. How can I access a particular > record using these two functions? How can I obtain student numbers > using seekp and seekg? Can I read all student numbers into main memory > and then do binary search? If not, how can I do binary search in the > text file? Seeking just allows you to move the "pointer to current position" of a file to a specified place. Then you are ready to read normally; to write you should move the put pointer with seekp. For use of seekg, seekp, tellg, you may look at a C++ book or the online notes pointed out by the course web page: http://www.icce.rug.nl/docs/cplusplus/ Look at section 12.3 in particular 12.3.4. Seeking is also described in the textbook, section 2.5. There the conceptual operation of moving to a position in the file is described, and in 2.5.2 comes the details of how to do it in C++. > Are > we supposed to create the tree to be traversed? Which method in the > assignment creates a huffman tree from freqfile? Which method traverses this > tree to decode one character? I have more questions, but this is > at least a starting point. If you did not obtain a precise explanation of what the parts of the code are and what you have to do in the assignment, come as soon as possible to my office hour - in 15 minutes I can get you started at the huffman code. I have seen several stduents today. My next office hour is on Tuesday (tomorrow) 1:30-3:30; the other one is on Friday. Answering the specific questions above: - the tree to be traversed has been already created when HuffmanObject was created. HuffmanDecoder is derived from HuffmanObject. So it can access its member "tree" which points to the root of the already created HuffmanTree (indeed HuffmanTree class is really a tree node) - methods to traverse the tree: HuffmanObject contains "tree" which is HuffmanTree* (pointer that points to the root of the huffmantree); a HuffmanTree (node in the tree) have public methods ("getLeft", "getRight", "getHuffmanCharacter", "isLeaf") which you will need to traverse the tree, get the character from the tree node, etc. - IBitStream is also important for your assignment, since this is the class you are going to use to read the input file bit-by-bit in your decoding. The whole decoding can fit in half a page. For help, you can e-mail the TA responsible for answering questions this week (Marc Raaphorst - mraaphorst@home.com); he is actually the person who wrote most of the huffman code, and is very knowledgeable in general. Anyone who has doubts about it, please come to my office hours. Lucia Moura