Assignment 1
Assignment 1
Problem:
Companies and people often buy and sell stocks. Often they buy the same stock
for different prices at different times. Say a person owns 1000 shares a certain stock
(such as Checkpoint), she may have bought the stock in amounts of 100 shares over 10
different times with 10 different prices.
We will analyze two different methods of accounting -- Fifo and Lifo accounting
used for determining the "cost" of a stock. This information is typically calculated when
a stock is sold to determine if a profit / loss was made. In our version of Fifo
accounting, the price of a commodity is averaged starting with the first purchase of that
item. Say we sell 250 shares of a stock, according to this method, the purchase price is
determined by averaging the prices on the first 250 shares bought. In our version of
Lifo accounting, the price of a commodity is averaged starting with the last purchase of
that item. Say we sell 250 shares of a stock, according to this method, the purchase price
is determined by averaging the prices on the last 250 shares bought.
In this assignment, you will be using a queue for storing data for Fifo accounting, and a
stack for Lifo accounting. You should use an array based implementation for your stack
based implementation and a linked list for implementing your queue.
Both your stack and queue should have records with the following fields:
You can assume that the first element of the structure is the security bought first, the
second was bought second, etc.
Your program should allow user able to enter information about various stocks, the
amount of shares, and the price. The user can then enter a query about a certain stock
and the cost according to the Lifo and Fifo accounting methods for a certain number of
shares.
Action requires:
• If 1 is pressed, the user needs to enter the stock symbol, and the number of
shares, and the price.
• If 2 is pressed, the user needs to enter the stock symbol being queried and the
number of shares in question.
Sample Data:
Press 1
Name of the stock : XYZ
No. of shares : 10
Price: 5 shares at 96
2 shares at 54
3 shares at 100
Press 1
Name of the stock : PQR
No. of shares : 20
Price: 2 shares at 59.4
10 shares at 98.1
5 shares at 89.0
3 shares at 78.3
Press 2
Name of the stock: XYZ
No. of shares you wish to sell: 6
The average price per share according to LIFO method is 84 ((100+100+100+54+54+96)/6)
The average price per share according to FIFO method is 89 ((96+96+96+96+96+54))/6
CSL303 - IOOM
Problem:
Suppose there is a circle. There are petrol pumps on that circle. Petrol pumps are
numbered 0 to N-1 (both inclusive). You have two pieces of information corresponding
to each of the petrol pump:
(1) the amount of petrol that particular petrol pumps will give, and
(2) the distance from that petrol pump to the next petrol pump.
Initially, you have a tank of infinite capacity carrying no petrol. You can start the
tour at any of the petrol pumps. Calculate the first point from where the truck will be
able to complete the circle. Consider that the truck will stop at each of the petrol pumps.
The truck will move one kilometer for each liter of the petrol.
Input Format
The first line will contain the value of N. The next lines will contain a pair of
integers each, i.e. the amount of petrol that petrol pumps will give and the distance
between that petrol pump and the next petrol pump.
Constraints:
1<=N<=105
Output Format
An integer which will be the smallest index of the petrol pump from which we
can start the tour.
Sample Input
3
15
10 3
34
Sample Output
Explanation