Lab 7 - Structured Programming

 

Overview

Our goal today is to get practice with structured programming. Nothing complicated is built all at once, and this includes programs. While you may be able to get away with writing simple programs directly from start to finish, as the problems we solve become more complicated a little discipline in thinking about the problem first will pay dividends in the time you'll save.

  • The first question you should always ask yourself when reading a problem description is -- "What do I need to do?" You should be able to answer this question to yourself, in your own words, and maybe in more detail than what was given in the assignment.
  • Next, you should write a skeleton for your program. This should include comments about what needs to be done, and a general framework for how control will flow through your program. It may also include method stubs, which are nothing more than the name of a method (potentially with a dummy return statement). The point is to get something you can incrementally refine until you have a working program.
  • Now that all this is done, you are ready to start adding meat to your skeleton. As you add each new part, test it and make sure that it is working correctly. Remember, writing testable code is almost as important (perhaps just as important) as writing correct code. Make sure you understand what your code is doing every step of the way. Remember - if you don't know why your program works, it doesn't.

 

Demo
Here's where we work together on the solution to last week's lab. If you don't understand anything, stop me!

 

Playing on...
This week, let's extend the music program from last week. Download three track listing files into your lab7 directory by executing the following commands:

% wget www.cs.indiana.edu/~jpr/i211/labs/lab7/files/Beatles.txt
% wget www.cs.indiana.edu/~jpr/i211/labs/lab7/files/DireStraits.txt
% wget www.cs.indiana.edu/~jpr/i211/labs/lab7/files/LedZeppelin.txt

Take the three methods you wrote last week (determine_total_time(), determine_total_size(), and determine_longest_song()) and put them in a file called musicsubs.pl.

Do this:
Write a program called newmusic.pl. Use the line require 'musicsubs.pl';, which will allow you to use the methods you defined in that file. Then write code that calls these methods on every file in @ARGV, printing out the total time, total size, and longest song in each.

 

Turn in your assignment
As usual, let's make a tarball of your assignment files (make sure they are ALL in the lab7 directory!) For this lab, you should have the following files:
  • musicsubs.pl
  • newmusic.pl
As a reminder, here's the command you can use:

jpr@sulu (i211/lab7) $ cd ..
jpr@sulu (i211) $ tar czv lab7 > lab7.tar.gz
music.pl
submusic.pl
jpr@sulu (i211) $

You should then download this lab7.tar.gz file and upload to the Lab 7 assignment on Oncourse. Make sure you press "submit" and "finish" enough times to actually upload your file. We will take off points for incorrect submissions, even if you really finished the lab on time.

Okay, that's it! Have a good weekend.

Image from http://www.yvonnelaneinteriors.com/tools/local/imageupload/content/MainImage/size1/00178efba36e4477c4180851e254d298.jpg
Thanks to Jacob Ratkiewicz for lab content, Sid Stamm for CSS stylesheets, and Rob Signorelli for original syntax-highlighting JavaScript.