06 Prepare : Checkpoint A
Overview
This checkpoint is intended to help you practice the syntax of basic inheritance.
In looking at the collection of books next to your bed, you notice that they fall into a few different categories. First, you have your regular books and novels, second, your textbooks, and finally, your collection of picture books :-).
You quickly recognize that they all have many things in common, but there are some slight differences in the properties of these different kinds of books.
In particular, all books seem to have the following:
title : string
author : string
publication_year : int
That information captures your regular books and novels fairly well, and yet your textbooks also have a subject they belong to, such as math, physics, computer science, etc.:
subject : string
Finally, your picture books contain all the information of a regular book, but in addition to an author, they also have an illustrator.
illustrator : string
You decide this sounds like a perfect opportunity to practice your new inheritance skills, because you could create a base class for a Book, a derived class TextBook that extends a Book, and another derived class PictureBook that also extends Book.
Instructions
For this assignment, because the classes we are going to create are so small and simplistic, and to help you focus on just the elements of inheritance, rather than the mechanics of creating lots of files, you will put all of your classes at the top of the main file, rather than creating separate files for each class, like we would for larger, real-world projects.
Create a class for a
Bookthat has the following member variables:title : string
author : string
publication_year : int
Next, create a class for a
TextBookthat extends aBookand adds the following member variable:subject : string
Finally, create a class for a
PictureBookthat that extends aBookand adds the following member variable:illustrator : string
In the base
Bookclass, create a methodprompt_book_infothat prompts the user for the title, author, and publication_year, and also a methoddisplay_book_infothat displays the title, author, and publication year in the format: "Title (publication_year) by Author".In the
TextBookclass, create methodsprompt_subjectanddisplay_subjectthat prompt and display the subject of the book.In the
PictureBookclass, create methodsprompt_illustratoranddisplay_illustratorthat prompt and display the Illustrator of the book.In
main, first create aBookobject and call the following methods:prompt_book_info
display_book_info
Next, create a
TextBookobject and call the following methods:prompt_book_info
prompt_subject
display_book_info
display_subject
Finally, create a
PictureBookobject and call the following methods:prompt_book_info
prompt_illustrator
display_book_info
display_illustrator
Sample Output
The following is an example of output for this program:
Title: The Miracle of Forgiveness
Author: Spencer W. Kimball
Publication Year: 1969
The Miracle of Forgiveness (1969) by Spencer W. Kimball
Title: Introduction to C++
Author: James Helfrich
Publication Year: 2012
Subject: Computer Science
Introduction to C++ (2012) by James Helfrich
Subject: Computer Science
Title: Click, Clack, Moo
Author: Doreen Cronin
Publication Year: 2000
Illustrator: Betsy Lewin
Click, Clack, Moo (2000) by Doreen Cronin
Illustrated by Betsy Lewin
Automatic Grading Script (TestBed)
This assignment is pass/fail. In order to receive credit, it must pass the auto-grading test script (TestBed). You can run this script as many times as you like while you are working on the assignment. The same test script will be run by the instructor for credit, so you should not be surprised at the result.
In addition, because the point of this exercise is to help you practice the use of inheritance, you must use inheritance to receive credit for this assignment.
To run the test script, log in to the CS Department Linux system and run the testBed command, providing the class and test script to run as well as the Python program to use, for example:
testBed cs241/check06a check06a.py
Submission
Submit your program by logging into the CS Department Linux system, and running the submit command with your filename, for example:
submit check06a.py
You should then select the appropriate course (CS 241), instructor, and assignment from the list.