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.
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.
Download and install perl on the operating system of your choice.
Run the cat.pl script to verify your perl installation.
Modify the constructor to initialize the cat’s age to a random number between 5 and 10.
Modify the constructor to accept the cat’s initial name.
Add a new method called speak() to make the cat say “meow”.
(Hint: use the print function.)
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.
Modify the set_name() method to keep an array of all names the cat has ever had.
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.
Modify the object so that the cat’s age increases by 1 every five times it speaks.
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
Copy Cat.pm to Dog.pm and make the necessary changes so it works.
Modify your script to create both cats and dogs with names.
Create a short series of unit tests to demonstrate the cat’s age is indeed between 5 and 10.
Create unit tests to demonstrate the constructor indeed accepts an initial name.
Create unit tests to assert the speak() method is properly functioning.
Create any other unit tests you deem appropriate.