Appropriate data structure for representing numbers

Assignment Help Basic Computer Science
Reference no: EM131109814

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

Reference no: EM131109814

Questions Cloud

Contract between buyer and the seller : Apply the CISG to the above contract between Buyer and the Seller. Your analysis and decision need to include the following: Applicability of the CISG; The rules on the goods;
Analyze bargaining situation and whether it is distributive : Analyze the bargaining situation and whether or not it is distributive. If so, determine the reservation price. Present the initial offer you would make and apply bracketing to achieve your target price of $310,000.
Explore some of current issues facing the private security : Analyze why it is important to conduct legal and ethical private investigation and security practices. What consequences may occur if illegal or unethical practices are followed?
Find the period of the resulting oscillatory motion : The distance of the block from the wall is switched on. Assuming elastic collisions (if any) find the period of the resulting oscillatory motion Is it a harmonic motion?
Appropriate data structure for representing numbers : 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 also
Theory of the leisure class by thorstein veblen : In The Theory of the Leisure Class by Thorstein Veblen. What does it tell about the period in which the writer composed it? What purpose does the document have regarding the nature of econmonics and the meaning of leisure, and how does the author def..
Write an essay about testing regulation : Write an essay about Testing Regulation. Covered employee: A person who operates (i.e., drives) a Commercial Motor Vehicle (CMV) with a gross vehicle weight rating (gvwr) of 26,001 or more pounds.
Medicine the legal rule is generally strict liability : What is meant by cause-in-fact? Explain how the logic of cause-in-fact does not always make economic sense.  Why is it that in manufacturing and medicine the legal rule is generally strict liability?
What resources capabilities and competencies does dubai have : What resources, capabilities, and competencies does Dubai have? What strengths, weaknesses, opportunities, and threats exist for Dubai? How is value created from Dubai's resources and capabilities

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Create an employee class

Create an Employee class

  Calculate the program average using the formula

Program average = total program points / maximum program points possible * 100. If no programs have been turned in at this point of the semester, set the program average to 0.0.

  The sport of gymnastics requires both impressive

The sport of gymnastics requires both impressive physical strength and extensive training for balance. The iron cross is an exercise performed on two suspended rings

  How much more secure is this double encryption

Now consider a double-encryption method that adds i to each plaintext character and then adds j to the resulting ciphertext character to get another ciphertext character. Again, all calculations are modulo 256.

  Solve the recurrence using the recursion trees method

Guess and prove by induction method - Solve the recurrence using the recursion trees method.

  Conducting an analysis and creating a business plan

When is inflation an important issue in conducting an analysis and creating a business plan? Why bother?

  Feature set of free helix forensics cd

Visit Helix web site and read about feature set of free Helix forensics CD. Note that documentation for Helix is not on CD, to keep it down to ~700MB.

  Explain daytime processing load

Assume daytime processing load consists of 60% CPU activityand 40% disk activity. Your customers are complaining that the system is slow. Which would you select to yield best performance improvement for least amount of money?

  Does the use of search engines threaten the privacy

Does the use of search engines threaten the privacy of ordinary people - Please keep it simple and short and no copy and paste.

  Determine the largest number of crates

The front wheels are free to roll. Assume that the engine of the loader is powerful enough to generate a torque that will cause the rear wheels to slip.

  Explain the key elements of computer ethics

Reflect on the technology minded "ten commandments" and the key elements of computer ethics you learned about in your module reading. Considering what you have learned and your own personal experiences, do the following Discussion Board activity

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd