View Full Version : C++ Help

26th January 2007, 04:33 PM
Alright so I have this assignment due and part of it requires reading from and writting to a binary database. I need to be able to add, edit, or delete an entry to the database. Each entry is a struct (called struct Book). Here's what the struct looks like and what each entry must contain;

const int TITLE_LENGTH = 200;
const int AUTHOR_LENGTH = 100;
const int ISBN_LENGTH = 20;

struct Book
bool deleted;
int number;
char title[TITLE_LENGTH+1];
char isbn[ISBN_LENGTH+1];
char author[AUTHOR_LENGTH+1];
int copies;

So yeah. How would I go about adding one of these entries to the database, edit one, or delete one? My assignment says that the program assigns a record number (rec #) to each entry. The edit command will prompt the user to enter the rec# to display the book's info.

I was in Mexico for the week we went over this stuff...

27th January 2007, 11:34 AM
there's a number of ways to do this... if you're implementing a search functino you'll need to use either a tree or a hash table. If not just use the simplest datastructure possible... a vector.

#include <vector>

class myDatabase {
vector <struct Book> myBooks;
int totalentries;
myDatabase() { totalentries = 0; }
bool addBook (const struct Book &aBook) {

28th January 2007, 12:24 PM
binary database? you mean like binary tree? 2-3, red-black, 2-3-4?
Well you should ask one of your classmates for help. I have a similar project in Java which puts books with authors into either ordered vector or un-ordered vector and sorts them by author or title. if you care to look at java code, let me know.