Changes

Jump to: navigation, search

OPS435 Python Lab 7

1,185 bytes added, 10:29, 3 December 2017
INVESTIGATION 1: Classes and objects
* Inside a program typically a class name starts with a capital letter and object names, as typical variable names, start with a lowercase letter.
* Just as you can define a function in a separate file from where you use it - you can define a class in a separate file. In fact it's even more common with classes since you're more likely to need to use them in multiple places.
* The names of the files are by convention all lowercase and short - but that's just because programmers are lazy typists. Feel free to give the files longer names so you can tell what they are without opening them.
For this investigation create the classes and objects from the table above. No test script is provided for this section because the design of the classes is left up to you. Store the data that you think might be relevant for that type. Implement at least two methods in each class (the constructor plus one other).
You may find that when you have more than one or two objects of a type - it will be easier to store them in a Python list instead of having separate variables for each of them. Again - which makes more sense depends entirely on what you do with your objects in your application in any particular situation.
 
To get you started, here's a template for a file you should name lab7a.py
 
<source lang="python">
#!/usr/bin/env python3
 
# Store one IPv4 address
class IPAddress:
# You probably want to construct it as a string, but you may want to store it as the four octets separately:
def __init__(self, address):
# Is this address from a private subnet? e.g. starting with 192.168. or 10.
def isPrivate():
 
# Store information about a person, perhaps someone you'll be adding as a user to a system:
class Person:
 
# Store information about different models from a specific manufacturer. Perhaps how many seats they have and how much fuel they use and the price range:
# Doesn't have to be BMW, pick any car or bike manufacturer:
class BWMModel:
 
# Store information about a specific car that someone owns.
# Spend some time thinking why this class is different than the one above, and whether it has to be different:
class Car:
 
</source>
= LAB 7 SIGN-OFF (SHOW INSTRUCTOR) =

Navigation menu