18.10.2014 Views

COSC 1P03 Assignment 3

COSC 1P03 Assignment 3

COSC 1P03 Assignment 3

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

than 9, the ones digit of the sum is used for the corresponding digit in the result and a carry (of 1) is<br />

carried to the next digit position. Thus, at any digit position, the sum is of the corresponding digits plus<br />

the carry from the previous position (which is either 0 or 1). If there is a carry in the leftmost position,<br />

the result has an additional digit, being the carry.<br />

Subtraction<br />

Subtraction works much like addition. Starting at the ones position, the corresponding digits are<br />

subtracted. If the difference is non-negative, this is the digit of the result. If the difference is negative, a<br />

borrow (of 1) is borrowed from the next position and the digit of the result is the difference increased by<br />

10. Again, at any position, the difference is the difference in the corresponding digits minus the borrow<br />

from the previous position (which is either 0 or 1). Since negative BigInt values are not supported, the<br />

second value should not be greater than the first and thus there cannot be a borrow in the leftmost digit<br />

position.<br />

Comparison<br />

Equality occurs if each digit in the corresponding digit positions are equal. Values with differing<br />

numbers of digits are unequal with the longer being the greater. With equal number of digits, the digits<br />

can be compared from the highest order position until unequal digits are encountered at which point the<br />

value with the smaller digit is the smaller.<br />

Multiplication and Division<br />

Multiplication and division can be implemented (not very efficiently) as repeated addition or subtraction,<br />

respectively.<br />

Testing<br />

To test your implementation, you must first create a .jar file from the Numbers package<br />

(Project/Create Jar File from Project) into the Numbers folder. Create a project in the<br />

Test folder with a class for testing ArrayBigInt. Import Numbers into this class, define variables<br />

using the BigInt type and create BigInt objects using ArrayBigInt constructors. Results of<br />

testing should be written to an ASCIIDisplayer. In your test project, add the .jar file in<br />

Numbers as an Extra Classpath (Project/Properties). Compile and run your test class to<br />

test your implementation. Marks will be awarded for quality of testing.<br />

Submission:<br />

Details regarding preparation and submission of assignments in <strong>COSC</strong> <strong>1P03</strong> are found on the <strong>COSC</strong><br />

<strong>1P03</strong> website at URL: http://www.cosc.brocku.ca/Offerings/<strong>1P03</strong>/AssignGuide.pdf. This<br />

document includes a discussion of assignment preparation, programming standards, evaluation criteria<br />

and academic conduct (including styles for citation) in addition to the detailed assignment submission<br />

process copied below. Part of the marks for the assignment will be awarded for programming<br />

standards.<br />

To prepare and submit the assignment electronically from the lab, follow the procedure below:<br />

1. Ensure your folder (say Assign3) for the assignment is stored on your Z: drive.<br />

2. Print (to PDFCreator) the .java file of your ArrayBigInt class for the assignment<br />

using the name ArrayBigInt.pdf and save the .pdf file at the top level of the project<br />

folder (i.e. directly within Assign3).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!