Thursday, July 30, 2009

C++ again!help again!?

I am makin this library program in c++. now the problem is that i dont know how to add the names of the book and the author into a file. this file on run time will display its contents like first the names of the authors. then when choosing an author name, all his or her books are displayed and the user can pick one up. now my problem is adding the names of the authors and his/her books.


Help!!!!!!

C++ again!help again!?
use XML, is an easy way to store information.





example:


you can write this directly into a XML file, or you can write them programly, then you read the XML file in C++ and display the information you want by selecting one or more node.


XmlDocument.Load("C:\myxmlfile.xml")





%26lt;?xml version="1.0" encoding="utf-8" ?%26gt;


%26lt;library%26gt;


%26lt;author%26gt;


%26lt;name%26gt;Jonathan Killerman%26lt;/name%26gt;


%26lt;books%26gt;


%26lt;book isbn="0-7472-6501-1"%26gt;The Murder Book%26lt;/book%26gt;


%26lt;book isbn="0-3454-5261-5"%26gt;Cone%26lt;/book%26gt;


%26lt;book isbn="0-3454-5256-9"%26gt;A Cold Heart%26lt;/book%26gt;


%26lt;/books%26gt;


%26lt;/author%26gt;


%26lt;author%26gt;


%26lt;name%26gt;Anna Quindlen%26lt;/name%26gt;


%26lt;books%26gt;


%26lt;book isbn="0-3755-0224-6"%26gt;Rise and Shine%26lt;/book%26gt;


%26lt;/books%26gt;


%26lt;/author%26gt;


%26lt;/library%26gt;








note: read about XML and it library and functions in C++
Reply:I suggest you to use a relational database like MSSQL, MS Access or MySql. This way you can set a master, detail relationship between two tables (authors, books). If you have to use a flat file. I urge you to define two structs one for authors and other for books (i.e. for book type use int ID; int authorID; char* bookName; ) then you can create two typed binary files where you can write instances of those structs.





Loren Soth


No comments:

Post a Comment