Skip to content

in library code #4433

@NESRAINJH

Description

@NESRAINJH

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

1p.c++: In member function 'void member::displayRemember()':
1p.c++:70:27: error: 'Id' was not declared in this scope    
             cout<<"ID: "<<Id<<endl;
                           ^~
1p.c++: In member function 'int member::getMemberId()':    
1p.c++:76:16: error: 'Id' was not declared in this scope   
         return Id;
                ^~
1p.c++: In member function 'void library::borrowBook(int)':
1p.c++:117:30: error: 'b' was not declared in this scope
                              b.borowBook();
                              ^
1p.c++: In function 'int main()':
1p.c++:157:15: error: invalid initialization of non-const reference of type 'Book&' from an rvalue of type 'Book'
     l.addBook(Book(1, "C++", "Author1", 2000, true));
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1p.c++:85:15: note:   initializing argument 1 of 'void library::addBook(Book&)'
          void addBook(Book& book)
               ^~~~~~~
1p.c++:158:15: error: invalid initialization of non-const reference of type 'Book&' from an rvalue of type 'Book'  
     l.addBook(Book(2, "Java", "Author2", 2010, true));
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1p.c++:85:15: note:   initializing argument 1 of 'void library::addBook(Book&)'
          void addBook(Book& book)
               ^~~~~~~
1p.c++:159:45: error: 'Member' was not declared in this scope
     l.addMember(Member(1, "John", "Address1"));
                                             ^
1p.c++:164:7: error: 'class library' has no member named 'borowBook'; did you mean 'borrowBook'?
     l.borowBook(1, 1);
       ^~~~~~~~~
1p.c++:166:7: error: 'class library' has no member named 'borowBook'; did you mean 'borrowBook'?
     l.borowBook(2, 2);
       ^~~~~~~~~
1p.c++:167:22: error: no matching function for call to 'library::returnBook(int, int)'
     l.returnBook(1, 1);
                      ^
1p.c++:136:18: note: candidate: void library::returnBook(int)
             void returnBook( int bookId)
                  ^~~~~~~~~~
1p.c++:136:18: note:   candidate expects 1 argument, 2 provided
1p.c++:168:22: error: no matching function for call to 'library::returnBook(int, int)'
     l.returnBook(2, 2);
                      ^
1p.c++:136:18: note: candidate: void library::returnBook(int)
             void returnBook( int bookId)
                  ^~~~~~~~~~
1p.c++:136:18: note:   candidate expects 1 argument, 2 provided
PS C:\Users\USER\Desktop\c++>

Screenshot

ITS FIRST OP FOR ME AND I DONT KNOW WHAT PROBLEM HELP

Environment data

class Book
{
    private:
    int id;
    string titel;
    string author;
    long year;
    bool isAvailable ;
    public:
    Book(long i, string t, string a, long y, bool av) 
    {
        id = i;
        titel = t;
        author = a;
        year = y;
        isAvailable = av;
    }
    void borowBook()
    {
         if (isAvailable = false)
         {
              cout<<"The book is borrowed"<<endl;
         }
         
    }
    void returnBook()
    {
        if (isAvailable = true)
        {
            cout<<"The book is returned"<<endl;
        }
    }
    bool getIsAvailable()
    {
        return isAvailable;
    }
    void display()
    {
        cout<<"ID: "<<id<<endl;
        cout<<"Title: "<<titel<<endl;
        cout<<"Author: "<<author<<endl;
        cout<<"Year: "<<year<<endl;
        cout<<"Availability: "<<(isAvailable?"Available":"Not Available")<<endl;
    }
    int getId()
    {
        return id;
    }
  
};
   class member 
     {
        private:
        int id;
        string name;
        string address;
        public:
        member(int i, string n, string a) 
        {
            id = i;
            name = n;
            address = a;
        }
        void displayRemember()
        {
            cout<<"ID: "<<Id<<endl;
            cout<<"Name: "<<name<<endl;
            cout<<"Address: "<<address<<endl;
        }
        int getMemberId()
    {
        return Id;
    } 
     };
   class library 
   {
       private:
       vector<Book> books;
         vector<member> members;
         public:
         void addBook(Book& book)
         {
             books.push_back(book);
         }
         void addMember(member& member)
         {
             members.push_back(member);
         }
         void displayAllBooks()
         {
             cout<<"All Books:"<<endl;
             for(auto & book: books)
             {
                 book.display();
             }
         }
         void displayAllMembers()
         {
             cout<<"All Members:"<<endl;
             for(auto & member: members)
             {
                 member.displayRemember();
             }
         }
         void borrowBook( int bookId)
         {
             for(auto &book : books)
             {
                 if(book.getId() == bookId)
                 {
                         if(book.getIsAvailable())
                         {
                             b.borowBook();
                             cout<<"Book borrowed successfully"<<endl;
                         }
                         else 
                         {
                            cout<<"Book is not available"<<endl;
                             return;
                         }
                     
                 }
                 else
                 {
                     cout<<"Book  not found \n "<<endl;
                 }
             }

         }
         
         
            void returnBook( int bookId)
            {
                for(auto & book : books)
                {
                    if(book.getId() == bookId)
                    {
                      
                                book.returnBook();
                                cout<<"Book returned successfully"<<endl;
                                return;
                            
                        
                    }
                }
                cout<<"Book  not found.....\n"<<endl;
            }
   };
int main() 

 {
    library l;
    l.addBook(Book(1, "C++", "Author1", 2000, true));
    l.addBook(Book(2, "Java", "Author2", 2010, true));
    l.addMember(Member(1, "John", "Address1"));
  l.addMember(Member(2, "Jane", "Address2"));
  cout<<"Library Management System"<<endl;
    l.displayAllBooks();
    l.displayAllMembers();
    l.borowBook(1, 1);
    cout<<"-------BOROWING A BOOK------------"<<endl;
    l.borowBook(2, 2);
    l.returnBook(1, 1);
    l.returnBook(2, 2);
    cout<<"-------RETURNED A BOOK------------"<<endl;
    l.displayAllBooks();
    l.displayAllMembers();







    return 0;
 }

Steps to reproduce

library

Expected behavior

its first time to me so I don't expected

Actual behavior

did not understand it

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions