Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
6.5k views
in Computer by (79.3k points)
edited by

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

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 member 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 top most location of the register if any, else returns "$$"
void display( ) displays all the names in the register

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 .

1 Answer

+1 vote
by (76.4k points)
selected by
 
Best answer

class Register

{

String stud [ ];

int cap, top;

Register (int max)

{

cap = max;

top = – 1;

stud = new int [cap];

}

void push (String n)

{

if (top = = cap – 1)

System. out. println ("OVER FLOW");

else

{

top ++;

stud [top] = n;

}

}

String pop ( )

{

if (top = = – 1)

return ("$ $");

else

{

String w = stud [top];

top – – ;

return (w);

}

}

}

(b) Stack

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...