OO Programming and Data Structures | CS 241

04 Prepare : Checkpoint A

Objective

Demonstrate composition in Python (a class that contains another).

Overview

After completing (or while completing) the preparation material for this week, complete the following exercise.

For this exercise, you will create a class to model books and the author that wrote it. Note the relationship that a book has an author.

At this point, you should put all of your classes and other code in the same file. Don't worry about separating it out into separate modules.

Instructions

Write a Python 3 program according to the following:

Person:

Book:

Then, create a main function that does the following:

Sample Output

The following is an example of output for this program:


untitled
Publisher:
unpublished
Author:
anonymous (b. unknown)

Please enter the following:
Name: C.S. Lewis
Year: 1898
Title: The Great Divorce
Publisher: Geoffrey Bles

The Great Divorce
Publisher:
Geoffrey Bles
Author:
C.S. Lewis (b. 1898)

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 classes. You must use classes to receive credit for this assignment.

To run the test script, log into 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/check04a check04a.py

Submission

Submit your program by logging into the CS Department Linux system, and running the submit command with your filename, for example:


submit check04a.py

You should then select the appropriate course (CS 241), instructor, and assignment from the list.