Question

Please use C++

Suppose we have the following book base class: class book { public: book(char*, char *, int); void show_book(); private: char

0 0
Add a comment Improve this question Transcribed image text
Answer #1

PLEASE NOTE : FEEL FREE TO ASK ANY DOUBTS by COMMENTING

  • I used inbuilt strcpy method to copy strings.
  • If you want me to add/change anythin, Please let me know by commenting.
  • Comments starts with ' // '. Check spellings for printing statements.
  • Please refer to the screenshot of the code to understand the indentation of the code

Language : C++ Programming

IDE : Dev C++

:::::::::::::::::::::::::::::::::::::::::::: CODE ::::::::::::::::::::::::::::::::::::::::

#include <iostream>
#include <cstring>
using namespace std;

// book class
class book{
   // public variables
   public:

       // constructor
       book(char*,char *,int);

       // to show book details
       void show_book();

   // private variables
   private:

       // title, author, pages
       char title[64];
       char author[64];
       int pages;
};

// implementing class functions
book::book(char *title,char *author, int pages){

   // copying title, author. Assigning pages
   strcpy(this->title,title);
   strcpy(this->author,author);
   this->pages = pages;
}

void book::show_book(){

   // showing book details
   cout << "Title: " << title << endl;
   cout << "Author: " << author << endl;
   cout << "Pages: " << pages << endl;
}

// class LibraryCard that inherits book class
class LibraryCard:book{
   // private variables
   private:
       // chatalog and checked_out value
       char catalog[64];
       int checked_out;

   // public variables
   public:
       // constructor
       LibraryCard(char *,char *,int,char*,int);
       // to show catalog details
       void show_card();
};

// constructor that calls base class constructor
LibraryCard::LibraryCard(char *title,char *author,int pages,
   char *catalog,int checked_out):book(title,author,pages){

   // copy catalog and assign checkedout value
   strcpy(this->catalog,catalog);
   this->checked_out = checked_out;
}

void LibraryCard::show_card(){

   // call base class method show_book
   book::show_book();

   // print catalog
   cout << "Catalog: " << catalog << endl;

   // if checked_out value is 1, printing "Checked out"
   cout << "Status: ";

   if(checked_out==1){
       cout << "Checked out";
   }

   // if checked_out value is not 1, printing "Avaiable"
   else{
       cout << "Available";
   }

   cout << endl;
}

int main(){

   // required variables with values
   char title[] = "C++ How to Program";

   char author[] = "Deitel & Deitel";

   int pages = 1400;

   char catalog[] = "300CPP";

   int checked_out = 1;

   // creating LibraryCard instance
   LibraryCard l(title,author,pages,catalog,checked_out);

   // calling show_card of above instance
   cout << "*************************\n";

   l.show_card();

   cout << "*************************\n";

   return 0;
}

:::::::::::::::::::::::::::::::::::::::::::: OUTPUT ::::::::::::::::::::::::::::::::::::::::

E: BOoks.exe ***** Title: C++ How to Program Author: Deitel & Deitel Pages: 1400 Catalog: 300CPP Status: checked out ********

:::::::::::::::::::::::::::::::::::::: CODE in EDITOR ::::::::::::::::::::::::::::::::::

BOoks.cpp #include <iostream> #include <cstring> using namespace std; 4 5 / book class 6 class book 7 Il public variables 8 pNNNNNN LON ܢܟ AWN 84 85 67 9 void LibraryCard::show_card(){ 68 69 // call base class method show_book 70 book::show_book ();

_________________________________________________________________

Dear Friend, Feel Free to Ask Any Doubts by Commenting. ASAP i'll respond when i'm available.

I'm on a critical Situation. Please Do Not Forget To Give A Thumbs UP +1. It will Helps me A Lot.

Thank YOU :-)

Add a comment
Know the answer?
Add Answer to:
Please use C++ Suppose we have the following book base class: class book { public: book(char*,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Suppose we have the following book base class: class book { public: book(char *, char *,...

    Suppose we have the following book base class: class book { public: book(char *, char *, int); void show_book(); private: char title[64]; char author[64]; int pages; }; Suppose that we need to derive a new class, called libraryCard class, which adds the following members to the book class: char catalog[64]; int checked out; // 1 if checked out, otherwise 0 if available libraryCard(char *, char *, int, char *, int); void show_card(); 1. Derive the new class from the base...

  • C++ program Suppose we have the following book base class: class book { public: book(char *,...

    C++ program Suppose we have the following book base class: class book { public: book(char *, char *, int); void show_book(); private: char title[64]; char author[64]; int pages; }; Suppose that we need to derive a new class, called libraryCard class, which adds the following members to the book class: char catalog[64]; int checked out; // 1 if checked out, otherwise 0 if available libraryCard(char *, char *, int, char *, int); void show_card(); 1. Derive the new class from...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • You are going to model a Book in a library. The Book class should contain a...

    You are going to model a Book in a library. The Book class should contain a title and an author (exactly 1 author is OK). Also, a book can be checked out and returned by a student. A Book object should be able to identify the student who currently holds the book. 1.Design the public interface (public constructor and public methods) for a class Book. You can use String to represent title, author, and student. 2. Implement the class Book...

  • please Code in c++ Create a new Library class. You will need both a header file...

    please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...

  • C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Ever...

    C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a "next" pointer. Textbook Туре String String String Attribute title author ISBN Textbook* next Library class should have a head node as an attribute to keep the list of the books. Also, following member...

  • Create a base class named Book. Data fields include title and author; functions include those that...

    Create a base class named Book. Data fields include title and author; functions include those that can set and display the fields. Derive two classes from the Book class: Fiction, which also contains a numeric grade reading level, and NonFiction, which contains a variable to hold the number of pages. The functions that set and display data field values for the subclasses should call the appropriate parent class functions to set and display the common fields, and include specific code...

  • 1- Create the base class Book that has the following instance variables, constructor, and methods title...

    1- Create the base class Book that has the following instance variables, constructor, and methods title ( String) isbn ( String) authors (String) publisher (String) edition ( int) published_year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method // that return sting representation of Book object. 2- Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title ( String) isbn...

  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  • Create a class called Restaurant that is the base class for all restaurants. It should have...

    Create a class called Restaurant that is the base class for all restaurants. It should have attributes for the restaurant's name{protected) and seats (private attribute that represents the number of seats inside the restaurant). Use the UML below to create the methods. Note, the toString prints the name and the number of seats. Derive a class Fastfood from Restaurant This class has one attribute - String slogan (the slogan that the restaurants uses when advertising - e.g., "Best Burgers Ever!")....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT