Honolulu Coders Discussions - TechHui2024-03-28T20:07:15Zhttp://www.techhui.com/group/honolulucoders/forum?feed=yes&xn_auth=noPerl Programmer Questionstag:www.techhui.com,2014-12-31:1702911:Topic:1325562014-12-31T13:05:27.375ZTom Bodinehttp://www.techhui.com/profile/TomBodine
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;"><strong>This is a sample Perl Homework set I got from a potential employer. Try it out.</strong></p>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;">This homework assignment helps us assess your programming abilities. Your mission, should you choose to accept it, is to complete the assigned task and send your completed files to us within one week of receipt.…</p>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;"><strong>This is a sample Perl Homework set I got from a potential employer. Try it out.</strong></p>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;">This homework assignment helps us assess your programming abilities. Your mission, should you choose to accept it, is to complete the assigned task and send your completed files to us within one week of receipt.</p>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;"><b>Description</b></p>
<p style="margin-bottom: 0in;">Perl supports an object oriented interface. A sample object has been provided in the file Cat.pm. Sample use of this object is in the file cat.pl. These two files will be the starting point of your project.</p>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;"><b>Prerequisites</b></p>
<ol>
<li><p style="margin-bottom: 0in;">Download and install perl on the operating system of your choice.</p>
</li>
<li><p style="margin-bottom: 0in;">Run the cat.pl script to verify your perl installation.</p>
</li>
</ol>
<p style="margin-bottom: 0in;"></p>
<p style="margin-bottom: 0in;"><b>Coding Tasks</b></p>
<ol>
<li><p>Modify the constructor to initialize the cat’s age to a random number between 5 and 10.</p>
</li>
<li><p>Modify the constructor to accept the cat’s initial name.</p>
</li>
<li><p>Add a new method called <b>speak</b>() to make the cat say “meow”.<br/> (Hint: use the print function.)</p>
</li>
<li><p>Modify the <b>speak</b>() method to take an optional argument.<br/> If not supplied, the cat still says “meow”.<br/> If supplied, the cat prints the value of the argument.</p>
</li>
<li><p>Modify the <b>set_name</b>() method to keep an array of all names the cat has ever had.</p>
</li>
<li><p>Create a <b>names</b>() method to return all the names the cat has ever had.<br/> Modify cat.pl to set several cat names then print out the list of names.</p>
</li>
<li><p>Modify the object so that the cat’s age increases by 1 every five times it speaks.</p>
</li>
<li><p>Create a new method <b>average_name_length</b>() that returns the average length, in characters, of all the names the cat has ever had.</p>
</li>
</ol>
<p style="margin-bottom: 0in;"></p>
<p><b>Expanding the Code</b></p>
<ol>
<li><p>Copy Cat.pm to Dog.pm and make the necessary changes so it works.</p>
</li>
<li><p>Modify your script to create both cats and dogs with names.</p>
</li>
</ol>
<p style="margin-bottom: 0in;"></p>
<p><b>Testing Tasks</b></p>
<ol>
<li><p>Create a short series of unit tests to demonstrate the cat’s age is indeed between 5 and 10.</p>
</li>
<li><p>Create unit tests to demonstrate the constructor indeed accepts an initial name.</p>
</li>
<li><p>Create unit tests to assert the <b>speak</b>() method is properly functioning.</p>
</li>
<li><p>Create any other unit tests you deem appropriate.</p>
</li>
</ol> Count Nodes interview problemtag:www.techhui.com,2014-12-30:1702911:Topic:1323822014-12-30T15:10:05.861ZTom Bodinehttp://www.techhui.com/profile/TomBodine
<p>I recently solved this for a job interview. See how you do with this.</p>
<p><span id="yui_3_16_0_1_1419948947413_45840" style="font-size: 11pt; font-family: Calibri, sans-serif; color: #1f497d;">There exists in memory a tree of nodes.<br></br> The programming question is to write the body of the function 'countDescendents' shown below. The example is shown in Java, but you can supply the solution in your programming language of choice.<br></br> <br></br> The Node class is defined as:<br></br> <br></br> public…</span></p>
<p>I recently solved this for a job interview. See how you do with this.</p>
<p><span id="yui_3_16_0_1_1419948947413_45840" style="font-size: 11pt; font-family: Calibri, sans-serif; color: #1f497d;">There exists in memory a tree of nodes.<br/> The programming question is to write the body of the function 'countDescendents' shown below. The example is shown in Java, but you can supply the solution in your programming language of choice.<br/> <br/> The Node class is defined as:<br/> <br/> public class Node {<br/> public Node firstChild;<br/> public Node nextSibling;</span></p>
<p><span id="yui_3_16_0_1_1419948947413_45840" style="font-size: 11pt; font-family: Calibri, sans-serif; color: #1f497d;"> public string name;<br/> }<br/> <br/> The function signature is:<br/> <br/> public int countDescendents(Node node) {<br/> ....<br/> }<br/> <br/> For example, if a node was represented by a box with a right pointy end for nextSibling and a downward pointy end for firstChild, then a family tree show might look like this:</span></p>
<p><span id="yui_3_16_0_1_1419948947413_45840" style="font-size: 11pt; font-family: Calibri, sans-serif; color: #1f497d;"><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/1044614117?profile=original"><img width="750" class="align-full" src="http://storage.ning.com/topology/rest/1.0/file/get/1044614117?profile=RESIZE_1024x1024" width="750"/></a>if countDecendants was passed grandpa, it would return 12.<br/> <br/> <b id="yui_3_16_0_1_1419948947413_45848">The countDescendents function should traverse the descendents of the node using only the firstChild and nextSibling attributes of Node.</b></span></p>
<p></p>