Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python ------ Regex, Dictionaries and Lists Exercise 7 - Inheritance Design two classes: One for a Person, and the second class refines the Person to

Python ------ Regex, Dictionaries and Lists

Exercise 7 - Inheritance

Design two classes: One for a Person, and the second class refines the Person to hold Passenger information:

class Person: firstname lastname class Passenger(Person ): row seat

Read the Passenger.csv file, and store each Person/Passenger in a Jet[ ]. Here is an excerpt from the data file:

betrozoff,tan,2,A bleick,iosif,9,E manh,timmothy,1,A

Using Exercise - 7 Inheritance that given above, modify it to use Inheritance and Polymorphism. Inheritance means having a Derived class use data and functions of a Base class. Polymorphism, in this case, means providing a uniform interface among all the classes.

datanode = "manh,timmothy,5,C" person = Person(datanode )# a datanode that __init__ parses using Regex (for example) passenger = Passenger(Person)# A passenger is-a person seat (row# and column-letter ) # contains a passenger jet.insert(passenger) # jet determines which section to insert passenger section.insert(passenger)# section determines which row to insert passenger row.insert(passenger)# row determines which seat to insert passenger Using the Person and Passenger objects, modify them as follows:

class Person: firstname : timmothy lastname : manh class Passenger(Person ): rowID = 5C row: 5 seat: ord('C' - 'A' ) = 2 class Seat (Passenger) {rowID : Passenger } class Row : { rowID : seat } class Section : # 1st, Business, and Economy { first : row 0-5 : } { business : row 6-15 } { economy : row 16-36 } class Jet : sections[ first, business, economy ]

Build 'smart' UDT objects. For example, a Jet object should be able to calculate which Section object to insert a passenger. A Section object should be able to calculate which Row object to insert a passenger. A Row object should be able to calculate which Seat to insert a Passenger. The smart objects can avoid programming a chain of IF statements by building the intelligence to manage itself internally instead of externally.

An example of a smart object would be a Reader class. The Reader class should handle not being able to open a file, instead of trying to open the file outside the Reader class. Read the Airline.XML file, and Passengers with rows 0 to 5 are in 1st class, rows 6 to 15 are in Business class and 16 to 35 are in Economy Class. After placing the Passengers in the appropriate sections in the Jet, output the Passengers by Section, and within each Section by Row.

Make the class interface as uniform as possible, meaning use the same interface for inserting a passenger into a seat, row, section, jet. For example, implement a 'insert' function to insert a passenger into each type of object.

Use the built-in iterators like Map, Filter, Reduce and Join where possible. You may also use __iter__, __next__ and generators even though they have not been covered in-class yet.

Note: This assignment calls for the use of both Dictionaries and Lists. One could assert that the assignment could be done best by using one or the other but not mixing both. The intention of mixing Lists with Dictionaries is to teach the differences between Lists and Dictionaries (and when it's appropriate to use one or the other). You may also use Tuples and Sets where appropriate.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions