Create a new project named lab8_1. You will be implementing two classes: A Book class, and a Bookshelf class. The Bookshelf has a Book object (actually 3 of them). You will be able to choose what Book to place in each Bookshelf.  Here are their UML diagrams  Book class UML Book - author  : string - title   : string - id      : int - count   : static int + Book() + Book(string, string) + setAuthor(string) : void + setTitle(string) : void + print() : void + setID() : void

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 8RQ
icon
Related questions
Question

In C++

  1. Create a new project named lab8_1. You will be implementing two classes: A Book class, and a Bookshelf class. The Bookshelf has a Book object (actually 3 of them). You will be able to choose what Book to place in each Bookshelf. 
  2. Here are their UML diagrams 

Book class UML

Book
- author  : string
- title   : string
- id      : int
- count   : static int
+ Book()
+ Book(string, string)
+ setAuthor(string) : void
+ setTitle(string) : void
+ print() : void
+ setID() : void

And the Bookshelf class UML

Bookshelf
- book1 : Book
- book2 : Book
- book3 : Book
+ Bookshelf()
+ Bookshelf(Book, Book, Book)
+ setBook1(Book) : void
+ setBook2(Book) : void
+ setBook3(Book) : void
+ print() : void

Some additional information:

    1. The Book class also has two constructors, which again offer the option of declaring a Book object with an author and title, or using the default constructor to set the author and title later, via the setters .

    2. The Book class will have a static member variable named count. You will use this variable to assign each book a unique ID number. Refer to this week’s sample code (Dog and Collar) for help with this.

    3. The Bookshelf class has two constructors. So, when you first create a Bookshelf object, you can choose which three books it will hold (by creating three Book objects, and using them during the Bookshelf declaration), or you can choose to have them set to default values (by using the Bookshelf default constructor).

    4. You will also make use of the const keyword to indicate which methods are not modifying the object.

    5. Demonstrate the use of your Bookshelf class by creating two objects of Bookshelf, each one using a different constructor. With the Bookshelf created using the default constructor, use the setters for each Book to set the Book objects to non default values.

    6. Potential sample run:

      Here are the books on the shelf:
      Title: The Martian, Author: Andy Weir, ID: 1000
      Title: Before the Coffee Gets Cold, Author: Toshikazu Kawaguchi, ID: 1001
      Title: Cat's Cradle, Author: Kurt Vonnegut, ID: 1002

      Here are the books on the shelf:
      Title: Cannery Row, Author: John Steinbeck, ID: 1012
      Title: City of Thieves, Author: David Benioff, ID: 1013
      Title: The Shadow of the Wind, Author: Carlos Ruiz Zafon, ID: 1014

Note: Your sample run may have different ID numbers for the books. That’s okay, as long as each book has its own unique ID that is set automatically when the book is created.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT