Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Loops and Arrays - Take Home Quiz #6 - Introduction to Bioinformatics | BIF 101, Quizzes of Bioinformatics

Material Type: Quiz; Class: Intro to Bioinformatics; Subject: Bioinformatics; University: Canisius College; Term: Unknown 1989;

Typology: Quizzes

Pre 2010

Uploaded on 08/16/2009

koofers-user-bdi-2
koofers-user-bdi-2 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
BIF 101 Take Home Quiz # 6 – loops and arrays
DO ON YOUR OWN!!!! It’s fine to use your book and class notes. Note that this
material will appear on the final, you need to understand it.
DUE: Tues. December 9, end of the day, via email.
1. Trace the following program for 2 different sets of input as specified below. Your
tracing table should include all variables, conditions, and any output. It’s fine to use tabs
to format the trace values, you need not actually create a table as long as your answer is
clear and well-formatted.
Input from the user: (1)
(2)
Program:
my @scores;
my $index = 0;
my $score;
print "type a score, to quit type a negative number: ";
$score = <>;
chomp($score);
while ($score >= 0)
{
$scores[$index] = $score;
$index++;
print "type a score, to quit type a negative number: ";
$score = <>;
chomp($score);
}
if ($index > 0)
{
print "You typed the following $index scores:\n";
foreach my $s (@scores)
{
print "$s\n";
}
pf2

Partial preview of the text

Download Loops and Arrays - Take Home Quiz #6 - Introduction to Bioinformatics | BIF 101 and more Quizzes Bioinformatics in PDF only on Docsity!

BIF 101 Take Home Quiz # 6 – loops and arrays

DO ON YOUR OWN!!!! It’s fine to use your book and class notes. Note that this material will appear on the final, you need to understand it.

DUE: Tues. December 9, end of the day, via email.

  1. Trace the following program for 2 different sets of input as specified below. Your tracing table should include all variables, conditions, and any output. It’s fine to use tabs to format the trace values, you need not actually create a table as long as your answer is clear and well-formatted.

Input from the user: (1) (2)

Program:

my @scores; my $index = 0; my $score;

print "type a score, to quit type a negative number: "; $score = <>; chomp($score);

while ($score >= 0) { $scores[$index] = $score; $index++;

print "type a score, to quit type a negative number: "; $score = <>; chomp($score); }

if ($index > 0) { print "You typed the following $index scores:\n";

foreach my $s (@scores) { print "$s\n"; }

  1. Write an algorithm (NOT a program) that inputs scores from a user until a negative score is input. Values must be stored in an array. Your algorithm must be accurate in terms of using an index into the array and updating it correctly. Assume that you can call sort function to sort the values in the array once they have all been input. Call the sort function, then print the median score. You may assume that there are at least 2 scores entered.

When there are an odd number of values the median is the middle value, for example, if there are 5 scores then (when sorted) the 3 rd^ value is the median.

When there are an even number of values the median is the average of the middle two elements. For example, if there are 8 scores then the median is the average of the 4th^ and 5 th^ scores.

You can easily find out how many scores have been entered based on your index value. How can you tell if a number is even or odd? How will you determine the middle index value in the array?

  1. Write a Perl program that inputs score values into an array until a negative score is typed, uses the sort function to sort the array, and prints the smallest, second smallest, largest, second largest, and average of the values. You may assume there are at least 2 values entered.