Computer Science I for majors by James Tam

Return to the course web page

CPSC 231: Mini-Assignment #6

Due Monday December 1, at 4 PM

New Concepts to be applied for the assignment

Description

Your program must consist of three classes (as described below).

  • Defines a class 'Cat' (9 marks)
 
  •  Attributes: name (String) and age (numeric) (2 marks)
 
  • Methods:
     
  • An "init()" constructor that sets the name and age attributes to obvious default starting values (e.g., "no name" for the name and -1 for the age) (2 marks)
  • Accessor 'get()' methods: one method will return the name, one method will return the age back to the caller of the method (2 marks)
  • Mutator 'set()' methods: a method that takes one argument in addition to the 'self' parameter. The value of that argument will be used to set the value of an attribute. There should be one set method for each attribute. (2 marks)
  • A 'makeSound()' method that displays the message 'meow' onscreen when called (1 mark)
     
     
     
  • Defines a class 'Dog' (9 marks)
 
  •  Attributes: name (String) and age (numeric) (2 marks)
 
  • Methods:
     
  • An "init()" constructor that sets the name and age attribute to obvious default starting values (e.g., "no name" for the name and -1 for the age) (2 marks)
  •  Accessor 'get()' methods: one method will return the name, one method will return the age back to the caller of the method (2 marks)
  • Mutator 'set()' methods: a method that takes one argument in addition to the 'self' parameter. The value of that argument will be used to set the value of an attribute. There should be one set method for each attribute. (2 marks)
  •  A 'makeSound()' method that displays the message 'bark' onscreen when called (1 mark)
     
     
     
  • Defines the 'Driver' class. The 'main()/driver()' method will contain the following instructions (10 marks)
 
  • Instantiates instances of a dog and cat (2 marks)
  • Displays the name and age attributes of the dog onscreen, the default values should appear (2 marks)
  • Displays the name and age attributes of the cat onscreen, the default values should appear (2 marks)
  • Sets the age and name of the cat to 7 and 'Tigger' respectively (2 marks)
  • Displays the name and age attributes of the cat onscreen, the new values should appear (2 marks)

Marking key

Marks earned 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Grade point 4.0 3.9 3.8 3.7 3.6 3.5 3.4 3.3 3.2 3.1 3.0 2.9 2.8 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.8 1.6 1.4 1.2 1 0.8 0.6 0.0

 

Submitting your work:

  1. Assignments (source code/'dot-py' file) must be electronically submitted according to [the assignment submission requirements] using [D2L]
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following [link].