PRASHNIKAप्रश्निका
‹ Back to the paper

Answer the questions on the class described below.

A class CustomerService is defined to resolve customer service requests in the order in which they…

Computer Science20265 marksCase based
A class CustomerService is defined to resolve customer service requests in the order in which they are received. The details of the members of the class are given below:
Class name:CustomerService
Data members/instance variables:
services[ ]:array to store customer service request
size:to store the maximum capacity of the array
first:to store the index of the first customer service request
last:to store the index of the last customer service request
Methods/Member functions:
CustomerService(int s):constructor to assign size = s, first = 0 and last = 0
void add(int reqst):to insert a request at index last, if space is available, otherwise display “Request cannot be accepted at the moment”
int del( ):to remove and return the request at index first, if any, else return -9999
(i)[4.0]
Specify the class CustomerService giving details of the functions void add(int) and int del( ). Assume that the other functions have been defined.
(ii)[1.0]
Name the entity described above and state its principle.

Answer

Answer (i)

AI
void add(int reqst)
{
    if (last == size)
        System.out.println("Request cannot be accepted at the moment");
    else
    {
        services[last] = reqst;
        last++;
    }
}

int del()
{
    if (first == last)
        return -9999;
    else
    {
        int val = services[first];
        first++;
        return val;
    }
}
(Tested (run for real) inside a complete class with size=3: adding a 4th request correctly printed "Request cannot be accepted at the moment", and the four del() calls correctly returned 101, 102, 103, then -9999.)

Answer (ii)

AI
Entity: Queue Principle: FIFO (First In First Out) — the request that is added (inserted) first is the first one to be removed and serviced.
Data structures

From ISC 2026 Improvement Computer Science Paper 1, question 9.