Chris Pollett > Old Classes > PIC40 ( Print View ) Lecture Notes-PDF Spring '01 Ad: Enrollment info Course Info:
Practice Exams: PIC: |
HW2 Solutions Page<html> <!-- Filename: p40hw2file1.php Purpose: This is the file that sets up the frame layout for the site the wily platypus site. --> <head> <title>The Wily Platypus</title> <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" /> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="Authors" content="Christopher Pollett" /> </head> <frameset cols="30%,70%"> <frame src="p40hw2file2.php" name="index" scrolling="yes" /> <frame src="p40hw2file3.php" name="content" scrolling="yes" /> </frameset> <noframes> <!-- Be nice to lynx users. --> Your poor browser does not appear to like frames. <a href="p40hw2file3.php">Click here</a> to see the main document. </noframes> </html> <html> <!-- Filename: p40hw2file2.php Purpose: This file contains the left hand frame for the site the wily platypus. This is file contains some links which act as an index to the right-hand document --> <head> <!-- Notice each frame has a head and a body. This make it easier to split if don't want frames at some later date. Also might keep some browsers happy--> <title>The Wily Platypus</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="Authors" content="Christopher Pollett" /> </head> <body style="background: #99FFCC"> <h3 style="text-align: center">Index</h3> <p> <a href="p40hw2file3.php#intro" target="content">Introduction</a> </p> <p> <a href="p40hw2file3.php#gestation" target="content">Gestation</a> </p> <p> <a href="p40hw2file3.php#plural" target="content">Pluralizing Platypus </a> </p> <p> <a href="p40hw2file3.php#avoid" target="content">Avoiding Platypus Attacks </a> </p> <p> <a href="dumbness.org/pictures/platypi.htm" target="_top"> Another Platypus Site</a> </p> </body> </html> <html> <!-- Filename: p40hw2file3.php Purpose: This file contains the right hand frame for the site the wily platypus. This is essentially a text document describing what a platypus is --> <head> <title>The Wily Platypus</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name="Authors" content="Christopher Pollett" /> </head> <body style="background: white"> <h1 style="text-align:center">The Wily Platypus</h1> <a name="intro"> <h3 style="text-align:left"> Introduction </h3></a> <p> Here you could have a whole bunch of content saying what a platypus was. But I am lazy so I am not going to tell that a platypus is a mammal nor that they live in Australia. Don't expect me to divulge that they have a duck-like mouth or a beaver-like tail and are otherwise furry. In fact, I am going to start spewing random characters now tell I am done at least one screen. So there. djhsjdg fhdh sdfth hdfghh dshghgjdj dfjdjdgh djfjh gg gghgh ghhg gh gh ghgh gh gh ghghghghyrturtyuetru tyrty tyrytry et ye ty tey t tyu eytuyruthrjhtuw ghdfghjdh wtrethwreht trewywty rewjhtjwreh trjhtejrhjt gfdgjnherhtjkrhjk rtjhj rejhjer trhjre retjre rtkjrjt rejktsn rtjwjn trwepolrp aw;ltlhmm wep[q </p> <a name="gestation"> <h3 style="text-align:left">Gestation</h3></a> <p> Did you know that platypus lays eggs? Time to babble again. adsghajdfg gakagjkfg gajhgfjkad gaklgakjg agkhgjag gakghag adkgjkre rrhetyjht gfdhgf shfh sh hshg shhhsyty ysrey y t asrt yhklklerw gkyhjkrt yktsryj sryeyjtw syhjjkst syrhjtryh;s syhjskthy ksyjtykj hyjtrjk j56h5j4 46hjqw43h 54hgq34h5 g rj6tyhejy tjyhejty jhyjerh jhyetjhyhj wyrekwhjrt wjyhjyhjhe yjehwjhytehj jhtyy yejehjeytyjhkjh ejhuhejkuehuj ejhuj;jk </p> <a name="plural"> <h3 style="text-align:left">Pluralizing Platypus</h3></a> <p> A very philosophical conundrum. Oh well. ksfjdkg trjehtjwerh gfsjbhjtr fdshfg eajthjret thrthj tkrejhtwjh tjhrwhthj sgjhrthjhjr djjdj rtyeytn dyuty rtjwrehj ytjhtrjh erjthtrjyh ryjhetj eyktj triute ywjhytw rtwjhjwrt yrwjhyhtj yrwjhyjh wyjhyj whgyhgy wlkjyj jwyjkweyh ywhyghjew ywhlqat p;wep[ra; tkysowe plty kytkjthjkju kyurjkyu ryklyrklkjly ryel;ksdyrlkl lkreklt fsgjkfd sdfghjfdhkjghjfghjsfgh fsdjgjsfdjghdfh nsfdghgfhjsfdh gsjdfgsdfhhjsf fsdhjskjgh jksgjksdfhj fdjghjsfdhgf sfdjhsfghjgfg fsdjgjsdhfhjgsfgh sdfgjhsfdhgsjdg sfdjhsjghjgj sfjdgfgsgdgh sgfdjgjshjfgj gsjhfgdjg sgjhdfgsdf sgjdgjshjgf sghjfg sfgjhgsfdhh sgfjfdfj sgfkjgfdf sgfkjgsfdh gsfdjgjh gsfshjfg sdgdjgfsdhjg fgsjgfdhjsgf sfgfjkgfhfg </p> <a name="avoid"> <h3 style="text-align:left">Avoiding Platypus Attacks</h3></a> <p> I don't know. Ask Crocodile Dundee. </p> </html> # # FileName: p40hw2file4.plx # # Purpose: This program gets a table of people's names followed by the # animals they like from the user. It then prints out the # distinct animals in alphabetical order together with all # the people who liked that animal also in alphabetical order. # # Example: # # Bob emu # Alice tiger # Jane emu # ^D # # Returns the result: # # emu: # Bob # Jane # # tiger: # Alice print "Please enter some people's names followed by a space followed\n"; print "by their favourite animal. Hit ^D (^Z<RET> on NT) when done.\n"; chomp(@inarray = <STDIN>); #each element of @inarray is in form "$name $animal" #the chomp gets rid of the trailing \n of each elt. @inarray = sort @inarray; # peoples names will now be in order # make the hash table, animals as keys and people's names as values. foreach $pair (@inarray) { ($name, $animal) = split(/\s/, $pair); $table{$animal} = "$table{$animal}\t\t$name\n"; # add the people's names to a row of hash table # note how we are also adding formatting instructions } @animals = sort keys(%table); # # print out hash table # foreach $animal (@animals) { print "$animal:\n"; print $table{$animal}; } |