Assignment 1

Due by 6pm on Sunday, January 23.
Create a file named hw.c in your math211hw directory. This file should be a copy of the "Hello world" program and should print
Hello world.
on the screen and the prompt should appear on the next line. If you want to make sure that I will be able to collect your file, type
Assign1
and hit enter. You should get a message back telling you that your file was found.

Assignment 2

Due by midnight on Thursday, February 3.
Create a file sr.c in your math211hw directory.
It should contain a main() which evaluates Simpson's Rule on a function. The integral should begin at 1 and continue to 3. You should use 100 steps in the program. The function to be integrated is to reside in an external file. The header file should be called function.h. In it will be the declaration
float fun(float);
You are welcome to use the tr.c, function.c and function.h files as a starting point for your own work. Indeed, you need never modify function.c and function.h at all.
Finally, you should print out your amswer to the screen on one line and then print a newline so the prompt is on the next line, just as we usually do. The printout should be 9 characters long with 6 of them following the decimal point.
If you want to make sure that I will be able to collect your file, type
Assign2
and hit enter. You should get a message back telling you that your file was found.

Assignment 3

Due by midnight on Monday, February 14.
Write a program to impliment Picard's method (Thomas/Finney p.626). The file should be called pm.c and should have an "#include function.h" line and a separate function.c file which contains the code for a function
float fun(float);
Your program should iterate the function until the nth iteration is within .001 of the n+1st or until you have done a thousand iterations. The initial value to begin the iterations should be 0.5. Your program should print the value of the function at the n+1st iteration (or the value of the function after a thousand iterations) using the format, 9 characters, 6 following the decimal point and then a newline.
Typing "Assign3" and hitting enter should return a message back telling you that your file was found.

Assignment 4

Due by midnight on Friday, February 25.
Add two commands to the calc.c program. You can write the first case using the functions you already have in Stack.c, but to do the second one you will need to add a new function to Stack.c (with the appropriate declaration in Stack.h). The new function is to be named Clear_Stack. It should take no variables and return nothing.
Assign4 will check if your homework can be collected.

Assignment 5

Due by midnight on Wedneday, March 8.
Add three commands to the calc.c program, d, h and H. The end result of these new commands is that the calculator will have both a decimal mode (in which numbers are entered and printed base ten) and a hex mode (in which numbers are entered and printed base 16). All the changes in your code should take place in the calc.c file and this will be the only file collected.
As examples, in decimal mode 30 hp should produce an output of 1e; 30 Hp should produce an output of 1E. When you are in hex mode, AA dp aa dp Aa dp and aA dp should all produce 170. In decimal mode again 30 hpHp should produce 1e on a line and then 1E on the next line.
You will also have to deal with the problem that c, C, and d can all mean different things depending on whether you are collecting a hex number or clearing the entry/stack or switching to decimal mode. Once you have begun to collect a hex number, they should all just be hex digits, but if they occur first (like the - sign) when we might be collecting a hex number, then you will have to do a wait-and-see maneuver as we did for -.
In a bit more detail, if you are in decimal mode, typing a 'c', 'C' or 'd' does the appropriate clear or keeps you in decimal mode. If you are in hex mode and have begun to collect a number, 'c', 'C' and 'd' are hex digits. If you are in hex mode but not yet collecting a number and you get a 'c', 'C' or 'd', you need to get the next character. If it's a digit then so was the first character, if it is not then neither was the first character. A question you might want to think about is how, under this scheme, you would enter the single digit hex number C.

Assignment 6

Due by midnight on Wednesday, April 5, 2000. Copy the file tree_stuff.h from our common space. It contains the declaration of a function
int count_nodes( wc *root);
You need to create a file, tree_stuff.c, containing the code for this function (and ONLY the code for this function). It should count the number of nodes in a binary tree pointed to by root. In particular, if root is 0, you have the empty tree and the function should return 0. As a hint, look at the code for the print_tree function and try to emulate it.

Assignment 7

Due by midnight on Wednesday, April 12, 2000. Use the "tree_stuff.h" and "tree_stuff.c" files from our common space. The "tree_stuff.h" already has the declaration for a function to take a tree and produce a new tree which is balanced (i.e. has as small a level as possible with the same ordering). Your assignment is to write the code in "tree_stuff.c" to make the function work.

More precisely, you need to write a function
wc* balance_tree(wc* initial);
which expects as its input a pointer to the root of a tree and which returns a pointer to the root of a balanced tree with the same data. I suggest that you use the tree_to_array function (also in tree_stuff.c) to keep pointers to the data while you are rearranging the tree. In the end you should have a new tree with the same data in the same order but with as few levels as possible.


Assignment 8

Due Wednesday, April 19, 2000 at midnight. Write a complete program (including a main) in one file to be called
Exp.c
which does the following. The command line is to look like
a.out   file_out   file_in ...
where ... may be more file names sperated by spaces.
1. If not at least two file names on command line, print a message
Usage: a.out file_out file_in ...
kick down to a new line and then exit.
2. If file_out exists, print a message
"file_out" exists and will not be over written.
The line should begin with a quote, file_out should be replaced by the name of the file which is first on the command line, and the second quote should follow immediately. Each word is separated by a space from the next and there is a period at the end (no space before or after the period). Finally, kick down to a new line and then exit.
3. Read each of the file_in's, in order, as a sequence of shorts.
4. Write one output file called file_out. The data in this file should be a sequence of doubles. Each double is exp of the corresponding short.
5. There is a file called XX in our common space which is a string of shorts that you may use to test the program. There is a file YY in our common space that is the correct output for the input XX.
6. If you fail to open the output file, print the message
Failed to open output file "file_out".
kick down to a newline and quit. If one of the input files fails to open print the message
Failed to open input file "??".
kick down to a newline and then continue to the next input file.

Assignment 9

Due Wednesday, May 3, 2000 at midnight. Modify the trapezoid rule Perl program to achieve the following behavior. Call the file PTr. To use the program, type
PTr lower_bound upper_bound number_steps function_code1 ...
where ... indicates that you may have several different functions to which you wish to apply the tapazoid rule. The output should be printed as a formated floating point number with 9 characters and 6 decimal places.
Some error checking needs to be done. If there are not at least 4 elements on the command line print the message
Usage: PTr lower_bound upper_bound number_steps function_code1 ...
and exit.
If number_steps is 0 or negative print an error message
The number of steps must be positive. You have number_steps.
End with a newline and exit. The phrase number_steps should be replaces with the actual value of number_steps and you should use the Perl print statement, NOT the formatted print statement.
If lower_bound is greater than upper_bound print a message
Lower bound lower_bound is greater than upper bound upper_bound. Will integrate anyway.
You should end the message with a newline. Then you should apply the usual trapezoid rule with the limits reversed and print the negative of the answer this yields. Of course the phrases lower_bound/upper_bound should be replaced by their current values and you should use the Perl print statement rather than the formatted print statement.

Back.