The goal of this assignment is to produce O'Caml code that will help you answer a set of questions about the top-grossing films in movie history. To get started, download the tarball located here. Unzip and untar the code and data by typing the following commands at a unix prompt.
$ tar -xfz a2.tar
You should find that the tarball contains the following items.
data
: This directory contains the data you need to answer the
questions asked on this assignment.
The data was downloaded in May 2012, so it will be slightly out of date ---
films like the The Hunger Games will have continued to rack up the dollars over the
last few months. That's ok. In order to make it easy to verify your answers, you are required
to use the data we provide as opposed to more recent data that you download from other sites.
There is one file for each movie rating category (G, PG, PG-13, R) and one file for all-time
inflation-adjusted gross movies. There are also a couple of small files you can use for
testing. You will find that the data in the files comes in an arbitrary order.
query.ml
: This file is mostly blank. You will write a set of functions
to analyze lists of movies. This is the file you will focus on primarily.
README.txt
: Report your answers to the movie trivia questions in this file.
Also, explain any unusual design decisions or problems you had here.
Makefile
: Type make all
to compile your code and
create an executable you can run to help you answer the key boxoffice trivia questions.
main.ml
: This file contains the driver for the program. Don't modify this file, but
you can take a look to see how it's organized. It uses the module Arg to parse command line
arguments in a nice way.
io.ml
: This utility file contains a set of useful routines for
parsing and printing movie files. Don't modify it, but feel free to take a look to
see how it's organized. If you'd like to parse and print other
simple text files using O'Caml, this code could be a starting point.
The file main.ml
is missing a bunch of functions that you need to code.
See the file for details. Your goal should be to focus first on this file independently
of any of the other files. Use the O'Caml top-level environment to fully debug all
functions you create first before proceeding with the second part of the assignment.
You will use these functions to query just a few data files. However, we will test
your functions thoroughly when grading them (and you should test them thoroughly when
writing them). They should operate correctly on all possible inputs. At the bottom
of the file there is one bit of sample data data4
and one unit test test1
.
You must create many more such tests to debug your code.
Since the data files you are working with are relatively small, you should not overly concern yourself with the efficiency of your code. However, none of your functions should be more than quadratic in complexity. Your main goals are correctness, clarity and good style. Be sure to refer to our style guide.
For this assignment, you should not use functions from the List module. You should code these functions "from first principles" using recursion.
We suggest you implement them in the following order.
take
-- return only the first n elements of a movie listdrop
-- return everything but the first n elements of a movie listaverage
-- return the average gross of all moviesdecade
-- return all movies produced in that decadesort
-- a polymorphic (selection) sort functionsort_by_gross
-- selection sort by gross revenue sort_by_year
-- selection sort by year produced by_studio
-- return total gross from all movies produced per studio Scripting is a kind of functional programming: Scripts take data files (often representing lists) as inputs and produce new data files as outputs. Like functions in a functional program, scripts often compose: you can pipe the output on stdout of one script into the input on stdin of another script.
When you have finished coding and thoroughly testing the functions in query.ml
,
compile the entire application by typing "make" at a shell prompt in your code directory.
To find out what you can do with your script, type the following at a shell prompt.
./boxoffice -help
You should see a list of options you can use. As a simple sanity check to make sure things are working properly, type the following:
./boxoffice -echo < data/trial1.txt
The above command should send the contents of the trial1.txt data file out on to standard output. We also included that test as a part of your makefile so you can also type the following to check your setup.
make checkAnother command you might try is this one:
./boxoffice -take 1 < data/G.txtWhat does it do? Recall that the pipe operator (vertical bar) allows you to send the output of one command in to the input of another command. With that in mind, what does the following do?
./boxoffice -sort-gross < data/G.txt | ./boxoffice -take 1
Now, take a look inside the makefile. You will see the clause for compiling boxoffice at the top. At the bottom, you'll see the clause for "topG". If you type:
make topGyou'll see the same thing. Feel free to add your own commands to the file.
To Do: Use your script to answer some questions about boxoffice trivia. Report your answers in the README.txt file. Also report the scripting commands you used to find the answers. Try to make the script do as much work as you can. If possible, use a series of calls to your script to produce only the data you need to answer the question and no more. (This may not be possible.)
Recall, you are not required to do Karma questions. They will have little if any impact on your grade. They are mostly for fun and a little extra challenge. Be sure to do the other questions first and ensure they are correct.
This problem set is to be done individually.
You must hand in these files to dropbox:
query.ml
-- this file contains the bulk of your solutionREADME.txt
-- this file contains written answersio.ml
-- this file does not need to be modified at all unless you did the Karma questionmain.ml
-- this file does not need to be modified at all unless you did the Karma question Be sure to include your name and netid at the top of every file.
Please make sure you submit your solutions, not the blank stubs you downloaded.