You are expected to have some experience with programming prior to this course, as most of the problem sets will include implementing an algorithm. The programs you write will not be fancy, but they will require that you be comfortable writing and debugging programs of perhaps two to three pages in length. The types of programming features you should know are:
- How to read input from the user and write output to the user
- How to perform loops and conditional statements
- How to declare and call subroutines
- How to specify and use an array (i.e. a subscripted variable)
- How to write recursive function calls
The programs we write will not require complicated programming statements; the sophistication comes from the algorithms that we will implement, not the language features you will be using.
You are allowed to use whatever language you like, with the following caveats:
I like the first two because I can run them without compiling them, so we don't run into any compiler incompatibilities. If you are going to use a compiled language, I would prefer that you keep the code generic. In particular, I don't want it to have any IBM/PC graphics calls or mouse I/O dependencies.
- My preferred languages are:
- Java (if you have to)
- My second choices are:
- C or Pascal
- FORTRAN (if you really are into numerical programming)
- Mathematica (if you have no other choice)
Some of you may wish to use Mathematica to write your code. I would prefer you didn't since I'm boycotting it, but if you must, please be sure that your code works with version 4.0 as I do have access to this if I really need it. I do not have ready access to Maple or MATLAB, so I would prefer you not use these as your programming language.
When you turn in a programming assignment, you should include the following:
It is a good idea for your program to print out the values that were input (in which case, you can give me just the output). For example, if your program prompts for the coefficients of a polynomial and a value for a tolerance variable called "epsilon", and uses these to find an x-value where the polynomial is within epsilon of zero, your output might look like:
- A written summary of the main points of your program. That is, describe the basic structure of what your program does, and any important aspects of your implementation of the algorithms. You don't have to explain the details that we have already worked out in class, but should say how you have organized your program to handle the algorithms. If your assignment was to modify an algorithm from class, you should explain the important new ideas that you have included, and the changes that you have made.
- Enough comments within your code to make it clear what is happening. For instance, if you use global variables, you should say what they are for. (It is a good idea to name them appropriately, too; for example, if you are writing a program that uses polynomials, it is better to have an array named "coefficients" than one named "a".) Each subroutine should be described briefly (and named appropriately), and you should point out any subtle ideas that it might include.
- A printout of the final, working version of the program.
- A printout of the input that you need to supply for your program to run.
- A printout of the output produced by your program for the input you have supplied.
Polynomial: 1 x^2 + -2 x + -5 Root: x = 3.449 (for an epsilon of .005)
If you are running on a Unix machine, you can capture the output of your program into a file using "redirection". For example, if your program is called
hw1, then the command
hw1 > hw1.out
will capture the output of your program into a file called
hw1.out. (You can also store the input in a file and not have to retype it every time you run your program. For example
hw1 < hw1.in > hw1.out
read the input from
hw1.inand stores the results in
You may be able to get a file that includes both the input and the output by using the script or enscript commands (see the man pages for more details).