Question

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

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

The C++ code is as follows:-

#include <iostream>
using namespace std;
class book
{
public:
book(char *t,char *a,int p)
{
std::copy(t, t+64, title);
std::copy(a, a+64, author);
pages=p;
}
void show_book() //implementing function
{
cout<<"Title: "<<title<<endl;
cout<<"Author: "<<author<<endl;
cout<<"Pages: "<<pages<<endl;
}
private:
char title[64];
char author[64];
int pages;
};
class libraryCard: public book //derive new class from base class
{
public:
char catelog[64];
int checked_out;
libraryCard(char * t,char * a,int p,char * c,int co):book(t,a,p)
{
std::copy(c, c+64, catelog);
checked_out=co;
}
void show_card() //implementing function
{
book::show_book();
cout<<"Catelog: "<<catelog<<endl;
if(checked_out==1)
cout<<"Status: Checked out";
else
cout<<"Status: Available";
}
};
int main()
{
libraryCard obj("C++ How to Program","Deitel & Deitel",1400,"300CPP",1); //creating object
obj.show_card(); //function calling
return 0;
}

The output of the above code is as follows:-

Title: C++ How to Program
Author: Deitel & Deitel
Pages: 1400
Catelog: 300CPP
Status: Checked out

The screenshot of the above code is as follows:-

C Computer Science question Chu X CC Code. Compile & Run Codeche x 22) WhatsApp | + c codechef.com/ide * int pages; 21 22 23

Add a comment
Know the answer?
Add Answer to:
Suppose we have the following book base class: class book { public: book(char *, 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
  • 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...

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

    Please use C++ 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...

  • 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...

  • 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...

  • 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...

  • LAB: Book information (overriding member methods)

    10.15 LAB: Book information (overriding member methods)Given main() and a base Book class, define a derived class called Encyclopedia. Within the derived Encyclopedia class, define a printInfo() method that overrides the Book class' printInfo() method by printing not only the title, author, publisher, and publication date, but also the edition and number of volumes.Ex. If the input is:The Hobbit J. R. R. Tolkien George Allen & Unwin 21 September 1937 The Illustrated Encyclopedia of the Universe James W. Guthrie Watson-Guptill 2001 2nd 1the output is:Book Information:     Book Title: The Hobbit    Author: J. R. R. Tolkien    Publisher: George Allen & Unwin    Publication Date: 21 September 1937 Book Information:     Book Title: The Illustrated Encyclopedia of the Universe    Author: James W. Guthrie    Publisher: Watson-Guptill    Publication Date: 2001    Edition: 2nd    Number of Volumes: 1Note: Indentations use 3 spaces.BookInformation.javaimport java.util.Scanner; public class BookInformation {    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);       Book myBook = new 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...

  • 2016 points output of following Java Program? public class Base { public final void show() {...

    2016 points output of following Java Program? public class Base { public final void show() { . System.out.println("Base::show() called"); public class Derived extends Base { public void show() { System.out.println("Derived::show() called"); } e lor rested in order public class Main { ects from and public static void main(String[] args) { Base b = new Derived(); b.show();

  • 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
ADVERTISEMENT