Lab 11: wc, Binary Search, and 2D Lists

Goals

After the lab, you should be proficient at

  1. using the wc command in Linux
  2. adapting binary search for use in another algorithm
  3. creating and processing 2D lists

Linux

As usual, create a directory for the programs and output you develop in this lab.

You will want to copy the files from your lab10 directory so that you can extend your Music Management program.

Using the wc Command

Objective: Programming in Python

Adding Searching to your Music Manager (45 pts)

As discussed in class, you will update your MusicCollection class to include a method that finds all the songs that have some title. The method will take as an input parameter the title of the song to search for and returns a list of songs with that title. Your method should: Note that your driver program will be responsible for printing out the songs that match or printing out a message if there are no songs that match. Also, if your sort method also prints the music collection, remove the print because that's a side effect you don't want your sort method to do when you're searching for a song.

You may want to get one of the new albums files added by your peers to help with your testing. They've been added to the handouts/lab10/albums directory too.

Music Manager Driver Program (15 pts)

Add an option that allows the user to find all the songs with some title.

Example Run:

Select one of the following options:
        (V)iew the library
        (I)mport songs into the library
        (S)ort the library
	(F)ind songs by title
        E(X)port the library to a file
        (Q)uit the program

Which option do you want? f
What is the title of the song you want to find? misunderstood

2 songs match that title:
Misunderstood        Better Than Ezra      Closer           00:03:47
Misunderstood        Better Than Ezra      Greatist Hits    00:03:45

Select one of the following options:
        (V)iew the library
        (I)mport songs into the library
        (S)ort the library
	(F)ind songs by title
        E(X)port the library to a file
        (Q)uit the program

Which option do you want? f
What is the title of the song you want to find?  Change your mind

2 songs match that title:
Change Your Mind                    Sister Hazel         Fortress             00:04:22
Change Your Mind                    The Killers          Hot Fuss             00:03:10

Demonstrate Your Program

Demonstrate that your program works in IDLE and save that in an appropriately name ".out" file.

How Much Code Did You Add?

Run the wc command again. This time, view the size of the .py files in your lab11 directory. Add the output from this command to your mywc.txt file using the >> operator. An example of running wc from your lab11 directory is
wc -l *.py >> mywc.txt

Now, when you view your mywc.txt file, you should be able to compute how many more lines of code you added to your files for this part of the project. Document this difference in comments in your driver program.

Working with 2D Lists

For each of the following problems, create a new Python script.

After you've developed a correct solution to each program, restart IDLE or close and reopen the IDLE "shell" by running the program again (using F5), demonstrate that the program works using several good test cases, and save the output to a file named lab11.x.out, where x is the problem number.

Finishing up: What to turn in for this lab

  1. IDLE and jEdit may create backup files with the "~" extension. Delete these files from your lab directory to save paper when you print.
  2. Copy your lab11 directory into the turnin directory. (Review the UNIX handout if you don't remember how to do that.)
  3. Remove the .pyc files from your directory.
  4. Use the printLab.sh command to create a file to print out. You should probably print from the labs directory. You may get a warning about the directory containing subdirectories. As long as you don't get an enscript error about unknown special escape, you should be okay.
  5. You can always view the output before you print it, using the gv command, such as
    gv lab11.ps

    Print the file using the lpr command introduced in the first lab.

Labs are due at the beginning of Friday's class. You should hand in the printed copy at the beginning of class, and the electronic version should be in the turnin directory before 2:25 p.m. on Friday.

Ask well before the deadline if you need help turning in your assignment!

Grading (100 pts)