For this lab, you are welcome to get technical help from another student on how to use or install any of the tools involved. You may also get syntax help on C. You may not, however, get help on the algorithmic portion of the exercise outside of office hours or piazza questions to TAs or instructors.
$ cd CNET-cs152-spr-16 $ mkdir hw7 $ svn add hw7 $ cd hw7
$ cd cs152-spr-16-duet-X $ svn update $ mkdir hw7 $ svn add hw7 $ cd hw7
You will be using the full power of repositories - repositories have two purposes: 1) backup your work in case you accidentally delete something 2) allow two people to work on different files of the same project at the same time. We will use this for both purposes.
At any given time, you should coordinate with your duet partner as to who is editing which file. Whenever your file is in a stable state (you completed something and, depending on the phases, got the compile errors out of it), you commit your file. Whenever you want to get the latest set of stable changes from your partner, you svn update.
Good luck and have fun learning together!In this warm-up, you are going to practice going between the binary representation of integers and different representations to print out (decimal, hex, octal, binary). You are going to perform these operations by storing the result in a provided string rather than print to a file or to the screen. This will make it easier for you to check your work. For efficiency, a character array (with unknown contents) will be passed into the functions. The functions then fill in the character array to create a string with the right representation. This means it must end with a '\0' character.
Copy these function prototypes into a head file warmup7.h.
int int_to_decimal_uns_string(unsigned int n, char *str); int int_to_decimal_sgn_string(int n, char *str); int int_to_hex_string(unsigned int n, char *str); int int_to_octal_string(unsigned int n, char *str); int int_to_binary_string(unsigned int n, char *str);
You are to write the function header in the .h and the .c files. n is the number that is going to be translated, and str is the location where the result will be placed. str has already been allocated by the caller. Do not allocate space for it. It returns the number of digits in the string representation.
If you call int_to_binary_string(17,buf); where buf is a char array with at least 33 chars, it will write 00000000000000000000000000010001 into buf and return 32.
int_to_hex_string(15,buf) will write 0F to buf and return 2.
Please note the following details:You will be graded both for correctness and proper abstraction and generalization. Do not submit large blocks of similar code that have been copied, pasted, and edited. Think carefully instead and use your programming skills to write auxiliary functions that generalize computational patterns by abstracting over different inputs.
You may not use any C library calls in these functions. You must place every character in the array directly.
You will be graded on the efficiency of your solution. You should have a linear time solution that is very clean and easy to read.
Place your test cases in test_warmup7.c. Make a Makefile using prior weeks' makefiles as examples. It needs to create an executable named convert.
char buf[50]; int_to_hex_string(31,buf); if (!strcmp(buf,"1F")) { // it is correct } else { // it is incorrect }
$ svn add hw7
mkdir CNET-cs152-spr-16/hw7 cp cs152-spr-16-duet-0x/hw7/* CNET-cs152-spr-16/hw7/* cd CNET-cs152-spr-16 svn add hw7
$ svn add *7* Makefile
$ svn commit -m "hw7 warmup complete"