Solved

c++ file handling a simple library information system

Posted on 2010-11-20
13
1,335 Views
Last Modified: 2012-05-10
can you provide me a simple program in c++ providing insert,update,delete and show the books?
the records should be kept in a file on the disk.
0
Comment
Question by:Dinesh Kumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 34179042
Insert into what ? Update what ? Delete what ?

Are you talking about interaction with a database ? Which database ?
0
 
LVL 9

Expert Comment

by:masheik
ID: 34179177
Hi,

   If i understand your question correctly, you can use linked lists to create a database dynamically and store database of what you have entered and retrieve the same,
  You need to go through what are linked lists , refer a good book about linked lists
 the following links can help to learn the basics,
c++:
-----
http://www.functionx.com/cpp/articles/linkedlist.htm
http://www.cplusplus.com/doc/tutorial/files/
c:
---
http://www.cprogramming.com/tutorial/lesson15.html
http://www.codeproject.com/KB/cpp/linked_list.aspx

  Create a linked list structre which all the datas you have mentioned,
struct libraryDB
{
  int bookNum;
 char *authName;
 etc..
 struct libraryDB *nextlibraryDB; //link to the structure
}

add function to add,delete ,insert,sort the linked lists

 try that all mentioned and comeback if you have issue ,we experts are here to help you
0
 

Author Comment

by:Dinesh Kumar
ID: 34179187
I want to keeps books' information like title, price, accession number in a file. so i need to use the file handling in c++. suppose I need to update the title of the book then i will open the file through c++ code in write only mode and will go to that specific records by using some id say accession number and update that particular book information.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Infinity08
ID: 34179218
Is this for professional purposes, a personal project, an academic assignment ?

Depending on what this is for, the answer will be very different. So a bit more background information would be useful.

How many books do you want to store ? And how do you want to access that information ? Is the access local only, or do you need access from different locations ? What kind of access do you need precisely ? Etc.
0
 

Author Comment

by:Dinesh Kumar
ID: 34179250
its for academic assignment.  every book will be having its own unique id. it will be used on a single system.
0
 
LVL 9

Accepted Solution

by:
masheik earned 267 total points
ID: 34179275
Ok..Read the File handling operations in C++,

How to read,write,append, remove,etc,

create a structure about books information and store data into it


/* Example Store data to file */

#include <iostream>
#include <fstream>
using namespace std;

struct bookInfo
{

 char title[255];
 unsigned int  price;
 int accessNum;
};

int main ()
{
  ofstream myfile ("example.txt",ios::out);
  bookInfo bInfo;
  cout <<"Enter title: ";
  cin  >>  bInfo.title ;
  cout <<"Enter price: ";
  cin  >> bInfo.price;
  cout <<"Enter accessNum:";
  cin  >> bInfo.accessNum;
  if (myfile.is_open())
  {
    myfile << bInfo.title ;
    myfile << "\t" ;
    myfile << bInfo.price;
      myfile << "\t" ;
    myfile << bInfo.accessNum;
      myfile << "\n" ;

    myfile.close();
  }
  else cout << "Unable to open file";
  return 0;
}
0
 

Author Comment

by:Dinesh Kumar
ID: 34182130
Masheik, I am working on following. Actually i just  noticed that I need to use inheritance concept.

How can i use inheritance in following problem?


Make a menu-driven project to create a library information system containing the following information for the proper storage and processing of books in the library.
(a) Accession Number                  (b) Name of the Author
(c) Title of the Book                  (d) Publisher Name
(e) Publisher Name                  (f) Cost of the Book
(g) Year of Publication            (h) Number of pages
Use the of inheritance

Menus:
1) Add a new Book
2) Display all the books
3) Delete a Book Details (Soft Delete only)
4) Search a book using Accession Number

the code i attached is to be still modified.
Article583-2792010.zip
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 34182272
>> its for academic assignment.  every book will be having its own unique id. it will be used on a single system.

I would start by implementing the "Add a new Book" feature. You'd need a Book class that represents a book. Its data members should describe all specifics of the book (title, author, year, etc.). And it should have some methods for manipulating the book (nothing special probably - just provide ways of retrieving and modifying the data members).

You can then write some code that asks the user to enter the details for a new book. While the details are being entered, you set them in a new instance of the Book class (via its constructor possibly). Once the Book instance has been filled, you can write some code that writes the information for the book to a file (or : that serializes a Book instance to a file).

When you have that, you can write code that retrieves a book from the file, creates a new Book instance for it, and keeps it in memory, where it can be manipulated.

The next step would be to have an in-memory data structure that can hold many Book instances, and provides a convenient way for performing lookup. Which data structure you choose will probably depend on what data structures you have already worked with during your classes.

You can then adapt your code to read multiple books from a file, and store them in the data structure. And to be able to write all books from the data structure back to a file.

All that is left after this is done, is some small features, which you can then add one by one.


Since your original question was about file handling in C++, I recommend that you have a look at this tutorial to guide you :

        http://www.cplusplus.com/doc/tutorial/files/
0
 

Author Comment

by:Dinesh Kumar
ID: 34182756
and how can we use the concept of inheritance?
0
 
LVL 9

Assisted Solution

by:masheik
masheik earned 267 total points
ID: 34183069
Okay inheritance is the process of creating new classes from a base class .go thru inheritance concepts as well.                           In your case you need to add cool entry remove book entry display all the books and search for a book
   
Say you have written only add and remove book methods in your base class and it is well tested /working fine
But you need to have search and display methods  
Create a derived class with using the base class you have written and add display ,search methods to the derived class this way you can use inheritance concepts
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 133 total points
ID: 34183428
>> and how can we use the concept of inheritance?

I can't think of a reasonable way of using inheritance for this - except maybe if you want to deal with other things besides books too (cd's, dvd's, etc. maybe).

How does the teacher say you should be using inheritance ?
0
 

Author Closing Comment

by:Dinesh Kumar
ID: 34184042
I did not find the complete solution.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 34184225
>> I did not find the complete solution.

Then why didn't you ask us for clarification about the parts that haven't been addressed ? Why didn't you respond to our last posts ?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question