Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me figure out whats wrong with the program I\'m writing. Its almost

ID: 3833594 • Letter: P

Question

Please help me figure out whats wrong with the program I'm writing. Its almost done but there are a few small bugs I cannot work out. Thank you for the help.

Problem:

Your design and C++ code should contain a base class and a derived class in which the derived class has inheritance of the base class. Design and implement in C++ a base class for the concept “BOOK” to represent book(s) and a derived class for the concept “LIBRARY CARD” that inherits the class definition BOOK in which LIBRARY CARD is a typical library card used by a library to provide a record of a book in a library. For both class definitions (BOOK and LIBRARY CARD) make sure to define class members (methods and data) as pubic or private or protected. Make sure to have a constructor and destructor for each class. Your program will use a constructor to create an instance of the class object LIBRARY CARD that in turn creates with a constructor an instance of the inherited class object BOOK. Each object, LIBRARY CARD and BOOK, should be instantiated with data by the respective constructors. Once you have created an instance of a library card and book, your program should output all the data for the instance of a LIBRARY CARD object with all the data for the inherited BOOK object.

Such data could include:

For BOOK ---- title of book, author name, total number of pages, …

For LIBRARY CARD ---- book code number, book checked out/in status code, …

This is what I have so far and its throwing these errors:

CODE:

#include <iostream>

#include <string>

using namespace std;

class book

{

public:

   book(char *, char *, int, float);

   ~book(void);

   void show_book(void);

   int change_pages(float);

   int book_id(void);

protected:

   char title[64];

private:

   char author[64];

   int book_id;

   float pages;

};

book::book(char *title, char *author, int book_id, float pages)

{

   cout << endl;

   cout << "Constructing the Book object for " << title << endl;

   strcpy_s(book::title, title);

   strcpy_s(book::author, author);

   book::book_id = book_id;

   if (pages < 50000.0)

   {

       book::pages = pages;

   }

   else

   {

       book::pages = 0.0;

   }

}

book::~book(void)

{

   cout << endl;

   cout << "Destroying the book object for " << title << endl;

}

void book::show_book(void)

{

   cout << endl;

   cout << "Title: " << title << endl;

   cout << "Author: " << author << endl;

   cout << "Id: " << book_id << endl;

   cout << "pages: " << pages << endl;

}

int book::change_pages(float new_pages)

{

   if (new_pages < 50000.0)

   {

       pages = new_pages;

       return(0);

   }

   else

   {

       return(-1);

   }

}

int book::book_id(void)

{

   return(book_id);

}

class libraryCard : public book

{

public:

   libraryCard(char *, char *, int, float, char *, float, int);

   ~libraryCard(void);

   void show_libraryCard(void);

private:

   char company_car[64];

   float checkedIn_bonus;

   int checkedOut_options;

};

libraryCard::libraryCard(char *title, char *author, int book_id, float pages, char *company_car, float bonus, int checkedOut_options) : book(title, author, book_id, pages)

{

   cout << endl;

   cout << "Constructing the libraryCard object for " << title << endl;

   strcpy_s(libraryCard::company_car, company_car);

   libraryCard::checkedIn_bonus = bonus;

   libraryCard::checkedOut_options = checkedOut_options;

}

libraryCard::~libraryCard(void)

{

   cout << endl << "Destroying the libraryCard object for " << libraryCard::title << endl;

}

void libraryCard::show_libraryCard(void)

{

   show_book();

   cout << "Company Car: " << company_car << endl;

   cout << "Book Checked In Code: " << checkedIn_bonus << endl;

   cout << "Book Checked Out Code: " << checkedOut_options << endl;

}

int main(void)

{

   book worker((char *) "Ryan Newbury", (char *) "Librarian", 101, 10101.0);

   libraryCard boss((char *) "Jane Doe", (char *) "Student", 102, 40101.0, (char *) "Out", 5000, 1000);

   worker.show_book();

   boss.show_libraryCard();

   getchar();

   return 0;

}

declaration is incompatible with "int book: book id" (declared at line 17 (x c2365 book book id': redefinition; previous definition was 'member function' (x C2659 '-1: function as left operand (x C3867 book book id': non-standard syntax use '&' to create a pointer to member (x C3867 book book id': non-standard syntax use '&' to create a pointer to member X C2440 eturn': cannot convert from "int thiscall book:* VOI to 'int' Project Project Project Project Project Project Source.cpp 66 source cpp 17 source cpp 27 source cpp 49 source cpp 68 source cpp 68

Explanation / Answer

#include <iostream>
#include<cstdio>
#include <string>

using namespace std;

class book

{

public:

    book(char *, char *, int, float);

    ~book(void);

    void show_book(void);

    int change_pages(float);

    int get_book_id(void);

protected:

    char title[64];

private:

    char author[64];

    int book_id;

    float pages;

};

book::book(char *title, char *author, int book_id, float pages)

{

    cout << endl;

    cout << "Constructing the Book object for " << title << endl;

    strcpy_s(book::title, title);

    strcpy_s(book::author, author);

    book::book_id = book_id;

    if (pages < 50000.0)

    {

        book::pages = pages;

    }

    else

    {

        book::pages = 0.0;

    }

}

book::~book(void)

{

    cout << endl;

    cout << "Destroying the book object for " << title << endl;

}

void book::show_book(void)

{

    cout << endl;

    cout << "Title: " << title << endl;

    cout << "Author: " << author << endl;

    cout << "Id: " << book_id << endl;

    cout << "pages: " << pages << endl;

}

int book::change_pages(float new_pages)

{

    if (new_pages < 50000.0)

    {

        pages = new_pages;

        return(0);

    }

    else

    {

        return(-1);

    }

}

int book::get_book_id(void)

{

    return(book_id);

}

class libraryCard : public book

{

public:

    libraryCard(char *, char *, int, float, char *, float, int);

    ~libraryCard(void);

    void show_libraryCard(void);

private:

    char company_car[64];

    float checkedIn_bonus;

    int checkedOut_options;

};

libraryCard::libraryCard(char *title, char *author, int book_id, float pages, char *company_car, float bonus, int checkedOut_options) : book(title, author, book_id, pages)

{
  
   cout << endl;

    cout << "Constructing the libraryCard object for " << title << endl;

    strcpy_s(libraryCard::company_car, company_car);

    libraryCard::checkedIn_bonus = bonus;

    libraryCard::checkedOut_options = checkedOut_options;

}

libraryCard::~libraryCard(void)

{

    cout << endl << "Destroying the libraryCard object for " << libraryCard::title << endl;

}

void libraryCard::show_libraryCard(void)

{

    show_book();

    cout << "Company Car: " << company_car << endl;

    cout << "Book Checked In Code: " << checkedIn_bonus << endl;

    cout << "Book Checked Out Code: " << checkedOut_options << endl;

}

int main(void)

{

    book worker((char *) "Ryan Newbury", (char *) "Librarian", 101, 10101.0);

    libraryCard boss((char *) "Jane Doe", (char *) "Student", 102, 40101.0, (char *) "Out", 5000, 1000);

    worker.show_book();

    boss.show_libraryCard();

    getchar();

    return 0;

}

I have modified the code, and should work well. The main problem was the function name and the variable name, 'book_id' were same causing conflict. I have changed the function name to 'get_book_id" and things are working well. If tou are ctill gettin an error, please comment below. I shall resolve that.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote