E50b section, week of April 5 1999
Alix Marchandise-Franquet
PROBLEM SET 3: a record management system
What is it?
Basically, you are keeping track of a collection of similar objects (ex: books, CDs...). The collection is stored in a file and you "load" the data into an array when you run the program, modify the data, store it back into the file to save the changes permanently.
The requirements:
The data: at least 4 fields defined in a class with the following types
- 1 numeric
- 1 character string
- 1 user-defined enumerated type.
- 1 of your choice
You must be able to:
- access the various commands through a main menu
- everything present in the bookdb example:
- writemenu,
- sort all/by criterion
- read/write file
- add/delete new object
- set the fields of an object
- selective editing of a particular record
- selective listing (i.e. extractBooks())
- data analysis and tabulation (compute mean, median, min, max of the numerical field(s))
Tips:
- study the bookdb example, and adapt the code to your record management system
- pseudo-code for extractBooks() - see lecture notes p.11
- there is a printout of bookdb.cc and bookdb.h in your course packet
- look at pp. 7-12 of the lecture notes unit 6 part 2
To set up 'make' and 'submit' for this assignment, do the following:
- make a directory named ps3 for your work in your home directory
- cd into it,
- copy your database files into it (if you've already started working...)
OR: copy the lecture files from ~libe50b/unit6 into it as follows:
cp ~libe50b/unit6/bookdb.h .
cp ~libe50b/unit6/bookdb.cc .
- name the program files 'database.cc' and 'database.h'
- copy the Makefile as follows:
cp ~libe50b/unit6/ps3_assign/Makefile .
...and don't forget that final ' dot' at the end!
now, 'make database' and 'make submit' will work! ...however, before using 'make submit', you'll have to create 'database.out', as usual!
GDB: GNU DEBUGGER
Learn how to use GDB by reading the tutorial in your course packet. Also, refer to the man page which you have in your course packet or you can access simply by typing man gdb at the prompt.
Basics:
You need to have the -g flag in the compile command
ex: g++ myprogram.cc -g -o myprogram
Once your program is compiled, you run the debugger gdb on the executable
ex: gdb myprogram
You get a prompt that looks like this: (gdb)
At the prompt, you may type several commands:
| (gdb) list | prints on the screen the lines surrounding the current line |
| (gdb)break n | the program will stop executing at line number n. You should set a breakpoint just before the part of the code where you think that something might wrong |
| (gdb)run |
start executing the program |
| (gdb)print var1 | print the value of the variable var1 |
| (gdb)n | next: execute the next line of source code |
| (gdb)s | step: suppose that the next line is a function call, if you used n
then you would execute the function call and move to the next line,
if you use step, then you execute the code in the function line by
line (i.e. you step into the function) |
| (gdb)finish | execute the program until the current function returns |
| (gdb)continue | continue the execution of the program until the next breakpoint or
the end of the program
|
| (gdb)quit | quit gdb |
Note:
- When you start gdb, you type gdb executablename, make sure you don't write the source file name...
- Your program must already compile to use gdb, it is not going to find your syntax errors...
- When trying to find the value of a variable, be careful to dereference pointers when you want to know the value of what they point to, otherwise you will get the address of what they point to (=> do print *ptr)
- You may use gdb with a core file to examine the states of the program when it crashed. Simply type gdb myprogram core at the ice prompt.