0% found this document useful (0 votes)
12 views2 pages

CS Paper2

The document outlines programming tasks requiring the definition of two Java classes: Stock and Purchase, where Purchase inherits from Stock to manage stock updates upon purchases. Additionally, it describes a class Array_to_Stack that implements a stack data structure to manage student marks in ascending order. Each class includes specific data members and methods for functionality, emphasizing the use of comments and clear logic in the code.
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)
12 views2 pages

CS Paper2

The document outlines programming tasks requiring the definition of two Java classes: Stock and Purchase, where Purchase inherits from Stock to manage stock updates upon purchases. Additionally, it describes a class Array_to_Stack that implements a stack data structure to manage student marks in ascending order. Each class includes specific data members and methods for functionality, emphasizing the use of comments and clear logic in the code.
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/ 2

SECTION – C

Answer any two questions.


Each program should be written in such a way that it clearly depicts the logic of the problem stepwise.
This can be achieved by using comments in the program and mnemonic names or pseudo codes for
algorithms. The programs must be written in Java and the algorithms must be written in general /
standard form, wherever required / specified.
(Flowcharts are not required.)
Question 11
A super class Stock has been defined to store the details of the stock of a retail store. Define [10]
a subclass Purchase to store the details of the items purchased with the new rate and updates
the stock. Some of the members of the classes are given below:
Class name : Stock
Data members/instance variables:
item : to store the name of the item
qty : to store the quantity of an item in stock
rate : to store the unit price of an item
amt : to store the net value of the item in stock
Member functions:
Stock (…) : parameterized constructor to assign values to the
data members
void display( ) : to display the stock details
Class name : Purchase
Data members/instance variables:
pqty : to store the purchased quantity
prate : to store the unit price of the purchased item
Member functions / methods
Purchase(…) : parameterized constructor to assign values to the
data members of both classes
void update ( ) : to update stock by adding the previous quantity by
the purchased quantity and replace the rate of the
item if there is a difference in the purchase rate.
Also update the current stock value as:
(quantity * unit price)
void display( ) to display the stock details before and after
updation
Specify the class Stock, giving details of the constructor() and void display( ). Using
concept of inheritance, specify the class Purchase, giving details of the constructor(),
void update( ) and void display( ).
The main function and algorithm need not be written.

162
}
void update()
{ qty += pqty;
if(prate!=rate)
rate=prate;
amt = qty * rate;
}
void display()
{ super.display();
update();
super.display();
}
}

Question 12

A stack is a linear data structure which enables the user to add and remove integers from [10]
one end only, using the concept of LIFO(Last In First Out). An array containing the marks
of 50 students in ascending order is to be pushed into the stack.

Define a class Array_to_Stack with the following details:


Class name : Array_to_Stack
Data members/instance variables:
m[ ] : to store the marks
st[ ] : to store the stack elements
cap : maximum capacity of the array and stack
top : to point the index of the topmost element of the
stack
Methods/Member functions:
Array_to_Stack (int n) : parameterized constructor to initialize cap = n
and top = -1
void input_marks( ) : to input the marks from user and store it in the
array m[ ] in ascending order and
simultaneously push the marks into the stack
st[ ] by invoking the function pushmarks( )
void pushmarks(int v) : to push the marks into the stack at top location
if possible, otherwise, display “not possible”
int popmarks( ) : to return marks from the stack if possible,
otherwise, return -999
void display( ) : To display the stack elements

164

You might also like