TechHui

Hawaiʻi's Technology Community

This is a sample Perl Homework set I got from a potential employer. Try it out.

This homework assignment helps us assess your programming abilities. Your mission, should you choose to accept it, is to complete the assigned task and send your completed files to us within one week of receipt.

Description

Perl supports an object oriented interface. A sample object has been provided in the file Cat.pm. Sample use of this object is in the file cat.pl. These two files will be the starting point of your project.

Prerequisites

  1. Download and install perl on the operating system of your choice.

  2. Run the cat.pl script to verify your perl installation.

Coding Tasks

  1. Modify the constructor to initialize the cat’s age to a random number between 5 and 10.

  2. Modify the constructor to accept the cat’s initial name.

  3. Add a new method called speak() to make the cat say “meow”.
    (Hint: use the print function.)

  4. Modify the speak() method to take an optional argument.
    If not supplied, the cat still says “meow”.
    If supplied, the cat prints the value of the argument.

  5. Modify the set_name() method to keep an array of all names the cat has ever had.

  6. Create a names() method to return all the names the cat has ever had.
    Modify cat.pl to set several cat names then print out the list of names.

  7. Modify the object so that the cat’s age increases by 1 every five times it speaks.

  8. Create a new method average_name_length() that returns the average length, in characters, of all the names the cat has ever had.

Expanding the Code

  1. Copy Cat.pm to Dog.pm and make the necessary changes so it works.

  2. Modify your script to create both cats and dogs with names.

Testing Tasks

  1. Create a short series of unit tests to demonstrate the cat’s age is indeed between 5 and 10.

  2. Create unit tests to demonstrate the constructor indeed accepts an initial name.

  3. Create unit tests to assert the speak() method is properly functioning.

  4. Create any other unit tests you deem appropriate.

Views: 14

Attachments:

Sponsors

web design, web development, localization

© 2020   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service