Write a program that takes as input sequence of transactions

Assignment Help Computer Engineering
Reference no: EM131832901

Problem

When a share of common stock of some company is sold, the capital gain (or, sometimes, loss) is the difference between the share's selling price and the price originally paid to buy it. This rule is easy to understand for a single share, but if we sell multiple shares of stock bought over a long period of time, then we must identify the shares actually being sold. A standard accounting principle for identifying which shares of a stock were sold in such a case is to use a FIFO protocol-the shares sold are the ones that have been held the longest (indeed, this is the default method built into several personal finance software packages). For example, suppose we buy 100 shares at $20 each on day 1, 20 shares at $24 on day 2, 200 shares at $36 on day 3, and then sell 150 shares on day 4 at $30 each. Then applying the FIFO protocol means that of the 150 shares sold, 100 were bought on day 1, 20 were bought on day 2, and 30 were bought on day 3. The capital gain in this case would therefore be 100 · 10 + 20 · 6 + 30 · (-6), or $940. Write a program that takes as input a sequence of transactions of the form "buy x; share(s) at $y each" or "sell x share(s) at $y each," assuming that the transactions occur on consecutive days and the values x and y are integers. Given this input sequence, the output should be the total capital gain (or loss) for the entire sequence, using the FIFO protocol to identify.

Reference no: EM131832901

Questions Cloud

What is the probability that among the balls drawn : What is the probability that among the balls drawn there will be (i) 1 white and 2 black balls, (ii) at least 2 black balls, (iii) more black than white balls?
What happens when you supply the same name for the input : What happens when you supply the same name for the input and output files to the Total program? Try it out if you are not sure.
Construct a mathematical model for events a and b : If you had to construct a mathematical model for events A and B, as described below, would it be appropriate to assume that A and Bare independent?
Disability payments have on the unemployment rate : Between 1984 and 2001, the U.S. government made it much easier to get disability payments and the number of disabled people more than doubled from 3.8 million.
Write a program that takes as input sequence of transactions : Write a program that takes as input a sequence of transactions of the form buy x; share(s) at $y each or sell x share(s) at $y each, assuming.
What is the trade-off here : What's the trade-off here? If 100% of the people work to make new ideas (R = 1), won't that create a prosperous world?
What is the total effect of the lobbying on the wages : In equilibrium, taking into account your answers to parts a and b, what is the total effect of this lobbying on the wages of these professionals.
Show the conditional probability : Show that the conditional probability that any given trial will result in a success, given that there are k successes in the n trials, is equal to k/n.
Identify potential future events or conferences : NIT5150 - Advanced Object Oriented Programming Assignment. Your task is to investigate the operation of ACM and identify potential future events or conferences

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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