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

  Information technology support company-s business processes

How can information Technology support a company's business processes and decision making and give it competitive advantage? Give examples to illustrate your answer.

  Write the code to compute s on the basis of these values

In physics, a common useful equation for finding the position s of a body in linear motion at a given time t, based on its initial position s0, initial velocity v0, and rate of acceleration a, is the following:

  Creating a hashing function

Suppose you are creating a hashing function to use for storing string data in hashtable. One Candidate hasing function would be to sum the ASCII or Unicode values for each character, and that result as the hashcode.

  Evaluate several main factors that business need to consider

Evaluate several main factors that business need to consider in information management. Describe in 1000 Words essay.

  How many inherited classes are defined in the code

1. Which function(s) is/are being overloaded on the code? (Check all that apply) *  void sort(int A[], int size)  bool testIfSorted(int A[], int size)  long getNumCmps()

  Social media usage differences around the world

Can you find the services that are most popular in Russia and Middle Eastern countries? Based on the information you find, what can you conclude about social media usage differences around the world?

  Privacy laws are in a near constant state of flux

1) Privacy laws are in a near constant state of flux. Conduct research to identify the current state of privacy law. Has any major legislation recently been proposed or approved? What are the implications for firms operating in effected industries? W..

  The current network diagram infrastructure

1. Determine which devices you will use for both the current network diagram infrastructure consisting of firewalls, routers, and workstations as well as the device you need to incorporate.

  You are given for input the student name

Draw a flowchart to illustrate the following problem. You are given for input the student name, number of credits, and cost per credit. You need to output the student name, number of credits and total tuition.

  Urban area of dibrugarh in assam

Aakanksha, Nikita and Parishma are the owners of a handicraft unit in the urban area of Dibrugarh in Assam, which is involved in the manufacturing and marketing of Sital Pati, traditional mats and Jappi (the traditional headgear).

  For combat orientated classes/professions

Each class should weight each attribute from most to least important. In Method IX, the most important attribute rolls 9d6 and keeps the highest 3. The second most important rolls 8d6, keeping the highest 3. This follows in this pattern of 7d6, th..

  Write px (x), the pmf of x

Write PX (x), the PMF of X. Be sure to write the value of PX (x) for all x from -∞ to ∞.

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