OO Programming and Data Structures | CS 241

06 Prepare : Checkpoint B

Overview

This checkpoint is intended to help you practice the syntax of inheritance, specifically, the syntax of calling methods from a base class.

You are to write a program to track cell phones. You determine that there are two types of cell phones: traditional phones that have a phone number, and smart phones that have a phone number but also contain an email address.

Instructions

Write a class Phone that contains a phone number, and then a class SmartPhone that extends the Phone class to add an email address according to the following:

  1. The Phone class should contain three integers for the different parts of a phone number. Here is its class diagram:

  2. Phone
    area_code : int
    prefix : int
    suffix : int
    prompt_number() : void
    display() : void
  3. The prompt_number method of the Phone class should ask the user to enter each element of a phone number.

  4. The display method of the Phone class should display the number in the format "(areaCode)prefix-suffix".

  5. The SmartPhone class should extend the Phone class and add the following:

  6. SmartPhone
    email : string
    prompt() : void
    display() : void
  7. The prompt method of the SmartPhone class should call the prompt_number method defined in the base class and then additionally prompt for an email address.

  8. The display method of the SmartPhone class should call the display method defined in the base class and then display the email address. (Yes, it must call it, and yes, they must both be named display.)

  9. In main function, create a Phone object, call its prompt_number method, and then its display method.

  10. After that, also in main, create a SmartPhone object, call its prompt method, and then its display method.

  11. For simplicity, you may again put all of your classes in the same file.

Sample Output

The following is an example of output for this program:


Phone:
Area Code: 801
Prefix: 123
Suffix: 4567

Phone info:
(801)123-4567

Smart phone:
Area Code: 208
Prefix: 867
Suffix: 5309
Email: jenny@test.com

Phone info:
(208)867-5309
jenny@test.com

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/check06b check06b.py

Submission

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


submit check06b.py

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