Help with writing class and imp them
-
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 implementationvoid 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 -
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 implementationvoid 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 differencethe code looks ok, except maybe for the
display
method; theshow_book
method will do what ? no, it is declared asvoid
, andcout
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
-
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 implementationvoid 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 differenceA 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