Class 12

Register Stack Program ISC 2018

Register is an entity which can hold a maximum of 100 names. The register enables the user to add and remove names from the topmost end only.

Define a class Register with the following details:

Class name: Register
Data members/instance variables:
stud[]: array to store the names of the students.
cap: stores the maximum capacity of the array.
top: to point the index of the top end.
Member functions:
Register(int max): constructor to initialize the data members cap = max, top = -1 and create the string array.
void push(String n): to add names in the register at the top location if possible, otherwise display the message “OVERFLOW”.
String pop(): removes and returns the names from the topmost location of the register if any, else returns “$$”.
void display(): displays all the names in the register.

(a) Specify the class Register giving details of the functions void push(String) and String pop(). Assume that the other functions have been defined.
The main function and algorithm need not be written.

(b) Name the entity used in the above data structure arrangement.

class Register{
    public void push(String n){
        if(top + 1 < cap)
            stud[++top] = n;
    public String pop(){
        if(top == -1)
            return "$$";
            return stud[top--];

The above data structure arrangement is a Stack.

2 replies on “Register Stack Program ISC 2018”

Assuming that capacity of this stack is 5.
And if you push 3 elements:
Topmost element is “SAM”.
If you pop elements one by one:
When empty, it will return “$$”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.