Assignment 28
Assignment 28
2024)
A class Repeat is which allows the user to add elements from one end (rear) and
remove elements from the other end (front) only. The following details of the
class Repeat are given below:
Data Members:
Member functions:
Repeat(int m): constructor to initialize the data members cap=m, f=0,r=0 and to
create the integer array.
void pushvalue(int v): to add integers from the rear index if possible else display
the message “overflow”.
int popvalue(): to remove and return element from the front, if array is empty
then return -9999.
o Data Members:
element).
int r: The rear index (keeps track of where to add an element).
2. Constructor (Repeat)
Ini alizes the queue with a specified capacity:
specified capacity m.
3. Method: pushvalue(int v)
Adds a value to the rear of the queue:
o Otherwise, stores the value v at the rear index r, then increments the
o Checks if the queue is empty (if f == r), and returns -9999 to indicate
o Checks if the queue is empty (if f == r), and prints "The list is empty."
if true.
o Otherwise, iterates over the queue from index f to r, prin ng each
the queue.
If the queue is empty (returns -9999), prints "The queue is
o Case 4: Exit:
Prints "Exi ng..." and breaks out of the loop to terminate the
program.
o Default Case:
Class Description
Repeat Represents a queue-like structure with
operations for adding, removing, and
displaying elements.
main Contains the main method to test the
functionality of the Repeat class.
OUTPUT: