3. Suppose you buy 100 shares of a stock at $12 per share, then another 100 at $10 per share, and then sell 150 shares at $15. You have to pay taxes on the gain, but exactly what is the gain? In the United States, the FIFO rule holds: You first sell all shares of the first batch for a profit of $300, then 50 of the shares from the second batch, for a profit of $250, yielding a total profit of $550. Write a program that can make these calculations for arbitrary purchases and sales of shares in a single company. The user enters commands buy quantity price, sell quantity price (which causes the gain to be displayed), and quit. Hint: Keep a queue of objects of a class Block that contains the quantity and price of a block of shares.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question
Data structure: Using Java,
3. Suppose you buy 100 shares of a stock at $12 per share, then another 100 at
$10 per share, and then sell 150 shares at $15. You have to pay taxes on the
gain, but exactly what is the gain? In the United States, the FIFO rule holds:
You first sell all shares of the first batch for a profit of $300, then 50 of the
shares from the second batch, for a profit of $250, yielding a total profit of
$550. Write a program that can make these calculations for arbitrary
purchases and sales of shares in a single company. The user enters
commands buy quantity price, sell quantity price (which causes the gain
to be displayed), and quit. Hint: Keep a
queue of objects of a
class Block that contains the quantity and price of a block of shares.
Transcribed Image Text:3. Suppose you buy 100 shares of a stock at $12 per share, then another 100 at $10 per share, and then sell 150 shares at $15. You have to pay taxes on the gain, but exactly what is the gain? In the United States, the FIFO rule holds: You first sell all shares of the first batch for a profit of $300, then 50 of the shares from the second batch, for a profit of $250, yielding a total profit of $550. Write a program that can make these calculations for arbitrary purchases and sales of shares in a single company. The user enters commands buy quantity price, sell quantity price (which causes the gain to be displayed), and quit. Hint: Keep a queue of objects of a class Block that contains the quantity and price of a block of shares.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Public key encryption
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning