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):
• Purpose of this program.
• Program psuedocode is not required for this lab.
• Program source code
• Program output
• What problems/successes did you have with this program?
• An estimate of how much time you spent working on this lab

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:

• Your program source code. This file should be called lab13***.cpp, where the *** is replaced with your initials.
• A copy of your program output saved as a file. This file should be called lab13***.txt, where the *** is replaced with your initials. The .txt signifies that this is an ASCII text file.
• A lab report as described above. The lab report may be in a Microsoft Word document, with a .doc suffix or an ASCII text file with a .txt suffix. Make sure it contains all of the required items. This file should be called either lab13***doc.txt for a text file or lab13***doc.doc for a Microsoft Word file, where the *** is replaced with your initials.

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.