cs270 Programming Assignment - print a number using recursion

Essentials

Due:
Key:

About The Assignment

This simple assignment is designed to teach you how to use the C address-of operator (&) and the dereference operator (*). It is a brief introduction to C pointers. This assignment will also provide you a reference when you implement this functionality in the LC3 assemnly language.

First read the Getting Started section below and then study the documentation for printnum.h in the Files tab to understand the details of the assignment.


Getting Started

Perform the following steps
  1. Create a directory for this assignment. A general scheme might be to have a directory for each CS class you are taking and beneath that, a directory for each assignment. The name of the directory is arbitrary, but you may find it useful to name it for the assignment (e.g. PAx).
  2. Copy four files into this directory. It is easiest to right click on the link, and do a Save Target As.. for each of the files.
  3. Open a terminal and make sure you are in the directory you created in step 1. The cd command can be used for this.
  4. In the terminal type the following command to build the executable.
    
        make
        
    You should see the following output:
    
        gcc -g -std=c99 -Wall -c printnum.c
        gcc -g -std=c99 -Wall -c testPrint.c
        gcc -g -std=c99 -Wall printnum.o testPrint.o -o testPrint
        
  5. In the terminal type testPrint and read how to run the the program.

You now have a functioning program. However, it doesn't do anything!


Completing the Code

Before attempting to write any of the functions of printnum.c, study the documentation in found in the files tab. Plan what you need to do before writing code.

The best way to complete the code is to follow a write/compile/test sequence. Do not attempt to write everything at once. Rather choose one function and do the following steps.

  1. Write some/all of one function in printnum.c using your favorite editor.
  2. Save your changes and recompile printnum.c using make. You will find it convenient to work with both a terminal and editor window at the same time.
  3. Repeat steps 1 and 2 until there are no errors or warnings.
  4. Test the function you have been working on. Do not attempt to move on until you complete and thoroughly test a function.
  5. Repeat steps 1 thru 5 for the remaining functions.

The function printNum() must call printDigit() to print a single digit. Therefore, you might first write code in printNum() to do nothing but call printDigit() with the numerator parameter. Then you can write and debug printDigit().

Now you might modify printNum() to simply call divRem() with the parameters numerator/base. You may use C's printf() to print the results. Now, write and debug divMod(). However, you may only use printf() for debugging. Your final code may only use putchar().

Finally, since your two support functions are completely debugged, you may write and debug the actual code for printNum().


Checking in Your Code

You will submit the single file printnum.c using the checkin program. Use the name PAx. At the terminal type:

    ~cs270/bin/checkin PAx printnum.c
  

The above command submits your assignment.

Relax, you are done with your assignment!