
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A lab assignment for a computer science course focusing on if and while statements in perl programming language. The assignment includes six programming tasks: averaging test scores, computing factorials, preventing division by zero errors, and avoiding infinite loops. Each task includes an algorithm and a perl program with testing instructions.
Typology: Lab Reports
1 / 1
This page cannot be seen from the preview
Don't miss anything!
BIF 101 Lab 9 – if and while statements (ch 6)
Assigned: November 13, 2008 Due: November 20, 2008
For each of the following write (1) an algorithm and (2) a program to solve the given problem. Test your program, demonstrating that it works and also demonstrating where (if this is the case) and how it will fail (e.g. inputs are not what is expected). Paste your code and the results of testing and results into a word file that you will submit via email.
Input the number of test scores a user will type, and input that many scores, computing and printing the average of the scores. Test the program with at least 5 scores and without entering any scores. Describe what happens.
Like avg1.pl but instead of having the user input the number of scores in advance tell the user what to type when he/she is ready to quit (“sentinel value”). This program should also check to see if there are no scores and should output a message – this will prevent a division by 0 error.
Write a perl program that uses a while loop that inputs a value and computes and prints the factorial of that value. Note that 0! is defined to be 1 as is 1! The factorial is the product of the numbers from 1 up to a given positive integer. Make sure to test you program on a negative number input, 0 input, and positive number input. Try typing a large positive number – what happens? Note you may have to kill the running program with control-C.
Like fact.pl but your program should check to make sure the number entered is > = 0 and < = 7. The program should keep prompting the user until an appropriate value is entered. Then the program should compute and print the factorial value.
Choose one of the programs you have written with a loop and comment out a statement that may cause the program to have an infinite loop. Run the program, explain what happens and why the loop will never stop.
Create a program that implements the search for CG-rich regions in a DNA sequence described in section 6.8.2 of the book. Explain how the program works.