C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 23rd, 2008, 06:46 AM
!makes_sense !makes_sense is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 7 !makes_sense User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 29 m 19 sec
Reputation Power: 0
Book Cataloging System Program

I need to write a program that manages a book catalog. Maximum books that can be held are 500. Book will hold following fields of information: ISBN, author's last name, first name, book title, year of publication, and price.

My instructor requires us to use C++ classes to implement and utilize abstract data types: Book and Catalog.

Now, I don't seem to understand what c++ classes is and what he means by abstract data types.

I thought I will declare the book to be a struct data type and the catalog will be an array of books with the maximum size of 500.

Does that sound right?

Furthermore, we need to be able to add a book to the catalog, validate the book by isbn(already know how to do that), delete an existing book and display the entire catalog with all books in alphabetical order.

Any ideas on how to approach this problem.

Reply With Quote
  #2  
Old May 23rd, 2008, 10:41 AM
Bobidybob's Avatar
Bobidybob Bobidybob is offline
Contributing Abuser
Click here for more information
 
Join Date: Apr 2007
Location: Starkville, MS
Posts: 336 Bobidybob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 15 h 51 m 40 sec
Reputation Power: 12
Send a message via AIM to Bobidybob
a class and a struct are 2 different things, though very similar. Think of a struct as a butter knife and a class as a Swiss Army knife complete with 2-way walky-talky, 32 inch plasma screen, and built in port-o-loo. sure you can conquer swizterland wielding either, but one is just more convenient and versatile.

an abstract datatype is basically any datatype that you created using said butter knife or swiss army knife. so if you made a struct or class called Chickybow, that would be an abstract datatype and could be declared like so:

Code:
 int x;                   //normal datatype called 'x'
 Chickybow wow;    //abstract datatype called 'wow'


as far as the significant differences between classes and structs, i would suggest an online tutorial or the textbook you probably are learning out of. Unless of course someone else on here wants to tackle the job

oh, and you could probably have some kind of AddBook(), RemoveBook() function that removes a book contained in a class member array based on ISBN passed or something like that. cheers!
__________________

Last edited by Bobidybob : May 23rd, 2008 at 10:43 AM.

Reply With Quote
  #3  
Old May 24th, 2008, 09:14 PM
!makes_sense !makes_sense is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 7 !makes_sense User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 29 m 19 sec
Reputation Power: 0
Thanks for the input.

I am writing this program step by step.

The first step is to be able to ask the user for book code, author's first and last name, title, year of publication and price.

Here is the programming assignment:


Book Cataloging System



Write a program to manage a Book Catalog. The catalog would contain a collection of books (maximum of 500), with following fields of information: book code (unique for each book; refer to assignment #3 for more info on this), authorís last name, authorís first name, book title, year of publication and price. The book catalog should use a file for storing the information on books.



You must use C++ Classes to implement and utilize an abstract data types: Book and Catalog



The information in the file is sorted alphabetically by title of the book, with a tab separating each piece of information about the book, with one bookís information per line. Refer to sample file: booklist.txt for more details.



The program should have the following features:



1. The program should allow the user to add a new book to the catalog. Use this feature to initially create the book catalog. The program should ask for the required information and then add the book to the catalog, only if there is no other book with the same code in the catalog.



2. Validate the book code; Make use your code from programming assignment #3 for this part. If the book code is not valid, an appropriate error message should be displayed and the book should not be added to the catalog.



3. The program should allow user to find a book in the catalog, given one of the following: author first name or last name or the book code. If the book is found, all the information about the book should be displayed. If the book is not found, an appropriate message should be displayed.



4. The program should allow you to delete an existing book from the catalog.



5. The program should have an option to display all the current books in the catalog. This should display the books sorted on their titles (in alphabetical order).



6. The program should have a menu driven interface to allow users to select one of the options to perform the above tasks. The program should display appropriate messages to the user for each operation, successful or not.



7. When exiting, the program should save the book catalog to file, taking in to account any of the above changes, for future use.




I can ask user this info and write this to a file. The problem is when I ask user to enter information about another book, the previous entry gets overwritten and is obviously not saved. How do I save the previous entry.

Reply With Quote
  #4  
Old May 25th, 2008, 01:48 AM
!makes_sense !makes_sense is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 7 !makes_sense User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 29 m 19 sec
Reputation Power: 0
so far I have been able to write only one book information, i tried writing more than one using a for loop, with count being 2, the first entry was alright, but the other two were strange.

output:

157231866x koffman EB C++ 2004 50

-858993460 -1.07374e+008

-858993460 -1.07374e+008

Reply With Quote
  #5  
Old May 26th, 2008, 07:37 AM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
Bull-o-meter triggered:
"Think of a struct as a butter knife and a class as a Swiss Army knife"

The only difference between a struct and a class is wether the first elements will be public (struct) or private (class) if the programmer does not insert that section marker.

Of the two, struct are often associated with C, where all it can do is hold be a group of variables. That's where the misunderstanding came from.

C++ added
-member functions
-virtual member functions
-access control (public/protected/private)
-operator overloading
to struct (and its new-born twin class).

(For more details read Design&Evolution of C++)



>Now, I don't seem to understand what c++ classes is and what he means by abstract data types.

If you really don't know this, it's either or both of
-You've been slacking (includes catching up after a forced absence)
-Your teacher hasn't been doing his job (includes inconsistencies, not clearing up misunderstandings)

If you still don't understand it, try to explain what you do know even if it doesn't make sense. Spotting the error or misunderstanding is easier that way.

Last edited by MaHuJa : May 26th, 2008 at 07:40 AM.

Reply With Quote
  #6  
Old May 26th, 2008, 08:17 AM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
>Now, I don't seem to understand what c++ classes is and what he means by abstract data types.

Quote:
Originally Posted by google define: abstract data type
A type whose implementation details are hidden and can only be handled using the publicly accessible operations provided for it. ...
www.cmis.brighton.ac.uk/~je/adacraft/glossary.htm

A mathematical model that includes a structure for storing data and operations that can be performed on that data. Common abstract data types include sets, trees, and heaps.
www.lnf.infn.it/computing/doc/aixcxx/html/glossary/a.htm

A specification of a type by giving only the operations that may be applied to values of that type (and, often, some properties of those operations). The term means much the same as interface but is used particularly when specifying data structures.
www.cs.ucc.ie/~dgb/courses/swd/glossary.html

a data type that specifies the logical properties without the implementation details
www.course.com/downloads/computerscience/malikcpp3e/keyterms12.cfm

In computing, an abstract data type (ADT) is a specification of a set of data and the set of operations that can be performed on the data. Such a data type is abstract in the sense that it is independent of various concrete implementations. ...
en.wikipedia.org/wiki/Abstract data type



For example,
Code:
class NON_abstract {
public:
  string ISBN;
  string author_lastname;
  string author_firstname;
  string title;
};

Is not abstract. The caller has to do everything (-deity- forbid actually forgetting to do the isbn validation... yet guess what; we're only human.) and is involved in every little detail of how the class works.

Code:
class abstract {
  string ISBN;
  //...
public:
  string get_isbn() const { return ISBN; }
  bool set_isbn(string);    // return false if successful
};
bool abstract::set_isbn(string s) {
  // Validate the ISBN here
    // Bad: return true;
  // Good:
  ISBN=s; return false;
}


(Feel free to ignore that const, I just add it for completeness.)

Perhaps there will even be a function like
bool Book::set_all (string isbn, string author_last, string author_first, string title);


The book does not have any chance to verify the ISBN as unique, of course, so that belongs to the Catalog class.

The catalog class, unabstracted, would perhaps be something like
class unab_catalog { public: Book b[500] };
Which means the client code has to implement all things like searching etc himself.

Code:
class catalog {
  // ... lots of stuff the client code doesn't care about ("implementation")
public:  // ("interface")
  Book get_isbn();  
  bool add_book(Book); // Does the unique ISBN check
  // etc
};


Some future version of the code could add an index lookup for get_isbn without touching the interface. Nothing needs to be done to the client code, which still gets a speed increase.

Searching for author/title etc where they're not guaranteed to be unique, has its own series of headaches that should be solved; usually in the form of an index or iterator value getting passed back and forth through the interface; the type of this value should then usually be given through a typedef. -- But this is a beginner exercise, isn't it?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Book Cataloging System


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap