Your first task will be to come up with an appropriate data


1. Your first task will be to come up with an appropriate data structure for representing numbers of arbitrary potential length in base 215. You will have to deal with large negative numbers also1. (Any negative number is to be stored in such a way that the most significant digit is a -1, but all lower order digits are positive. Note that you will need to make sure that you don't have a multidigit number with 0 as the high order digit. Also, you are required to make sure that the top two high order digits of any number store are not -1,32767. If you have trouble figuring out why, come see me...) You need to write a function that takes a given file that contains a number in base 10, reads it in, and stores it in your data structure in base 215.
2. Given a number that is represented in your data structure, you will need a function that prints it out in base 215 in such a way that its contents can be checked for correctness. Your function will need to print out the "digits" of the number, one digit after another, each separated by a comma with no white spaces in between, high-order "digit" of your number first.
3. You will write functions for both addition and subtraction of two num- bers encoded in your data structure. These functions should not be hard to write. Remember how you add and subtract numbers in base 10 and you should be able to figure out how to do it. Addition should automati- cally calculate the sum of memory locations 1 and 2 and store the answer in memory location 3 (erasing any other number that was previously in memory location 3). Subtraction should automatically calculate mem- ory location 1 minus memory location 2 and store the answer in memory location 3 (again, erasing any previous data).
4. You need to write a function that performs multiplication of two numbers in your data structure. Again, remember how you multiply numbers in base 10 and you should be fine. Multiplication should automatically cal- culate the product of memory locations 1 and 2 and store the answer in memory location 3 (erasing previous data).
5. Write a function that performs integer division. The function should take the large number in memory location 1 and divide it by the large number in memory location 2 disregarding any remainder. The result should be placed into memory location 3. This will probably be your most difficult function to write for this assignment. Remember how you do long division in base 10...
6. Write a function that performs the integer mod function. Given the pre- vious functions you have implemented already, this one should be a piece of cake. This function will find the result of taking the large number in memory location 1 modulo the large number is memory location 2, placing the result in memory location 3. (If location #2 has a negative number in it, then you will take the mod using the absolute value of that number.) The result of a "mod" operation will always be a nonnegative number less than absolute value of the large number in memory location 2.
7. Finally, you need to implement a function which will write out a given user-specified memory location to disk in base 10. That means that you have to convert the large number data structure back into base 10 digits before writing them back out to disk. The user will input the file name that the file is supposed to write to along with which memory location.
Your program should be menu driven and contain menu functions for each of the functions that you had to write above. Your code doesn't need to be superoptimized, but it does need to be good enough so that any given command takes at most one minute to execute. The menu should look as follows.
1. Read in a number from a file 2. Print out a large number to the screen 3. Add two large numbers 4. Subtract two large numbers 5. Multiply two large numbers 6. Integer divide two large numbers 7. Location 1 modulo location 2 8. Write to disk in base 10 9. Quit Choose your option: 1 File name: a.dat Memory location (number between 1 and 3): 1

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Your first task will be to come up with an appropriate data
Reference No:- TGS01487800

Now Priced at $40 (50% Discount)

Recommended (98%)

Rated (4.3/5)