"Briton" <br******@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
New to c++ and OOP. I need help
I'm trying to code a sample library system using arrays of objects that
will do the following:
-Add a book to the library
-Remove a book from the library
-Search for a specific book
-List books on a given subject or author in alphabetical order
I'm totally buffed. I don't even know where to start.
All help will be appreciated
Well, look at this and identify all the objects.
"add a book to the library"
We have a book
We have a library.
"remove a book from the library"
nothign new needed here.
"Search for a specific book"
Okay, we'll need to be able to search the books.
"List books on a given subject or author in alphabetical order"
Hmm.. need to be indexed at least alphabetcially.
So, it looks like we want to have books in an ordered list.
So first, create your book. What do books have? From your work you see
they have:
"given subject"
"author"
"alphabetical order"
a subject
an author
a title
you might want to include the isbn even though this isn't required.
So, create your book class with those variables.
Test it.
Now, you need a way to add this book to the library, which will be some type
of container, which we need to decide on.
We can use a vector, but a vector is unsorted naturally.
We can use a map, which is sorted, but only has one key.
If there is a container that allows more than one key for a collection, I
dont' know what it is. There may very well be one.
So I would probably stick it on in a vector.
Do the searches manually, which is rather slow (iterate through all the
entries searching).
Build a vector for the result and search it.
You may notice, I haven't given you a single line of code. That's right,
this is homework. Maybe someone else has a better solution than a vector
though, if someone does it would be great.