To properly interface with the visual debugger, you will need to use the following objects in your lab:
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)
//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();
//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
//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
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:
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");
}