Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    el gizmo magnifico
    el gizmo magnifico's Avatar
    Guest

    help with perl, Subroutines, need by Monday night (before 9 pm EST if possible)?

    ok I have 1 more problem to go but I can't seem to figure it out on what to do. so can anyone help me.

    here is the problem
    Copy rectangle04.pl to rectangle05.pl. Add code within the subroutine to separately check the values of length and width to be sure they are greater than zero. If either value is zero or less than zero print an informative message and stop the program. All checks should be done in the getArea subroutine.
    HERE IS RECTANGLE04.pl

    #!/usr/bin/perl -w
    #
    # ================= Subroutines ===================
    #
    # --------------------------------------------------
    # SUBROUTINE: max
    # OBJECTIVE: Return the maximum value of two numbers.
    #
    # SAMPLE USAGE:
    # $maxValue = &max($firstValue,$secondValue) ;
    #
    # KNOWN BUGS: No error checking.

    # --------------------------------------------------
    sub max {
    if($_[0] > $_[1]) {
    $_[0] ; # return first value.
    }
    else {
    $_[1] ; # return second value.
    } ;
    }
    # --------------------------------------------------
    # SUBROUTINE: min
    # OBJECTIVE: Return the minimum value of two numbers.
    #
    # SAMPLE USAGE:
    # $minValue = &min($firstValue,$secondValue) ;
    #
    # KNOWN BUGS: No error checking.
    # --------------------------------------------------
    sub min {
    if($_[0] < $_[1]) {
    $_[0] ; # return first value.
    }
    else {
    $_[1] ; # return second value.
    } ;
    }
    #--------------------------------------------------
    # SUBROUTINE: getArea
    # OBJECTIVE: Return the area of a rectangle from the
    # two input numbers.
    #
    # SAMPLE USAGE:
    # $area = getArea($length,$width) ;
    #
    # KNOWN BUGS: No error checking.
    # --------------------------------------------------
    sub getArea {
    my $length = $_[0] ;
    my $width = $_[1] ;
    my $area = $length * $width ;
    return $area ;
    }
    # ================= main program ===================
    print "Enter the first value:" ;
    $firstValue = <STDIN> ;
    chomp $firstValue ;
    print "Enter the second value:" ;
    $secondValue = <STDIN> ;
    chomp $secondValue ;
    $maxValue = &max($firstValue,$secondValue) ;
    print "The maximum value is $maxValue\n" ;

    $minValue = &min($firstValue,$secondValue) ;
    print "The minimum value is $minValue\n" ;

    $getArea = &getArea ($firstValue,$secondValue) ;
    print "the area is $getArea\n" ;

    if you need to know more about what im doing here is the pages

    http://cset.stcc.edu/~edbigos/courses/2008fa/cset-111/hw/hw10.pdf
    if you need to know more about what im doing here is the pages

    http://cset.stcc.edu/~edbigos/courses/2008fa/cset-111/hw/hw10.pdf

  2. #2
    martinthurn
    martinthurn's Avatar
    Guest
    I can't believe how BAD the other two answers are! Do you guys even know Perl? I've been a professional Perl programmer for OVER TEN YEARS. It's so simple:

    if ($length <= 0)
    {
    print STDERR "Length is less than zero, can not continue";
    exit 88;
    }

    Do the same thing for $width

 

 

Quick Reply Quick Reply

Click here to log in


In what corner do we have Search box?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. randomizing subroutines in PERL?
    By chocomilo in forum Discuss PERL
    Replies: 0
    Last Post: 03-11-2010, 06:20 PM
  2. Writing random subroutines in PERL?
    By chocomilo in forum Discuss PERL
    Replies: 0
    Last Post: 03-11-2010, 06:18 PM
  3. WWE vs TNA on 4th of January 2010 : Monday Night War or Monday Night Massacre?
    By The Clown Prince of Crime in forum Discuss Military
    Replies: 0
    Last Post: 01-09-2010, 10:07 AM
  4. I had unprotected sex Monday night, I missed 2 pills and took them Tuesday night
    By Devan in forum Discuss Relationship and Intimacy
    Replies: 4
    Last Post: 09-10-2009, 09:19 AM
  5. Replies: 1
    Last Post: 04-15-2008, 04:45 PM

Bookmarks

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •