Computer Science I for majors by James Tam

Return to the course web page

CPSC 231: Mini Assignment 5

Due Monday Nov 28  at 4 PM

New Concepts to be applied for the assignment

[TA Marking spreadsheet]

Description

Define two new classes: 'Cat' and 'Dog'. Each class consists of at least one attribute and method (including the constructor). Each class must be defined in a separate file (module). A third module will contain the 'Driver' class where instances of the two classes will be instantiated and various methods and attributes will be accessed. You should have attended the classes where Object-Oriented programming concepts where covered so you are familiar with all the terminology and you have seen the concepts. Ideally you not only worked through the examples yourself but tried to implement them on your own (at least the simple ones) before starting this assignment.

Assignment details

  • Defines a class 'Cat'
 
  •  Attribute: favoriteFood (String)
 
  • Methods:
     
  • A no argument constructor that sets the favoriteFood attributes to an obvious default starting value (e.g., "I hate everything you give me >.<" for the food)
  • A 'makeSound()' method that displays an appropriate message onscreen using print() when called. It should not display the value of the attribute however.
     
  • Defines a class 'Dog'
 
  •  Attribute: name favoriteFoods (note the use of a plural a 1D list is needed to store multiple values)
 
  • Method:
     
  • A no argument constructor that sets the food attribute to two obvious default starting values (e.g., ["dog food", "people food"] for the foods)
     
  • Defines the 'Driver' module. The code for this module is in a file separate from the two class definitions but a class need not be defined for this module only the starting function: the 'main()' or 'start()' function will contain the following instructions.
 
  • Create an instance of a dog and an instance of a cat
  • Displays the default values for attribute of the cat onscreen
  • Displays the default values for attribute of the dog onscreen
  • Sets the favourite food of the cat to and non-default value e.g.  'tuna'
  • Displays the favourite food of the cat onscreen, the new value should appear
  • Calls cat's 'makeSound()' method

(The call to the start() function can reside in this file).

Points to keep in mind:

  1. Due time: All assignments are due at 4 PM on the due dates listed on the course web page.  Late assignments or components of assignments will not be accepted for marking without approval for an extension beforehand. What you have submitted in D2L as of the due date is what will be marked.
  2. Extensions may be granted for reasonable cases by the course instructor with the receipt of the appropriate documentation (e.g., a doctor's note). Typical examples of reasonable cases for an extension include: illness or a death in the family. Cases where extensions will not be granted include situations that are typical of student life: having multiple due dates, work commitments etc. Tutorial instructors (TA's) will not be able to provide extension on their own and must receive permission from the course instructor first. (Note: Forgetting to hand your assignment or a component of your assignment in does not constitute a sufficient reason for handing your assignment late).
  3. Method of submission: You are to submit your assignment using D2L [help link]. Make sure that you [check the contents of your submitted files] (e.g., is the file okay or was it corrupted, is it the correct version etc.). It's your responsibility to do this! (Make sure that your submit your assignment with enough time before it comes due for you to do a check).
  4. Identifying information: All assignments should include contact information (full name and student ID number) at the very top of your program in the class where the 'main()' function/method resides.
  5. Collaboration: Assignments must reflect individual work, group work is not allowed in this class nor can you copy the work of others.  For more detailed information as to what constitutes academic misconduct (i.e., cheating) for this course please read the following [link].
  6. Execution: programs must run on the computer science network running Python 3.x. If you write you code in the lab and work remotely using a remote login program such as Putty or SSH. If you choose to install Python on your own computer then it is your responsibility to ensure that your program will run properly here. It's not recommended that you use an IDE for writing your programs but if you use one then make sure that you submit your program in the form of text ".py" file or files
  7. Use of pre-created Python libraries: unless otherwise told you are to write the code yourself and not use any pre-created functions from the Python libraries. For this assignment the usual acceptable functions include: print().

D2L configuration:

Marking: