CS 2213 Advanced Programming, Spring 2001 Programming Assignment 0


Due Thursday, February 8, 2001

Programming Assignment 0 has 6 parts. Note that you need to do part 5 if you complete part 1, even if you do not complete the other parts of the assignment.


You will be writing and testing the multiple precision aritmetic routines discussed in class. See the class notes for some of the details.

You are to write the functions for handling integer arithmetic described in arithmetic.h and put them in arithmetic.c. The format for storing the integers was discussed in class. You must use the format exactly as it was specified.

The goal is to get this working correctly, not to write the most efficient code. However, your functions cannot use any arrays other than those passed as parameters and you cannot use any dynamic memory allocation.

Use the cover sheet as the first sheet when handing in your assignment. The cover sheet gives a list of what needs to be handed in. Make sure you understand all messages generated by lint and fix any problems indicated.


Part 0:
Make a directory called assign0 and copy all of the files from /usr/local/courses/cs2213/spring2001/assign0 into this directory. You will have a makefile as well as the arithmetic.h file. You will also have a copy of arithmetic.c which contains the functions we looked at in class and a driver.c program which you will modify.

Compile these programs and run the driver. (It doesn't do much.)


Part 1:

Keep the value of 5 for INTSIZE for this part of the assignment.

Write the functions addposint and printint. Put these in arithmetic.c Write a main program called driver.c that starts by printing your full name. It then reads two integers from standard input using readint, prints these using printint, calls addint to add the numbers and the displays the results using printint. Make sure you check the results of readint and addint for errors and display an appropriate error message if necessary. It should be clear from the output what numbers are being added and what the result is.

Use this to test your program fro the cases handled by addint so far, those in which the numbers to be added have the same sign. Run tests which show all of the important special cases you need to handle. Save the results to be handed in.


Part 2:
Write subposint and greater and finish addint. Use your driver to completely test you programs. Save you output to show how you tested your program.


Part 3:
Write subint which should be very similar to addint and test it. Modify your driver so that it also produces the difference of the numbers entered. Test and save your output.


Part 4:
Write multint and test it. Modify your driver so that it also produces the product of the numbers entered. Test and save your output. You probably want to increase INTSIZE to at least 10 for testing this.

Multiplication is considerably harder than addition or subtraction. You might want to start by writing a function like:
int multint1(char a[], int n, int k, char c[]);
which multiplies a by n and adds the result shifted over k places to c.


Part 5:
In this part you will run my test programs on your code.

You will run two tests on your program.

Start by making a subdirectory of assign0 called small. Make sure you have compiled your program with INTSIZE equal to 8 and copy arithmetic.o into this directory. Copy all of the files from /usr/local/courses/cs2213/spring2001/assign0/smalltest into your small directory. Execute
make
and you should have a executable called testsmall. Run testsmall and redirect the output to a file. If everything is correct, a congratulations message should appear. Hand in the output from this test.

Now go back into your assign0 directory and change INTSIZE to 50. Execute
make clean and then make.
Make a subdirectory of assign0 called testlarge and copy your arithmetic.o into this directory. Copy all of the files from /usr/local/courses/cs2213/spring2001/assign0/largetest into your large directory. Execute
make
and you should have a executable called testlarge. Run testlarge and redirect the output to a file. If everything is correct, a congratulations message should appear. Hand in the output from this test.