Answered step by step
Verified Expert Solution
Question
1 Approved Answer
~ Perl Assignment 01 ~ Objectives To get practice in using the Perl language by using common programming concepts: Scalars, arithmetic, user input, if-statements, loops
~ Perl Assignment 01 ~
- Objectives
- To get practice in using the Perl language by using common programming concepts:
- Scalars, arithmetic, user input, if-statements, loops
- Create 2 Perl scripts given the following specifications
- To get practice in using the Perl language by using common programming concepts:
- Perl Program 01A
- Create a perl script named LastnameFirstname01A.pl.
- Include strict and warnings at the top of your program.
- This script will compute the circumference of a circle given a radius.
- The formula for computing circumference is 2r, that is 2 * pi * r.
- You may use the value 3.14 for the value of pi.
- Store the value of pi in a scalar variable.
- Output a message stating to the user that this script calculates circumference.
- Ask the user to enter in the radius.
- Retrieve the radius from standard input and store it in a scalar variable.
- Calculate the circumference.
- If the user enters a number less than zero, output 0 instead of a negative number.
- Output the result of the calculation.
- Ensure all output is properly labeled.
- It is okay when your program crashes if the user enters letters or symbols instead of a number, we will deal with those later.
- Ensure that your code is sufficiently styled and documented.
- Styled meaning code is indented when applicable, variables are named properly, etc.
- Documentation includes a program description at the top and in-line comments throughout the script.
- See posted examples in the Lecture Material page.
- Perl Program 01B
- Create a perl script named LastnameFirstname01B.pl.
- Include strict and warnings at the top of your program.
- Note: This script has no user input.
- Create a loop to print the numbers from 1 to 100, each number on its own line.
- You do not need an array to accomplish this, simply create a loop that counts from 1 to 100 and print the loop increment variable.
- Modify the loop so that numbers with certain characteristics print a word instead:
- For numbers divisible only by 3, print "Spam" instead of the number.
- For numbers divisible only by 7, print "Musubi" instead of the number.
- For numbers divisible by 3 and 7, print "SpamMusubi" instead of the number.
- All other numbers, just print them out.
- Use the modulo operator % to determine if a number is divisible by another number.
- For example, to test if a number is divisible by 3, the condition would be:
- if ($i % 3 == 0), where $i represents the number you want to test which can be replaced by a value or another scalar variable that contains the number.
- Ensure that your code is sufficiently styled and documented.
- Styled meaning code is indented when applicable, variables are named properly, etc.
- Documentation includes a program description at the top and in-line comments throughout the script.
- See posted examples in the Lecture Material page.
- Submission Guidelines
- Submit both your perl scripts to the Digital Dropbox.
- Be sure to check your hawaii.edu e-mail for confirmation of your submission.
- Due Date: Tuesday, Jan. 25 by 11:55pm
- Submit both your perl scripts to the Digital Dropbox.
- Perl Program 01B Output
> perl MeyerEdward01B.p1 1 2 Spam 4 5 Spam Musubi 8 Spam 10 11 Spam 13 Musubi Spam 16 17 Spam 19 20 SpamMusubi 22 23 Spam 25 26 Spam Musubi 29 Spam 31 32 Spam 34 Musubi Spam 37 38 Spam 40 41 SpamMusubi 43 44 Spam 46 47 Spam Musubi 50 Spam 52 53 Spam 55 Musubi Spam 58 59 Spam 61 62 SpamMusubi 64 65 Spam 67 68 Spam Musubi 71 Spam 73 74 Spam 76 Musubi Spam 79 80 Spam 82 83 SpamMusubi 85 86 Spam 88 89 Spam Musubi 92 Spam 94 95 Spam 97 Musubi Spam 100
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started