fork download
  1. #!/usr/bin/perl
  2. # Perl Assignment - Hash of Hashes
  3. # Drew Williams
  4.  
  5. # Teams using a Hash of Hashes
  6.  
  7. # Mission Year Comm Module Lunar Modue Leader Co-pilot
  8. # Apollo 13 1970 Odyssey Aquarius Lovell Swigert
  9. # Apollo 14 1971 Kitty Hawk Antares Shepard Roosa
  10. # Apollo 15 1971 Endeavour Falcon Scott Worden
  11. # Apollo 16 1972 Casper Orion Young Mattingly
  12. # Apollo 17 1972 America Challenger Cernan Evans
  13.  
  14. # I have created the following array:
  15.  
  16. @missions = ("Apollo 13", "Apollo 14", "Apollo 15", "Apollo 16" , "Apollo 17");
  17.  
  18. # and the following Hash of Hashes:
  19.  
  20. %aMission = ( "Apollo 13" => { yearLaunch => 1970,
  21. commMod => "Odyssey",
  22. lunMod => "Aquarius",
  23. leader => "Lovell",
  24. coPilot => "Swigert"
  25. },
  26. "Apollo 14" => { yearLaunch => 1971,
  27. commMod => "Kitty Hawk",
  28. lunMod => "Antares",
  29. leader => "Sheppard",
  30. coPilot => "Roosa"
  31. },
  32. "Apollo 15" => { yearLaunch => 1971,
  33. commMod => "Endeavour",
  34. lunMod => "Falcon",
  35. leader => "Scott",
  36. coPilot => "Worden"
  37. },
  38. "Apollo 16" => { yearLaunch => 1972,
  39. commMod => "Casper",
  40. lunMod => "Orion",
  41. leader => "Young",
  42. coPilot => "Mattingly"
  43. },
  44. "Apollo 17" => { yearLaunch => 1972,
  45. commMod => "America",
  46. lunMod => "Challenger",
  47. leader => "Cernan",
  48. coPilot => "Evans"
  49. },
  50.  
  51. );
  52.  
  53. # To print out sorted Team information in the Hash of Hashes (ascending order):
  54.  
  55. print ("\n\nApollo Mission - sorted by Mission Name ascending:\n\n");
  56.  
  57. printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", "Mission", "Year", "Comm Module", "Lunar Module", "Leader", "Co-Pilot");
  58.  
  59. @sortedKeys = sort (@missions);
  60.  
  61. for $missionName (@sortedKeys) {
  62. $yearLaunch = $aMission{$missionName}{'yearLaunch'};
  63. $commMod = $aMission{$missionName}{'commMod'};
  64. $lunMod = $aMission{$missionName}{'lunMod'};
  65. $leader = $aMission{$missionName}{'leader'};
  66. $coPilot = $aMission{$missionName}{'coPilot'};
  67.  
  68. printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", $missionName, $yearLaunch, $commMod, $lunMod, $leader, $coPilot);
  69. print "\n";
  70. }
  71.  
  72. # To print out sorted Team information in the Hash of Hashes (descending order):
  73.  
  74. print ("\n\Apollo Mission - sorted by Mission Name decending:\n\n");
  75.  
  76. printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", "Mission", "Year", "Comm Module", "Lunar Module", "Leader", "Co-Pilot");
  77.  
  78. @reverseKeys = reverse (@sortedKeys);
  79.  
  80. for $missionName (@reverseKeys) {
  81. $yearLaunch = $aMission{$missionName}{'yearLaunch'};
  82. $commMod = $aMission{$missionName}{'commMod'};
  83. $lunMod = $aMission{$missionName}{'lunMod'};
  84. $leader = $aMission{$missionName}{'leader'};
  85. $coPilot = $aMission{$missionName}{'coPilot'};
  86.  
  87. printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", $missionName, $yearLaunch, $commMod, $lunMod, $leader, $coPilot);
  88. print "\n";
  89. }
  90.  
  91. print "\n\nHTML Page containing information on Apollo Missions:\n\n";
  92.  
  93. print "<html>\n";
  94. print "<head>\n";
  95. print "<title>Apollo Mission</title>";
  96. print "</head>\n";
  97. print "<body>\n";
  98. print "<H1>Apollo Missions</H1>\n";
  99. print "<table border=1>\n";
  100. print "<tr><th>Mission</th><th>Year</th><th>Comm Module</th><th>Lunar Module</th><th>Leader</th><th>Co-Pilot</th></tr>\n";
  101.  
  102. for $missionName (sort keys %aMission ) {
  103. $yearLaunch = $aMission{$missionName}{'yearLaunch'};
  104. $commMod = $aMission{$missionName}{'commMod'};
  105. $lunMod = $aMission{$missionName}{'lunMod'};
  106. $leader = $aMission{$missionName}{'leader'};
  107. $coPilot = $aMission{$missionName}{'coPilot'};
  108.  
  109. print "<tr><td>$missionName</td><td>$yearLaunch</td><td>$commMod</td><td>$lunMod</td><td>$leader</td><td>$coPilot</td></tr>\n";
  110. }
  111. print "</table>\n";
  112. print "</body>\n";
  113. print "</html>\n";
  114.  
  115. print "\n\nXML Page containing information on Apollo Missions:\n\n";
  116.  
  117. print "<missions>\n";
  118.  
  119. for $missionName (sort keys %aMission ) {
  120. $yearLaunch = $aMission{$missionName}{'yearLaunch'};
  121. $commMod = $aMission{$missionName}{'commMod'};
  122. $lunMod = $aMission{$missionName}{'lunMod'};
  123. $leader = $aMission{$missionName}{'leader'};
  124. $coPilot = $aMission{$missionName}{'coPilot'};
  125.  
  126. print " <mission>\n";
  127. print " <missionName>$missionName</missionName>\n";
  128. print " <yearLaunch>$yearLaunch</yearLaunch>\n";
  129. print " <commMod>$commMod</commMod>\n";
  130. print " <lunMod>$lunMod</lunMod>\n";
  131. print " <leader>$leader</leader>\n";
  132. print " <coPilot>$coPilot</coPilot>\n";
  133. print " </mission>\n";
  134. }
  135.  
  136. print "</missions>\n";
  137.  
Success #stdin #stdout 0s 5284KB
stdin
#include <iostream>
using namespace std;

const double pi = 3.14159265359;

double cylinderVolume(double radius, double height) {
    return pi * radius * radius * height;
}

int main() {
    double radius = 4.0; // in centimeters
    double height = 10.0; // in centimeters

    double volume = cylinderVolume(radius, height);

    cout << "The volume of the right cylinder is: " << volume << " cubic centimeters." << endl;

    return 0;
}
stdout

Apollo Mission - sorted by Mission Name ascending:

Mission      Year     Comm Module   	Lunar Module    Leader     Co-Pilot    
Apollo 13    1970     Odyssey       	Aquarius        Lovell     Swigert     

Apollo 14    1971     Kitty Hawk    	Antares         Sheppard   Roosa       

Apollo 15    1971     Endeavour     	Falcon          Scott      Worden      

Apollo 16    1972     Casper        	Orion           Young      Mattingly   

Apollo 17    1972     America       	Challenger      Cernan     Evans       


Apollo Mission - sorted by Mission Name decending:

Mission      Year     Comm Module   	Lunar Module    Leader     Co-Pilot    
Apollo 17    1972     America       	Challenger      Cernan     Evans       

Apollo 16    1972     Casper        	Orion           Young      Mattingly   

Apollo 15    1971     Endeavour     	Falcon          Scott      Worden      

Apollo 14    1971     Kitty Hawk    	Antares         Sheppard   Roosa       

Apollo 13    1970     Odyssey       	Aquarius        Lovell     Swigert     



HTML Page containing information on Apollo Missions:

<html>
<head>
<title>Apollo Mission</title></head>
<body>
<H1>Apollo Missions</H1>
<table border=1>
<tr><th>Mission</th><th>Year</th><th>Comm Module</th><th>Lunar Module</th><th>Leader</th><th>Co-Pilot</th></tr>
<tr><td>Apollo 13</td><td>1970</td><td>Odyssey</td><td>Aquarius</td><td>Lovell</td><td>Swigert</td></tr>
<tr><td>Apollo 14</td><td>1971</td><td>Kitty Hawk</td><td>Antares</td><td>Sheppard</td><td>Roosa</td></tr>
<tr><td>Apollo 15</td><td>1971</td><td>Endeavour</td><td>Falcon</td><td>Scott</td><td>Worden</td></tr>
<tr><td>Apollo 16</td><td>1972</td><td>Casper</td><td>Orion</td><td>Young</td><td>Mattingly</td></tr>
<tr><td>Apollo 17</td><td>1972</td><td>America</td><td>Challenger</td><td>Cernan</td><td>Evans</td></tr>
</table>
</body>
</html>


XML Page containing information on Apollo Missions:

<missions>
 <mission>
    <missionName>Apollo 13</missionName>
    <yearLaunch>1970</yearLaunch>
    <commMod>Odyssey</commMod>
    <lunMod>Aquarius</lunMod>
    <leader>Lovell</leader>
    <coPilot>Swigert</coPilot>
 </mission>
 <mission>
    <missionName>Apollo 14</missionName>
    <yearLaunch>1971</yearLaunch>
    <commMod>Kitty Hawk</commMod>
    <lunMod>Antares</lunMod>
    <leader>Sheppard</leader>
    <coPilot>Roosa</coPilot>
 </mission>
 <mission>
    <missionName>Apollo 15</missionName>
    <yearLaunch>1971</yearLaunch>
    <commMod>Endeavour</commMod>
    <lunMod>Falcon</lunMod>
    <leader>Scott</leader>
    <coPilot>Worden</coPilot>
 </mission>
 <mission>
    <missionName>Apollo 16</missionName>
    <yearLaunch>1972</yearLaunch>
    <commMod>Casper</commMod>
    <lunMod>Orion</lunMod>
    <leader>Young</leader>
    <coPilot>Mattingly</coPilot>
 </mission>
 <mission>
    <missionName>Apollo 17</missionName>
    <yearLaunch>1972</yearLaunch>
    <commMod>America</commMod>
    <lunMod>Challenger</lunMod>
    <leader>Cernan</leader>
    <coPilot>Evans</coPilot>
 </mission>
</missions>