CS 2213 Advanced Programming, Fall 2000 Lab Assignment 2


Due Thursday, September 21, 2000

Lab Assignment 2 has 2 parts.


Part 0:
Write a function:
void printTree15(int vals[]);
which takes an array of size at least 15 as its parameter.
This will print the elements of the array on 4 lines in tree form.
The root of the tree (vals[0]) will be on a line by itself ending at position 40.
The next line will contain vals[1] ending at position 20 and vals[2]ending at position 60.
The third line will contain vals[3] through vals[6] ending at positions 10, 30, 50 and 70.
The last line will contain vals[7] through vals[14} ending at positions 5, 15, 25, 35, 45, 55, 65 and 75.
For example, one line of your function might be:
printf("%20d%40d\n",vals[1],vals[2]);
or you might use three lines:
printf("%20d",vals[1]);
printf("%40d",vals[2]);
printf("\n");

Put the function in a file called printtree15.c and write a main program to test this. Use a makefile and use separate compilation. Be sure to also run lint.


Part 1:
Write a function:
void printTree(int vals[], int size);
which is like printTree15, but stops after size entries. For example, if the array entry at index i is the square of i, then printTree(vals,5) should produce output like
                                      0
                   1                                       4
         9                  16
Put your function in a file called printtree.c and write a main program (in a separate file) to test it. Be sure to use make and run lint. Your test program should create an array in which the element at index i is the square of i. Run the program with size equal to 11. Use cut and paste to send the output to cs2213 as part of a mail message with subject line:
cs 2213 lab assignment 2 results

Be sure that you use cut and paste. Do not send your results as an attachment which assumes a particular type of mail reader.

Do not send this email before Friday, September 15.