CS270 Fall 2013 Programming Assignment PA1 - radix conversion in C

Essentials

Due: Friday Sept 13 2013 @ 12:00 (noon)
Key: Use the key PA1 for checkin

About The Assignment

This assignment is designed to teach you how to:

First read the Getting Started section below and then study the documentation for radix.h in the Files tab to understand the details of the assignment. In addition, be sure th read and understand the notes on Number Systems including the part dealing with fractions (for extra credit).


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. PA1).
  2. Copy the three 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 three commands to build the executable.
    
        gcc -g -Wall -c -std=c99 testRadix.c
        gcc -g -Wall -c -std=c99 radix.c
        gcc -g testRadix.o radix.o -o testRadix
        
  5. In the terminal type testRadix and read how to run the the program.

You now have a functioning program. All the commands work. However, none will produce correct results at this point.


Completing the Code

Before attempting to write any of the functions of radix.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 radix.c using your favorite editor.
  2. Save your changes and recompile radix.c using gcc -g -Wall -c radix.c. 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. (Re)build the executable using gcc -g testRadix.o radix.o -o testRadix.
  5. Test the function you have been working on. Do not attempt to move on until you complete and thoroughly test a function. You will find that the function int2char() is called int the int2str() function and that char2int() is useful in str2int(). Therefore, you might write the functions in the following order:
    1. char2int()
    2. int2char()
    3. int2str()
    4. str2int()
    5. str2frac() [Extra Credit]
  6. Repeat steps 1 thru 5 for the remaining functions.

Checking in Your Code

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

    ~cs270/bin/checkin PA1 radix.c
  

The above command submits your assignment. For a sanity check, type the following to get the file you checked in and make sure it compiles and runs properly with the provided files:

    mkdir sanityCheck
    cd sanityCheck
    ~cs270/bin/peek PA1 radix.c > radix.c
    cp ../radix.h ../testRadix.c .
    gcc -g -Wall -c -std=c99 testRadix.c
    gcc -g -Wall -c -std=c99 radix.c
    gcc -g testRadix.o radix.o -o testRadix 
    // Do LOTS of test cases.
Relax, you are done with your assignment!