Classes needed to interface with External Sorting Visual Debugger:

To properly interface with the visual debugger, you will need to use the following objects in your lab:

  1. class Record - used to store each set of three input values. Relevant functions:
    	 	void setField1(int)  //set the value in field1 
    		int getField1() //return the value in field1
    		void setField2(int)
    		int getField2()
    		void setField3(int)
    		int getField3()
    
    	 Constructors:  Record()
    	 		Record(int field1, int field2, int field3)
    

  2. class File - used for file I/O. This class mimics the file system. You will declare your input file, output file, and scratch files to be of type File. You will need to read the actual input file (the input file on the command line) into the input file object and you will need to write the output file object out to the actual output file (the output file on the command line). The following two methods accomplish this task:
    	//read values from actual file 'filename' into array of Records
    		void readFromFile(char *filename)
    
    	//write contents of array of Records to actual file 'filename'
    		void writeFromFile(char *filename)
    

    In order to open or close a file you should use the following two methods:

    	// open a File for input ('i') or output ('o'). Must do prior
    	// to the Read and Write functions below, but not the
    	// readFromFile or writeFromFile functions above. Open 
    	// returns true if the open succeeds and false if the open fails.
    		bool Open(char)
    		
    	// closes a File. If File is opened for input, you must close
    	// it before opening it for output
    		bool Close()
    

    To read a record from a file or write a record to a file use the following two methods:

    	// Read is used with Files opened for input, and Write is used
    	// with Files opened for output. For the Read method you must
    	// provide the memory for Record--Read will *not* allocate it
    	// for you.
    
    		bool Read(Record *) //reads next record from File--returns
    		                    //true if a record was successfully read
    				    //and false if end of file was reached
    		bool Write(Record *) //writes next record to the File
    

    To create a new file, you can use the following constructor. The name parameter will be displayed in the visual debugger so that you can identify the file.

    	
    	Constructor:
    		File(char *name)
    

    To determine the total number of reads and writes from all files, you can use the following two methods:

            int getNumReads();
            int getNumWrites();
    

  3. class Array - used to hold an array of Records. This class stores pointers to Records so the relevant functions will be:
    	//used to set and get Records from the array at specific indexes
    		void setElem(int index, Record *record)
    		Record *getElem(int index)
    	Constructor:
    		Array(int size)  //size of the Record array
    

  4. class arrayFiles - used to hold an array of Files. This class stores pointers to Files. You will use this class to create your scratch file banks (i.e. input/output file banks) and your input and output files. Relevant functions:
    	//same as the Array class above, but for files
    		void setElem(int index, File *)
    		File *getElem(int index)
    
    	     Constructor:
    	     	arrayFiles(int size)  //size of the File array
    

Where to Find Things

The .h files for this lab can be found in /ruby/homes/ftp/pub/bvz/classes/cs302/labs/lab8 and the object files for this lab can be found in /ruby/homes/ftp/pub/bvz/classes/cs302/objs/. The relevant files are:

  1. classes.h contains the class declarations for Record, File, Array, and arrayFiles.

  2. classes.o is the object file that you will link with your driver program. Do not copy this object file to your directory.

  3. driver.o is the driver program that calls your external_sort procedure. Do not copy this object file to your directory.


Making the Visual Debugger Pause

In order to make the debugging environment pause during the execution of your program, you will need to call the following function:

pause(char *comment)

pause will cause your program to temporarily pause and allow you to visually inspect your program's data structures. The comment character string will be printed out in the visual debugger so that you know where you are in your code. Here is one example use of pause:

for (i = 0; i < 10; i++) {
   myarray.setElem(i, new File("myfile"));
   pause("creating files");
}