unique book id in a library database

I am writing a library database management software.
I want to make sure that the the book id of one book won't be equal to book id of another book.
This is similar to the primary key from sql.
Is there any way to ensure that?



you have a list of books and a newbook

WHILE list contains newbook
  modify newbook.id

append newbook to list
Last edited on
1
2
3
while(newBook.id is already contained in the data base)
    give newBook a unique idea
add newBook to database
Could any of you give me some actual code.
I am a beginner and even though i have studied till inheritance and stuff..I don't have any practice in that area.
Any help appreciated.
Pl write a comment for each code line..
std::map
Okay! working on it...i think std::map might be the fix.
I am writing a library database management software.

Sounds like reinventing wheel.
I am a beginner ...I don't have any practice in that area.
Pl write a comment for each code line.

Homework then. Purpose of homework is to learn by doing. Spoon-feeding code does not help much in the process; it actually makes things worse (IMHO).

You are creating a database within the C++ program. You must have some vision about how to do it. What is in your "one book"? How are you storing multiple books now? Why is there an book ID? What will it be used for? What are the "management operations" that you have to implement?

1)
Homework then. Purpose of homework is to learn by doing

Its not homework. I am doing it because i saw it as a project on some website.But i do understand what you are trying to say.

2)
You are creating a database within the C++ program. You must have some vision about how to do it.

I am creating the database by using fstream class. I will create one file each for each book entered in the library by the librarian.

3)
How are you storing multiple books now?

I am using a structure of book, like so:
1
2
3
4
5
6
7
struct book
{
string name;
string author;
string id;
int qty
}bk[1000];

So i will store the name of the first book by using bk[0].name. Get it?

4)
Why is there an book ID? What will it be used for?

The book id is there, so that the librarian can issue the correct book to the student. In case there are two books with the same name but differing by the year of publication, then the librarian can differentiate between them.

5)
What are the "management operations" that you have to implement?

I librarian can:
a. Add a student to the library(1 year subscription)
b. Remove a student from the library(if subscription not renewed)
c. Add a book to the library.
d. Remove a book from the library.
e. Issue a book to a student.
f. Return a book(by the student).

When the librarian is issuing a book i want him/her to be able to search the book by any substring that forms a part of the book's name, author,year,edition.
And i will return multiple entries with their book name, author name and book id.
Then i will ask the librarian one final time for the book code of the book. And thus i will issue that book with the matching book id.

6)
Spoon-feeding code does not help much in the process; it actually makes things worse (IMHO).

Thanks for the tip. I am new to c++ and am trying out a lot of new ways of learning to code, and to make the learning process interesting.
Last edited on
The book id is there, so that the librarian can issue the correct book to the student. In case there are two books with the same name but differing by the year of publication, then the librarian can differentiate between them.

Useful variable names help us understand what your trying to do OP. If you mean the ISBN then just call the variable that.

It sounds like you also need a class to represent a student. Probably just a name, a date of subscription and a container for the books that they have out from the sound of it. You could then store these in an std::vector to make adding and removing them simpler for yourself.

When the librarian is issuing a book i want him/her to be able to search the book by any substring that forms a part of the book's name, author,year,edition.

That would be what is called a regex. Get the aspirin ready.
Get the aspirin ready.

hahahaha thanks for the help.

Working on regex...
Topic archived. No new replies allowed.