Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with writing class and imp them

Help with writing class and imp them

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestionlearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bhangie
    wrote on last edited by
    #1

    Hi there I would like some help with this plz if posible. I need to write the following class book and it's implementation, this is what i have done. class book { public: book(const string title,const author,const char isbn[10]); void show_book(); private: const string T; const string A; const char I; }; Ok,the library class must be able to add books. some other stuff aswell. class library { public: library() void add_book(); void display()const; //display all the books on record private: vector<book *> book_list; }; The library class implementation void library::add_book() { book * new_book = new book("Danger","Mike","102- RT34"); book_list.push_back(new_book); } void library::display() const { for(int i = 0; i < book_list.size(); i++) { cout << book_list[i]->show_book() << "\n"; } } First is there any thing wrong with this code? Secondly is there a beter way of writing this code? Thirdly how would i go about adding books at runtime and iterate thru the vector to find a specific book? excuse the english, Thanks in advance I Never said you should like me.I say be yourself, and make a difference

    M B 2 Replies Last reply
    0
    • B bhangie

      Hi there I would like some help with this plz if posible. I need to write the following class book and it's implementation, this is what i have done. class book { public: book(const string title,const author,const char isbn[10]); void show_book(); private: const string T; const string A; const char I; }; Ok,the library class must be able to add books. some other stuff aswell. class library { public: library() void add_book(); void display()const; //display all the books on record private: vector<book *> book_list; }; The library class implementation void library::add_book() { book * new_book = new book("Danger","Mike","102- RT34"); book_list.push_back(new_book); } void library::display() const { for(int i = 0; i < book_list.size(); i++) { cout << book_list[i]->show_book() << "\n"; } } First is there any thing wrong with this code? Secondly is there a beter way of writing this code? Thirdly how would i go about adding books at runtime and iterate thru the vector to find a specific book? excuse the english, Thanks in advance I Never said you should like me.I say be yourself, and make a difference

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      the code looks ok, except maybe for the display method; the show_book method will do what ? no, it is declared as void, and cout will do nothing for it; or might not compile. to find a book, you need to compare somthing, when iterating the list, you can compare one it with the search criteria. for example ( pseudo code ) CString sCriteriaTitle; for(int i = 0; i < book_list.size(); i++) { if ( sCriteriaTitle.Compare( book_list[i]->get_book_title() ) == 0) { bFound = true; } } }


      Maximilien Lincourt Your Head A Splode - Strong Bad

      1 Reply Last reply
      0
      • B bhangie

        Hi there I would like some help with this plz if posible. I need to write the following class book and it's implementation, this is what i have done. class book { public: book(const string title,const author,const char isbn[10]); void show_book(); private: const string T; const string A; const char I; }; Ok,the library class must be able to add books. some other stuff aswell. class library { public: library() void add_book(); void display()const; //display all the books on record private: vector<book *> book_list; }; The library class implementation void library::add_book() { book * new_book = new book("Danger","Mike","102- RT34"); book_list.push_back(new_book); } void library::display() const { for(int i = 0; i < book_list.size(); i++) { cout << book_list[i]->show_book() << "\n"; } } First is there any thing wrong with this code? Secondly is there a beter way of writing this code? Thirdly how would i go about adding books at runtime and iterate thru the vector to find a specific book? excuse the english, Thanks in advance I Never said you should like me.I say be yourself, and make a difference

        B Offline
        B Offline
        BaldwinMartin
        wrote on last edited by
        #3

        A Class is just a structure. Can youm write a structure with all these elements? "Naked we come and bruised we go." - James Douglas Morrison Best Wishes, ez_way

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups