COSC 1335 Lab 13

Purpose: This lab is designed to provide experience working with converting integer decimal numbers to binary and binary numbers to decimal numbers, using functions, loops, and arrays.

Due: Before class on May 6, 2013

Requirements C++ Programs: You will be writing a series of C++ programs for this lab.

1. This lab will be in phases that allows for an orderly design and development process.

Phase A. This phase will be done as a group project in the beginning of the lab. Write a driver program with a do while loop that inputs an integer number in the range from -32768 to 32767. This range of numbers can be stored in 16 binary digits. Validate the number is in the legal range using a while loop. Put in stubs/function prototypes for the convDecToBin, convBinToBinary, twosComplment, integer power function, and printBinary functions. We will write the printBinary function as a group.

Phase B. Code a convDecToBin function that works for positive numbers, in the range of 0 to 32767, based upon the class discussion and the text (Brookshear, Figures 1.16 - 1.18, page 43). This function is designed to be passed in a integer decimal value and return the binary equivalent in an array of bools that is passed back to the calling function. You must reverse the binary digits in this function and not in the function that prints the binary digits. You may not use C++ library functions to complete this phase of the assignment. Print out the values of the bool array from the calling program (printBinary function). Test your program, especially for 0, 1, 3, 8, 15, and 32767, to verify it works properly. Here is my output to compare against your output (it includes the later phases of the program).

Phase C. Complete your convDecToBin function so that it can properly handle negative numbers. To do this you will need to write a 2-complment function (Brookshear Figure 1.22, page 48) that is called from your convDecToBin function for negative numbers. You may not use C++ library functions to complete this phase of the assignment. Test your program, especially for -1, -3, -8, -15, and -32768, to verify it works properly.

Phase D. Code a convBinToDec function (Brookshear Figure 1.15, page 42). This function will take in the Boolean array and return an integer that represents the value of the information in the Boolean array. You can use this function to ensure you properly did both conversion. This function must properly handle negative numbers stored in 2-complment. Verify your program works properly.

2. Prepare a lab report/documentation package. All of these items do not need to be in the same file or word document, but the main lab report file must reference each item by name. Make sure a digital copy of each item is attached to the email. The lab report must includes the following information for the final program (phase C):

3. Bonus. For 25 additional points, add in a function that adds two binary numbers. The function header is as follows:

void addBinary(bool bArray1[], bool bArray2[], bool bArrayResult[], const int iSize)

where bArray1 is the first incoming array to be added, bArray2 is the second incoming array to be added, bArrayResult is the array where the result of the add operation are stored, iSize is the size of the binary array. Modify your main program to properly call and display the result.

Program Submission. You will be submitting this lab via Blackboard. The teaching assistant will provide further instructions on how to accomplish this. Prepare the following:

Submit via blackboard following the instructions given during the lab.

Grading Criteria: 100 points available for this lab. 25 bonus points are available as shown above.