COSC 1435 Bonus Lab
Purpose:
This lab is to look at how to manipulate numbers, by developing a program
that displays the manual process of long division of integer numbers that
you learned in elementary school.
Due:
May 8, 2013
Requirements:
Do the following:
1. Write a program
that inputs two two numbers. Write the program so that it divides the first
number by the second and display the long division process as if you were
doing long division by hand. All of the long division process must work properly.
Show the remainder, when the integer division is complete. The program must
work properly for all positive and negative integers, except division by zero
(check for this and give an error message). This program must go through/show
all the intermediate steps that occur during long division, giving just an
answer, even if correct, does not satisfy this lab. Hints:
- Do several iterations of long division, by hand, and note exactly what you
do at each step. Look for a pattern that could be turned into a loop. What
causes the loop to terminate?
- When you integer divide by 10, what happens?
- Determine whether the result
is positive or negative, and save it, then use only positive numbers until
the process is almost over.
- Do not try to start coding this
project until you have a good plan (pseudocode), that you have tested to determine
that you will receive the correct answer.
- The very last step is the screen
display, after every thing else is working properly. Then, and only then,
use the information you stored as the long division process occurred to create
a nice looking screen output. Do not try to duplicate the long division method
on the screen. Just properly document each step, so I can tell what you are
doing.
I recommend you do this program in phases, but for this lab, you need only
turn in the final completed lab. I recommend that you break the project into
phases as follows:
- Phase A. Get the input and validation routines working properly. You will
probably want to handle negative numbers during this phase.
- Phase B. Write a function that takes in a number and will return the value
of a specific digit. For example, if the number I send to the function is
95773, and I want digit 1 (zero based), the function would return 5. You cannot
do this problem without this function.
- Phase C. Write the divide routine, that outputs the data in a debug format.
My output at this stage looked like this. You
may turn in your lab at this stage and receive full credit.
- Phase D. For bonus credit, change your output so that it actually looks
like long division, as if done by hand. I did fudge the answer in one way
for this example, the answer on top of the long division problem, was done
using the built in divide and modulus operators, since the answer is not known
until the end, but everything else was done as it was calculated. My output
at this stage looked like this. This is more difficult
than it looks like.
2. Allow the user
to input multiple pairs of numbers to be divided.
3. Make sure your
program is properly documented and good programming standards are followed,
including properly type casting conversions between variable types. There
should be no float or double variables in the program.
4. Try your program with a variety
of input values, to determine it works properly. For test values, I suggest
you use these pairs of numbers: 1 / 0, 1 / 1, -1 / 2, 5 / 3, 3 / 5, 1 / -999999,
10 / -2, 73 / 21, 95483 / 4381, and -9654223 / 23167.
5. 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:
- Your Name
-
Purpose of this program.
- Program psuedocode or flowchart
- Program source code
- How was this program tested, including the input values you used to test
the program.
- What problems/successes did you have with this program?
- An estimate of how much time you spent working on this lab
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 lab15***.cpp, where the ***
is replaced with your initials.
-
A copy of
your program output saved as a file. This file should be called lab15***.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 lab15***doc.txt for a text file or lab15***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. 40 bonus
points availble as described in Part D above.