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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. I can't display book and borrower's details

I can't display book and borrower's details

Scheduled Pinned Locked Moved C / C++ / MFC
databasealgorithmsdata-structureshelplearning
2 Posts 1 Posters 2 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.
  • G Offline
    G Offline
    grscot
    wrote on last edited by
    #1

    Dear all,
    I can't borrow a book even though the code does not have any error. When I try to display the book details along with the member's name (in case the member has borrowed the book), I can't display the member's name, but only the book details and a message: "no member has borrowed a book".

    Though the code works fine when I have one book and one member, but now that I'm using an array of books and members it doesn't work.

    The code that displays the book and the member's name when I have 1 book and 1 member is:
    void Book::display(Member* borrower) { cout<<"Book title and author are: "<<this->bookDetails<<"."<<endl; if (borrower) cout<<"The member's name is: "<<borrower->get_Data()/*get_name()*/<<"."<<endl; else cout<<"No member has borrowed a book."<<endl; }

    char* get_Data(){return this->name;}

    returns the member's full name, entered in the constructor

    I have an associationlist that holds pointers to associations. Each association has two pointers, one to a book object and the other to the member object.

    class AssociationList { public: //It initialises all slots in the associationlist array to zero. AssociationList(); /* It searches the associationlist, if book is found then returns the member that is connected with.*/ //Member* get_member(Book* book); Member* get_data(Book* book); /* It searches the associationlist, if member is found then returns the book that is connected with.*/ //Book* get_book(Member* member); Book* get_data(Member* member); /* Checks that book/member not already linked creates association if objects are free to link returns whether or not link was valid */ bool link(Book* book,Member* member); /* Checks that book and member are linked deletes association if they are linked returns whether or not unlinking was valid */ bool unlink(Book* book,Member* member); private: Association<Book,Member>* association_list[LIST_SIZE]; };

    The code that performs the linking between 1 book object and 1 member object is the following:

    template bool AssociationList::link(Book* book,Member* member) { bool searching=true; bool success=true; int index=0; int free_slot; while(searching) { if(this->association_list[index]) if((this->association_list[ind

    G 1 Reply Last reply
    0
    • G grscot

      Dear all,
      I can't borrow a book even though the code does not have any error. When I try to display the book details along with the member's name (in case the member has borrowed the book), I can't display the member's name, but only the book details and a message: "no member has borrowed a book".

      Though the code works fine when I have one book and one member, but now that I'm using an array of books and members it doesn't work.

      The code that displays the book and the member's name when I have 1 book and 1 member is:
      void Book::display(Member* borrower) { cout<<"Book title and author are: "<<this->bookDetails<<"."<<endl; if (borrower) cout<<"The member's name is: "<<borrower->get_Data()/*get_name()*/<<"."<<endl; else cout<<"No member has borrowed a book."<<endl; }

      char* get_Data(){return this->name;}

      returns the member's full name, entered in the constructor

      I have an associationlist that holds pointers to associations. Each association has two pointers, one to a book object and the other to the member object.

      class AssociationList { public: //It initialises all slots in the associationlist array to zero. AssociationList(); /* It searches the associationlist, if book is found then returns the member that is connected with.*/ //Member* get_member(Book* book); Member* get_data(Book* book); /* It searches the associationlist, if member is found then returns the book that is connected with.*/ //Book* get_book(Member* member); Book* get_data(Member* member); /* Checks that book/member not already linked creates association if objects are free to link returns whether or not link was valid */ bool link(Book* book,Member* member); /* Checks that book and member are linked deletes association if they are linked returns whether or not unlinking was valid */ bool unlink(Book* book,Member* member); private: Association<Book,Member>* association_list[LIST_SIZE]; };

      The code that performs the linking between 1 book object and 1 member object is the following:

      template bool AssociationList::link(Book* book,Member* member) { bool searching=true; bool success=true; int index=0; int free_slot; while(searching) { if(this->association_list[index]) if((this->association_list[ind

      G Offline
      G Offline
      grscot
      wrote on last edited by
      #2

      Dear all, I'm still struggling to display the book and borrower's details together. Could someone help me? regards, grscot

      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