This is a simple command line project that uses Perl. It assumes that you have downloaded and installed PERL ( if you work on your home machine) and have completed the ICP’s (In Class Projects) prior to working on this exercise. Please review those if you have trouble starting. Available functions that you can use in Perl can be found here.
The above image contains a lot of blocks stacked ton two separate structures. Your problem is to calculate the surface area and total volume of the two separate structures. Start with the following instruction.
print “Enter the squares edge width”; $a=<STDIN>;
Work on the large object first and when that is working add the code to do the small structure. Use a while loop to add up all blocks in each of the layers of the large structure starting at the bottom. The bottom layer has 4 by 5 blocks, the one above has 3 by 4 , etc. Get the picture? Write code that counts the number of blocks first for the two structures. When you get that working then add on the surface area etc. One step at a time.
To get you started here is the code that would count the number of blocks of the small structure.
$numblocks2 = $width + $numblocks2;
$width = $width -1;
print “The number of blocks in the small structure is $numblocks2\n”;
The write Perl code to calculate the surface area and volume of the structures and print out the resulting information in the following form.
The number of blocks in the large structure is ….
The surface area of the large structure is …
The total volume of the large structure is …
The number of blocks in the small structure is ….
The surface area of the small structure is …
The total volume of the small structure is ….
Turn in the source program (your Perl code) and the output. Be sure and comment your perl program at the top, including your name, the project name (IE Blocks HW4) and what the program does.
Use DOS file concatenation to combine the Perl source and output into one file and then print that file.
Advanced Thought: Could you do this if you were told the height (no of blocks) of the structures assuming the pattern is continued?