Sale!

ECE-C301 Laboratory Assignment: Week 2 solution

$30.00

ECE-C301 Advanced Programming for Engineers
Laboratory Assignment: Week 2

(30 Points) Implement a base class called Person that is used to derive two subclasses: Student and
Instructor. A Person should have a name and year of birth. In addition to maintaining all the attributes
of a Person, a Student should have a major and a GPA, and an Instructor should have a salary.
A Person should have the accessor methods getName and getBirthYear; the Person’s name and date of
birth year should be set in the constructor.
A student should have accessor methods getMajor and getGPA as well as corresponding mutator methods
setMajor and setGPA; the major and GPA attributes should be optionally settable during construction.1
An Instructor should have the accessor method getSalary and the mutator method setSalary; the
salary attribute should be optionally settable during construction.

Category:

Description

5/5 - (2 votes)

ECE-C301 Advanced Programming for Engineers
Laboratory Assignment: Week 2

(30 Points) Implement a base class called Person that is used to derive two subclasses: Student and
Instructor. A Person should have a name and year of birth. In addition to maintaining all the attributes
of a Person, a Student should have a major and a GPA, and an Instructor should have a salary.
A Person should have the accessor methods getName and getBirthYear; the Person’s name and date of
birth year should be set in the constructor.
A student should have accessor methods getMajor and getGPA as well as corresponding mutator methods
setMajor and setGPA; the major and GPA attributes should be optionally settable during construction.1
An Instructor should have the accessor method getSalary and the mutator method setSalary; the
salary attribute should be optionally settable during construction.
Each class should additionally implement the repr magic method, which should return a string describing
the type of the instance and its current attributes (including those that are inherited).
Write a test program that imports your classes and clearly demonstrates that they work properly.

 

 

1Hint: See the function definition for my range from slide 63 of Deck 3.pdf (from the ECE-203 Blitz Edition). Also, lookup
the Python built-in constant None (https://docs.python.org/2/library/constants.html).
1