![]() |
| ||
| Urgent:need Help Hi I have been given a assignment of making a "inventory control program of a book store in c++" i have done all the parts except for two 1. I have to delete a record from the file (i am using fstream and saving the file i need the piece of code to delete the particular record). 2 . i have to sell a book but when ever i subtract something from the record a new record gets created and the problem becomes harder. this the program #include<iostream.h> |
| ||
| Re: Urgent:need Help please don't name your threads like this anymore. Urgent::need help is just plain rude. It implies your thread is more important than others, when this forum prioritizes help requests on a first come, first-served basis. |
| ||
| Re: Urgent:need Help On the 'new record' issue, everywhere else you use the ISBN as an index into the file. Yet when you write a new record, you have opened the file in 'append' mode so the write happens at the end of the file. Unless you add records in ISBN order, this won't work. Speaking of ISBN, that's some number assigned by the publisher, isn't it? For file positions you probably want a number that is generally in the range 0..n so you don't have file waste. If ISBN's are like '17750294' you are going to have a massive file with a ton of dead space in it if you use the ISBN as a record number. Alternatives would be to read the entire file to find the entered ISBN, or to maintain an array in RAM of the ISBN's in the file with their corresponding file position or record index. You would read the file once at startup to build this in-ram list and then maintain it as you go. OR you could have a second file with ISBN's in it that might be faster to read than the entire book file. Getting more sophisticated, you could investigate an indexing method like BTrees (look it up in Google) and build a 'sorted' index file. Since the records are in this specific order, though, a 'delete' could be as simple as setting the quantity on hand to 0 or you could write nulls/spaces into the record, or if the record needs to be removed entirely, you might have to COPY the file over to a new file, minus this record, and then delete the original and rename the copy. |
| ||
| Re: Urgent:need Help Quote:
bit of sample code: for(int i = 0; i < number_of_records; i++) |
| All times are GMT -4. The time now is 4:15 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC