problem in classes in c++

Discussion in 'C++' started by namrata, Sep 17, 2008.

  1. namrata

    namrata New Member

    Joined:
    Jan 28, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi there I have a question regarding class my question is Create the specification and implementation files defining a „Book‟ class. The class should have member functions for setting the title, author, ISBN number, publication year, the publisher of a book and the number of copies currently in inventory. It should also include member functions for obtaining the title, author, ISBN number, publication year, the publisher of a book and the number of copies currently in inventory of a book. The member functions should not interact with the user of the program either by providing output or by getting input. Two additional member functions should be defined that will allow more copies of the book to be added to inventory and to allow copies of the book to be removed from inventory. If the amount to remove from inventory will result in a negative number of copies, do not adjust the number of copies and return a value of „false‟ to the caller. If the value is valid, adjust the number of copies accordingly and return a „true‟ to the caller.

    so far my code for header file, cpp file, and main functiuon are and so please all suggestions are welcome
    Code:
    class BOOK
    {
    public:
    X    BOOK(const string & ,const string & , const string & , const string &, int , int);
    X    void setTitle (const string &);
    X        string getTitle () const;
    X
    X    void setauthor (const string &);
    X        string getAuthor ()const;
    X
    X    void setISBN (const string &);
    X        string getISBN ()const;
    X
    X    void setPublicationYear (int);
    X        int getPublicationYear ()const;
    X
    X    void setPublisher (const string &);
    X        string getPublisher ()const;
    X
    X    void setcopiesininventory(int);
    X        int getcopiesininventory()const;
    X    void print() const;
    Xprivate:
    X        string Title;
    X        string Author;
    X        string ISBN;
    X        int PublicationYear;
    X        string Publisher;
    X        int copiesininventory;
    };
    
    cpp file:#include "book.h"
    X
    BOOK::BOOK(const string & Title ,const string & Author , const string & ISBN,
    X        int PublicationYear , const string &Publisher , int copiesininventory);
    X
    X
    {
    X    Title = TITLE;
    X    Author= AUTHOR;
    X    ISBN  = number;
    X    set PublicationYear();
    X    Publisher= PUBLISHER;
    X    set copiesininventory();
    }
    X
    void BOOK::set Title(const string & TITLE)
    {
    X   cout<<"enter the book title"<<endl;
    X   cin>>TITLE;
    X    Title=TITLE;
    }
    string BOOK::get Title()const
    {
    X    return title;
    }
    X
    void BOOK::set Author(const string & AUTHOR)
    {
    X    cout<<"enter the book title"<<endl;
    X    cin>>TITLE;
    X    Author=AUTHOR;
    }
    string BOOK::get Author()const
    {
    X        return Author;
    }
    void BOOK::set Publisher(const string & PUBLISHER)
    {
    X       Publisher = PUBLISHER;
    }
    string BOOK::get Publisher()const
    {
    X        return Publisher;
    }
    X
    void BOOK::set copiesininventory (int copies)
    {
    X      copiesininventory = copies ;
    }
    string BOOK::get copiesininventory()const
    {
    X        return copiesininventory  ;
    }
    X
    X
    void BOOK::print()const
    {
    X    cout<<\n"Title:"<< TITLE<<endl;
    X    cout<<\n"Author:"<< AUTHOR<<endl;
    X    cout<<\n"ISBN:"<< number<<endl;
    X    cout<<\n"PublicationYear:"<< PUBLICATIONYEAR<<endl;
    X    cout<<\n"Publisher:"<< PUBLISHER<<endl;
    X    cout<<\n"copiesininventory:"<< copies<<endl;
    X
    }
    main function :
    void BOOK::set Publisher(const string & PUBLISHER)
    {
    X       Publisher = PUBLISHER;
    }
    string BOOK::get Publisher()const
    {
    X        return Publisher;
    }
    X
    void BOOK::set copiesininventory (int copies)
    {
    X      copiesininventory = copies ;
    }
    string BOOK::get copiesininventory()const
    {
    X        return copiesininventory  ;
    }
    X
    X
    void BOOK::print()const
    {
    X    cout<<\n"Title:"<< TITLE<<endl;
    X    cout<<\n"Author:"<< AUTHOR<<endl;
    X    cout<<\n"ISBN:"<< number<<endl;
    X    cout<<\n"PublicationYear:"<< PUBLICATIONYEAR<<endl;
    X    cout<<\n"Publisher:"<< PUBLISHER<<endl;
    X    cout<<\n"copiesininventory:"<< copies<<endl;
    X
    }
    X
     
    Last edited by a moderator: Sep 17, 2008
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What help do you want? Does the code do what you want? If not what exactly does it do wrong and on what line?

    Obviously nobody can use the code you've posted without some tedious and unnecessary editing of leading X's -- what is the point of that, and of not using a CODE block?

    void BOOK::set Publisher(const string & PUBLISHER) is not the main function. int main(int argc, char *argv[]) is the main function, and is not present.
     
  3. oogabooga

    oogabooga New Member

    Joined:
    Jan 9, 2008
    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    Not only that, but it looks like a homework problem dump.
    At least try the problem yourself before posting.
    (The X's kill me! )
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice