assignments
due Mon Sep 10
preliminaries
- First thing: if you're taking this course, send me some email so that I can get your username into the course software system.
- Start getting your software tools in order.
- Install (if you don't already have one) a text editor. (See the resources page for some helpful links.)
- Install (if you don't already have it) perl (ditto).
- Make sure you can get to the command prompt on your computer (mac: Utilities/Terminal; microsoft: menu start / run / cmd) to invoke perl ("perl -v" should tell you it's version number.)
- Start browsing through the links on the resources page.
- Read chapter 1 in the text, "First Steps".
- Do chap 1, exercise 1 on pg 11.
- Submit your work by clicking the "submit work" button on the assignments page after you've logged in with the link at the top-left of your browser window. (If you can't log in, talk to me.) You should turn in
- your code for exercise 1,
- a brief blurb describing what you computer background is, and
- how all the work described above is going.
due Mon Sep 17
scalars and booleans
- work through chapter 2
- Write a program that asks for three numbers, and then prints out their sum and product.
- Do exercise chapter 2 number 1 on page 50.
- The substr function can be used to extract characters from a string.
# get a substring of length 1 starting at character number 3
# (starting count at 0)
print substr("012345", 3, 1);
Using substr() and ord() described on page 34, write a program that prints the ascii numbers for each letter in a word input by the user.
- Describe briefly what the following operators do, and what the difference is between them.
+ - * / ** .
== < > <= >=
eq lt gt le ge
not !
and &&
or ||
cmp <=>
- Try the following lines in perl, and explain what you get.
print "answer='", ( 0 or 1 ), "'\n";
print "answer='", ( 8 <=> 10 ), "'\n";
print "answer='", ( 8 cmp 10 ), "'\n";
print "answer='", ( 3 < 5 and 10 > 7 ), "'\n";
print "answer='", ( 21 == 3 * 7 ), "'\n"; # why not (21=3*7) ?
print "answer='", ( 0b101010 ), "'\n";
print "answer='", ( 0xFF ), "'\n";
due Mon Sep 24
conditionals and loops
- Revisit the problem from last week of printing the ascii code for each letter in an input word. The length() function returns the number of characters in a string; use it to handle an arbitrary length word correctly.
- Write a program that asks several questions (pick at least three), and prompts the user to type 'yes', 'no', or "" (no answer) after each. Whenever anything other than 'yes', 'no', or "" is typed, the program should ask the same question again. After three failures to respond, the answer should be set to "" and the next question should be asked.
- Do one of the following:
- Write a program to find all the prime numbers between 1 and 1000. (A prime is a number that cannot be evenly divided by any smaller number other than 1.)
- Write a program to search for perfect numbers, which are those which are the sum of its proper positive divisors. For example, 28 = 1 + 2 + 4 + 7 + 14 is perfect.
- Write at least six variations of a short program that asks for a word and prints "You said yes" if the user types 'yes'. Look particularly at the different ways of branching mentioned in this chapter.
due Mon Oct 1
lists
- Read chapter 4 in the text.
- Re-do the "three questions" exercise from last week using lists.
- Write a program that reads in at least six words, and then prints them backwords.
- Explain what the difference is between "scalar context" and "array context" in perl, and give an example of each.
- Explain exactly what's going in each of the following lines.
my ($foo, @foo, $x, @y, $list, @list, @alphabet);
$foo = "hello";
$foo = ("hello");
$foo = ("hello", "goodbye");
@foo = ("hello");
@foo = ("hello", "goodbye");
print "The number of elements in \@foo is " . scalar(@foo) . "\n";
$x = @y = "hello"; # what is $x after this?
$list = 100;
@list = ('zero', 'one', 'two');
$list[0] = 0;
print '@list is ' . " (@list) \n";
print '$list is ' . " $list \n";
@alphabet = 'a' .. 'z';
$a = pop(@alphabet);
print "\$a is $a \n";
print 'while $a[-1] is \'' , $a[-1] , "'\n";
print 'and @alphabet is ' , @alphabet , "\n";
- Explain the push, pop, shift, and unshift operators, and give an example of each.
due Mon Oct 8
hashes; subroutines part 1
- Read chapter 5; start reading chapter 6.
- Explain what a "hash" is. Give an example.
- Explain what the following terms mean: function, input parameter, return value, local variable, global variable, scope. Give examples.
- In one file, write functions that have the following inputs and outputs, and show how each can be used.
- Input: a number. Output: true if the number is prime, false if it isn't.
- Input: a string. Output: the number of words in the string.
- Input: A prompt string. Output: the text input by the user after the prompt.
- The same, but only allow "yes" or "no" as user input.
- The same, but only allow a number as user input. (Hint: You can use "0+" to convert to a number.")
- Input: a character. Output: the morse-code representation of that character. (Hint: use a hash to store the information.)
- Input: a list of strings. Output: the same list sorted by the length of the strings in increasing order (i.e. shortest first, longest last).
- Pick any two of the programs you've written for earlier assignments, and re-write them using subroutines to break them into smaller pieces.
- Write a program that asks the user for a string, and then prints that string in morse code.
due Mon Oct 15
Regular Expression
- First, read what I said about your last subroutine homework. Or, if you didn't do that ... do it now. If you need to work on that part more, do so, and turn in revised versions: that's more important than this next bit. Feel free to use any of the regular expression stuff ...
- Read about regular expressions. You have a number of choices; see what fits your experience and taste:
- Do exercises 1 and 2 on page 175 of the text.
- If time and skill allow: write a program that turns text into pig latin. (See for example wikipedia:pig latin for a definition.)
- Give me an update on how you think things are going so far. OK? Too fast? Too slow?
due Mon Oct 29
files and system
- read through chapters 8, 9, 10, on files, strings, and the operating system
- Download the files american-english and british-english.
- Write a program that reads the two files and prints out
- how many words there are in each file,
- what percentage of the words are in one file but not the other,
- the longest words from each file.
- Write a program that prints out its command line arguments, one per line.
- Write a program that prints a list of the files in the current directory.
due Wed Oct 31
midterm project
- your first graded program
- include documentation and sample input/output
- Pick one of the following three problem:
- (1) Analyze census statistics
- counties.txt is a file of population statistics for vermount counties.
- (obtained from http://www.census.gov/ , select "vermont" in box on right, clicked "alphabetic for counties", click "print/download" the resulting table of county populations in tab separated format.)
- Write a perl program to read in that file, and print out a summary of estimated 2006 populations, sorted largest to smallest, including the percentage each county is of the total.
- (2) Make a restriction enzyme map
- This is a FASTA file of human DNA.
- Here are lots more
- This is an enzyme list
- Here are lots more
- The task is to read in these two files, and find the locations where the enzymes (or some of them) cut the DNA.
- (3) Find palindromes (words that read the same forward and backwards) in the dictionary file from the previous problem.
due Mon Nov 5
references
- read chapter 11 (references). Also look at the perl tutorials
- start reading the "objects" stuff for the next assignment; see below.
- Write a program that stores a 3 x 3 matrix representing a tic-tac-toe board. Include subroutines to make a move on the board and print it out. Show it doing a few simple things like
- print a blank board
- put an X in the top left, and print that
- put an O in the center, and print that.
- Write a program that contains information about movies. Each "movie" should contain at least its name and a list of actors. Put the information about a few movies directly into the program code. When it runs, the user is asked for a movie name, and the program responds by printing the information for that movie. (This is very similar to the address book example in the text.) Optionally, input the movie database from a text file of some sort.
due Mon Nov 12
objects
- start reading chapter 12 (objects). Also look at the tutorials
- Write an object oriented program that defines and illustrates the use of a "Shape" class which contains a "size" parameter (a scalar), a "position" parameter (a pair of x,y coordinates), accessors for size and position, a "new" constructor, and a "describe" method.
- Add to the previous exercise "Square" and "Circle" classes which inherit from Shape, each of which implements an "area" method in different ways. Have your program create a number of circles and squares and print some stuff about each.
due Sun Nov 18
modules
- Read chapter 13 (modules)
- Browse through the perl modules in the standard library. Pick one to try out, and write a short program that uses it.
- Browse through the perl modules in CPAN. Pick one to try out, install it, and write a short program that uses it.
- Pick and describe a final programming project of your choice. The topic is up to you, but it should be something that lets you demonstrate your grasp of the work we've done this semester. Possible projects include
- a program to read and manipulate a file, like the ones for the midterm project
- something that playes a game or allows a user or users to play it (battleship, tic-tac-toe, cards - don't get too fancy)
- something that solves a puzzle or word-search
- a program that draws a picture
- a program that automates a task
- Not sure? Come talk to me.
due Mon Dec 3
CGI
- Read chapter 14, on CGI scripts
- Browse some online docs on HTML, such as wikiversity basic HTML and CSS
- Create on your cs.marlboro.edu account a CGI script that displays a randomly chosen quotation.
- Start work on a "bulletin board" script that lets a vistor type their name and a message, and displays all such messages. The basic idea is to use a form to get the data, append it to a file when the user submits the form, and display the file each time the page loads. (This will be due the following week.)
due Mon Dec 10
CGI part 2
- Create the "bulletin board" cgi script described in the last assigment.
- Be ready to present your final project to the class on Mon or Tues.
due Fri Dec 14
final project
- Write a perl program that solves a problem of your choice, and which shows what you can do.
- As we've been talking about all term, you should include (and will be graded on) the code (whether it works, how clear it is), the documentation (overview, sample input/output, etc), and your testing (so that you and I are convinced it does what it should).
term grade
- placeholder for Jim's comments