0% found this document useful (0 votes)
378 views

Assignment 1

The document describes a lab assignment to write C code to analyze two stock accounting methods, FIFO and LIFO, using a queue and stack data structures respectively, by allowing the user to input stock purchase data and query the average price of shares sold based on the accounting method; it also describes a problem to calculate the starting point of a petrol pump circuit where pumps add varying amounts of petrol and distances between pumps may exceed the petrol added.

Uploaded by

G.J. ShivRaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
378 views

Assignment 1

The document describes a lab assignment to write C code to analyze two stock accounting methods, FIFO and LIFO, using a queue and stack data structures respectively, by allowing the user to input stock purchase data and query the average price of shares sold based on the accounting method; it also describes a problem to calculate the starting point of a petrol pump circuit where pumps add varying amounts of petrol and distances between pumps may exceed the petrol added.

Uploaded by

G.J. ShivRaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CSL303 - IOOM

Lab Assignment – 1 Batch 1& 2

Evaluation: Tuesday August 20, 2019 at 2.00 PM

Write C code for following problem.

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:

The name of the stock (a string or int)

The number of shares of a stock (an int)

The purchase price (real)

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.

The following could be your menu:

• Press 1 to enter a new stock


• Press 2 to find the Lifo and Fifo price for a stock.

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

Lab Assignment – 1 Batch 3 & 4

Evaluation: Wednesday August 21, 2019 at 2.00 PM

Write C code for following problem.

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

Amount of petrol >1, distance < 109

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

We can start the tour from the second petrol pump.

You might also like