Question

Perl Programming CSCI 2215 Section Name: Assignment 5 (100 pts) Instructions: Submit an electronic copy of the assignment to
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part a:

This code contains a hash definition at first, then Hotel and Category are printed, * is printed. q{ }; is used as comments.

%hotels=("Pillowmint Lodge" => "5",
"Buxton Suites" => "5",
"The Middletonian" => "3",
"Notchbelow" => "4",
"Rancho El Cheopo" => "1",
"Pile Inn" => "2"
);
print "Hotel Category\n\n";
print "*********************************\n";
foreach $key (keys %hotels) { q{To traverse through every key of hotel keys function is used};
$a = int($hotels{$key}); q{Variable a is used to store the number of star in integer form by first converting the value of the key to integer from string};
print "$key |"; q{Printing the key of hotels hash};
for(;$a>0;$a--){ q{array to print number of stars of the hotels listed};
print "*";
}
print "\n";
}
print "*********************************\n";

Part b:

This code contains a hash definition at first, then Hotel and Category are printed, * is printed. q{ }; is used as comments.

%hotels=("Pillowmint Lodge" => "5",
"Buxton Suites" => "5",
"The Middletonian" => "3",
"Notchbelow" => "4",
"Rancho El Cheopo" => "1",
"Pile Inn" => "2"
);

print "Hotel Category\n\n";
print "*********************************\n";
foreach my $key (sort {$hotels{$b} <=> $hotels{$a}} keys %hotels){ q{Just this line is different else everything is same, here sort function is used to sort the hash in descending order of values of hash then simply each call to the key is made from highest stars first to lowest star at the last};
$a = int($hotels{$key});
print "$key |";
for(;$a>0;$a--){
print "*";
}
print "\n";
}
print "*********************************\n";

Add a comment
Know the answer?
Add Answer to:
Perl Programming CSCI 2215 Section Name: Assignment 5 (100 pts) Instructions: Submit an electroni...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT