[an error occurred while processing this directive]

Perl

Menu

Homework 4

For this assignment, you will create two class modules, one of which uses the other. You will also gain experience in creating test files and documentation for your modules.

PhoneCall

The first class you create will model a telephone call. Please name your module Rcsid::PhoneCall (where "Rcsid" is your RCS Id, with the first letter capitalized). This class has the following properties:

  • number - the telephone number of the other party
  • start - the start time (in hh:mm format) of the phone call
  • length - how long the call lasted (in minutes)
  • made - A boolean value. If the owner of this phone made this call, it is set equal to 1. If the owner of this phone received this call, it is set equal to 0.

This class also has the following methods:

  • dial - a constructor. This creates a new Rcsid::PhoneCall object. It takes in the number, start, and length. It sets made equal to 1.
  • receive - another constructor. It takes the same arguments as dial, but it sets made equal to 0.
  • get_* - four accessor methods, one for each data element. Each one returns the appropriate data value.
  • peak - returns a true or false value. If the call was started during peak time, returns true. Else, returns false. Peak time begins at 09:00. Off-Peak time begins at 19:00. The duration of the call is irrelevant, only the start time matters.

Finally, this class should overload the less than, greater than, addition, and subtraction operators. Less than and greater than can be used to compare an PhoneCall to a number, or to another PhoneCall. Only a number will be added to or subtracted from an object. You need not worry about the results of one object plus or minus another object. All four operators cause the length of the call to be used in the calculation or comparison.

CallLog

The second class you create will be a call log. For example, your monthly cellphone bill contains a detailed listing of every call you made or received. Please name your module Rcsid::CallLog. This class has the following properties:

  • name - the name of the account holder
  • number - the phone number of this account
  • minutes - how many monthly minutes are allocated
  • rate - the rate per minute charged when the allocated minutes are exceeded.
  • calls - an array that contains the list of calls this account made or received this month.

This class defines the following methods:

  • new - a constructor. It takes in the name, number, and rate as arguments. It returns a new object, setting the minutes = 0 and the calls equal to a reference to an empty array.
  • get_* - five accessor methods, that simply return each of the five data elements.
  • set_minutes - takes in the number of minutes to allocate to this account, and sets the minutes property to that number.
  • dial - takes in the number, start, and length of a call to make. Calls the dial method of the PhoneCall class, with these arguments, and then pushes the returned object onto the CallLog's array of calls.
  • receive - similar to dial, takes in those same arguments, but calls the PhoneCall's receive method to create the call.
  • add_call - Takes in an already-created PhoneCall object, and adds it to the calls array.
  • show_log - prints to the currently selected file handle a list of every call that was made or received, in the order in which they were made or received. For each call, display the originating number, the dialed number, the start time, the length, and whether or not the call was during peak. For example:
    From         To           Start Length Peak
    -------------------------------------------
    888-876-5309 518-123-4567 14:00 30     Y
    518-987-6543 888-876-5309 20:00 45     N
    860-877-9362 888-876-5309 09:30 25     Y
  • overage - Returns the current overage charges for this account. The overage charge is equal to the rate times the total calls length minus the allocated minutes. That is, if an account is allocated 100 minutes at an overage rate of 15¢/minute, and the account's total call lengths sum to 150 minutes, the overage is (150-100)*15¢ = $7.50.

For each of dial, receive, and add_call, you should carp out a warning if the new call's length will result in overage charges (ie, if the sum of all the calls' lengths plus the new call's length will be greater than the allocated minutes). This warning should not, however, impact whether or not the call gets added to the log.

Notes

  • The methods listed here are the required methods. You are free to create additional methods if you feel they would be useful to you. It is recommended that if you create any additional methods not intended for use by the main user of your module, you name them with a leading underscore.

Documentation & Testing

You must fully document each module, using POD. You should use the h2xs framework as discussed in class. Make sure you give a brief synopsis, description, and summary of each method's intended usage.

For each module, you must create one or more test files. These test files should use the Test::More class. Make sure to fully test all features and methods of each class.

Grading Criteria

PhoneCall constructors 10
PhoneCall accessors 5
PhoneCall peak 7.5
PhoneCall overloading 7.5
CallLog constructor 5
CallLog accessors 5
CallLog set_minutes 5
CallLog add_call/dial/receive 10
CallLog overage 7.5
CallLog show_log 10
Documentation 10
Testing 10
No Warnings 5
Error Checking 5
Code Style 5
Output Style 2.5

Penalties

  • Compilation errors: -50, code graded subjectively
  • Late, up to 14 hours: -20 points.
  • Late, more than 14 hours: -100 points.

Bonus

Because this assignment is somewhat larger than normal, it is worth a total of 110 points. It will still be graded out of 100, however. Therefore the remaining 10 points can be considered a bonus to be added to your HW total.

No Warnings

There should be no Perl-generated warnings in your code. You, however, should generate warnings to the user (using the Carp module's carp function if they do something wrong.

Error Checking

You must error check all arguments the user passes to your methods. You must make sure that a valid object was returned from the constructors. If there is no way to recover from a user's error, make sure you print out an appropriate error message using Carp's croak function.

Code style

Your code must be readable by a human being. Most important are consistent indentation, explanatory comments, and meaningful variable names. See also: perldoc perlstyle

Output style

Output style is worth less in this HW because the only output your modules should generate is the results of the show_log method. This list should be formatted as shown above, including spacing and newlines. You may find the function printf or sprintf useful to you as you attempt to space out the columns correctly.

Submission Instructions

Before submitting, make sure you have fully documented and tested your modules. If you have any special instructions or notes, edit the README file that h2xs created. Then, inside each module directory (ie, ~/Rcsid-PhoneCall and ~/Rcsid-CallLog) run the command make dist. This will create a tarball (a .tar.gz file) containing all of your code, documentation, tests, Makefile, README, etc.

After running this command, execute ~lallip/public/submit.pl on solaris.remote.cs.rpi.edu. Submit only the two tarballs. Do not submit any other files individually.

You may submit infinite times. Make sure every submission you make has both tarballs. Your final submission is due at 11:59:59pm Wednesday, April 7, 2010.

Perl Quotes
Perl Quotes