GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Sep-2008, 13:45
glacier glacier is offline
New Member
 
Join Date: Sep 2006
Posts: 19
glacier is an unknown quantity at this point

Question related to Class in C++


Hi there I have a problem in writing codes for books class my question is–

The Main Test Program The main function should: Declare an object of type Book Prompt the user for all property values for the book (all values should be stored in local variables declared in the main function).
Call the appropriate methods to set the Book's private data members Prompt the user for the number of books to be added to inventory. If the value entered is less than or equal to zero, continue to prompt the user for a value until the value is valid. Prompt the user for the number of books to remove from inventory. If the value entered is less than or equal to zero, continue to prompt the user for a value until the value is valid. If a „false‟ is returned from this function call, display an error message that the number of books exceeds the amount in inventory. Call the appropriate methods to display each of the properties of the book.
The class must contain the following private data members:
o Title (string)
o Author (string)
o ISBN (string)
o Publication year (integer)
o Publisher (string)
o Copies in inventory (integer)

so far I have done that my header file is here

CPP / C++ / C Code:
Class BOOK
{
Public:
    BOOK(const string & ,const string & , const string & , const string &, int , int);
    void set Title (const string &);
        string get Title () const;
    void set author (const string &);
        string get Author ()const;
    void set ISBN (const string &);
        string get ISBN ()const;
    void set Publication Year (int);
        int get Publication Year ()const;
    void set Publisher (const string &);
        string get Publisher ()const;
    void set copies in inventory(int);
        int get copies in inventory()const;
Private:
        string Title;
        string Author;
        string ISBN;
        int Publication Year;
        string Publisher;
        int copies in inventory;
};

Now I am confuse in how write the code for adding and removing books from inventory (If the value entered is less than or equal to zero, continue to prompt the user for a value until the value is valid. Prompt the user for the number of books to remove from inventory. If the value entered is less than or equal to zero, continue to prompt the user for a value until the value is valid. If a „false‟ is returned from this function call, display an error message that the number of books exceeds the amount in inventory.)
Last edited by admin : 16-Sep-2008 at 19:31. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 16-Sep-2008, 14:10
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Question related to Class in c++


Quote:
Originally Posted by glacier
so far I have done that my header file is here
CPP / C++ / C Code:
Class BOOK
{
Public:
    BOOK(const string & ,const string & , const string & , const string &, int , int);
    void set Title (const string &);
        string get Title () const;
    void set author (const string &);
        string get Author ()const;
    void set ISBN (const string &);
        string get ISBN ()const;
    void set Publication Year (int);
        int get Publication Year ()const;
    void set Publisher (const string &);
        string get Publisher ()const;
    void set copies in inventory(int);
        int get copies in inventory()const;
Private:
        string Title;
        string Author;
        string ISBN;
        int Publication Year;
        string Publisher;
        int copies in inventory;
};
Several corrections:
  • The keywords class, public, private have a specific case. The first letter cannot be capitalized & still denote these keywords.
  • Variable names such "copies in inventory" are not syntactically correct as spaces cannot be used within the name itself. Either concatenate all words together, or use underscores as a substitution.
  • Member function names cannot have spaces for the same reason.
  • When posting code, please place a [cpp] tag before, & [/cpp] afterwards such that the code will be formatted. Indentation will be preserved, & you will be making life simpler for readers who you are hoping will spend their time on answering your questions.
Quote:
Now I am confuse in how write the code for adding and removing books from inventory...
You may want to consider creating an array of type BOOK which will contain all books which have been entered thus far. If you use an array, you will need to ensure that the array is large enough to hold all anticipated books. You will also need to include code to stop insertions past the end of the array.

Creating a linked list would accomplish the same thing, plus not be constrained by the array size. You may or may not have covered this subject yet.

As for removal, you have get & set member functions which are used to initialize each book. When the copies in inventory reaches zero, set the title, author, etc. to empty strings.
Last edited by ocicat : 16-Sep-2008 at 14:49.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning a Struct to a separate class usmsci C++ Forum 9 07-Feb-2007 09:34
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Box Class, need help again :( TransformedBG C++ Forum 7 13-Nov-2006 16:11
a tester class and then some. postage Java Forum 1 06-May-2006 16:48
Opinion on my code and a c++ class question FlipNode C++ Forum 7 07-Feb-2006 09:15

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:07.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.