Perl

Menu

In-Class Assignment #6

This assignment will get you familiar with the basics of Object-Oriented Programming in Perl, including constructors, methods, and overloading

Implement a class named Movie, as used by the sample main program below. Objects of the class Movie have three attributes: a title, a release year, and a list of actors/actresses. The constructor (new()) will take both the title and the year as parameters.
In addition to the constructor, you should write one method which takes a name to add to the actor list (add_actor()), and another method that returns a list of all the actors, sorted by their names. (actors()).

Finally, when your object is printed in a double quoted string, it should print the title of the movie, followed by its release year in parentheses (see sample output)

Notes

There is no requirement to be able to access or update the title or year once an object is created.

Similarly, there is no requirement to be able to remove an actor, or to access an individual actor's name.

Sample Main

The below file can be copied to your local directory on rcs-sun4.rpi.edu by executing the command:
cp ~lallip/public_html/movies.pl .
It can also be downloaded from the web.
#!/usr/bin/env perl
use strict;
use warnings;

use Movie;

my $st = Movie->new ('Star Trek: The Motion Picture', 1978);
for my $actor ('Shatner, William', 'Nimoy, Leonard', 'Kelly, DeForest'){
    $st->add_actor($actor);
}
{
    local $" = "; ";
    my @actors = $st->actors();
    print "$st starred: @actors\n";
}

Sample Output

Star Trek: The Motion Picture (1978) starred: Kelly, DeForest; Nimoy, Leonard; Shatner, William 

Submission

As with all in-class assignments (thus far), your module must work on rcs-sun4.rpi.edu. To submit, log in to rcs-sun4.rpi.edu, and run the program ~lallip/public/ic_submit.pl. The module must be submitted by 6pm today, October 12, 2005.

Do NOT submit any code other than your module. Do not submit the sample main file, do not zip or tar any files to submit multiples. Just the one, single, Movie.pm file should be submitted. DO make sure that your module works with the sample main without any alterations. I should be able to run my sample main file as-is, just by adding your Movie.pm file to the current directory.

Perl Quotes
Perl Quotes