Programming Exercise 3-1
Programming Exercise 11-3
# person.py
class Person:
def __init__(self, name, address, phone_number):
self.__name = name
self.__address = address
self.__phone_number = phone_number
def set_name(self, name):
self.__name = name
def set_address(self, address):
self.__address = address
def set_phone_number(self, phone_number):
self.__phone_number = phone_number
def get_name(self):
return self.__name
def get_address(self):
return self.__address
def get_phone_number(self):
return self.__phone_number
class Customer(Person):
def __init__(self, name, address, phone_number, cust_number, on_list):
# Call superclass __init__ method
Person.__init__(self, name, address, phone_number)
# Initialize the cust_number and on_list attributes
self.__cust_number = cust_number
self.__on_list = on_list
# Mutator functions for cust_number and on_list
def set_cust_number(self, cust_number):
self.__cust_number = cust_number
def set_on_list(self, on_list):
self.__on_list = on_list
# Accessor functions for cust_number and on_list
def get_cust_number(self):
return self.__cust_number
def get_on_list(self):
return self.__on_list
# Exercise 11-3.py
import person
def main():
# Local variables
name =
address =
phone_number =
cust_number = 0
on_list_flag = False
# Get data attributes.
name = input(Enter the name: )
address = input(Enter the address: )
phone_number = input(Enter the phone_number: )
cust_number = input(Enter the customer number: )
on_list = input(Does the customer wish to be
on the mailing list?(Yes/No) )
if on_list == Yes:
on_list_flag = True
else:
on_list_flag = False
# Create an instance of Customer.
customer = person.Customer(name, address, phone_number,
cust_number, on_list_flag)
# Display information.
print (Customer information: )
print (Name:, customer.get_name())
print (Address:, customer.get_address())
print (Phone number:, customer.get_phone_number())
print (Customer Number:, customer.get_cust_number())
print (On Mailing List:, customer.get_on_list())
# Call the main function.
main()
Reviews
There are no reviews yet.