Python,C,C++ and JAVA programs for CBSE, ISC, B.Tech and I.T Computer Science and MCA students

The Programming Project: ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 11

Friday, January 22, 2021

ISC COMPUTER SCIENCE THEORY PAPER JAVA PROGRAMS - 2019 Question 11

 Question 11

A linear data structure enables the user to add address from rear end and remove address

from front. Define a class Diary with the following details:

Class name                                                                 : Diary

Data members / instance variables:

Q[ ]                                                                              : array to store the addresses

Size                                                                             : stores the maximum capacity of the

array

start                                                                             : to point the index of the front end

end                                                                              : to point the index of the rear end

Member functions:

Diary (int max)                                                            : constructor to initialize the data

member size=max, start=0 and end=0

void pushadd(String n)                                               : to add address in the diary from the

rear end if possible, otherwise display

the message “ NO SPACE”

String popadd( )                                                          : removes and returns the address from

the front end of the diary if any, else

returns “?????

void show( )                                                                : displays all the addresses in the diary

 

(a) Specify the class Diary giving details of the functions void pushadd(String) and

String popadd( ). 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 : Answer QUEUE


In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. By convention, the end of the sequence at which elements are added is called the back, tail, or rear of the queue, and the end at which elements are removed is called the head or front of the queue, analogously to the words used when people line up to wait for goods or services.

The operation of adding an element to the rear of the queue is known as enqueue, and the operation of removing an element from the front is known as dequeue. Other operations may also be allowed, often including a peek or front operation that returns the value of the next element to be dequeued without dequeuing it.

import java.util.*;
public class ISC2019Q11 {
       public static void main(String[] args) {
       int max;
       int choice = -1;
       Scanner input = new Scanner(System.in);
       System.out.println("Enter the maximum strength of the diary:");
       max = input.nextInt();
       Diary obj = new Diary(max);
       System.out.println("Enter 0 to exit:");
       System.out.println("Enter 1 to add:");
       System.out.println("Enter 2 to remove:");
       System.out.println("Enter 3 to display:");
       do {
           System.out.println("Enter your choice:");
           choice = input.nextInt();
           switch(choice) {
           case 0:
               break;
           case 1:     
               String n;
               System.out.println("Enter the address to add:");
               n = input.next();
               obj.pushAdd(n);
               break;
           case 2:
               System.out.println(obj.popAdd());
               break;
           case 3:
               obj.show();
               break;
               
           }
                            
       }while(choice !=0);
       input.close();
       }
}
class Diary {
    public void show() {
        for(int i = start; i<end; i++)
            System.out.println("Address at "+(i+1)+" is: "+Q[i]);
    }
    public String popAdd() {
        String frontValue;
        if ( end == start)
            return ("QUEUE IS EMPTY");
        else { 
            frontValue = Q[start];
            for(int i = 0; i < end-1 ;i++)
                Q[i]=Q[i+1];
            end--;
            return (frontValue);
        }
    }
    public void pushAdd(String n) {
        if (end < size) {
            Q[end] = n;
            end++;
        }
        else
            System.out.println("NO SPACE:"); 
    }
    Diary (int max){
        this.size = max;
        this.start = 0;
        this.end = 0;
        Q = new String[this.size];
    }
    private String[] Q;
    private int size;
    private int start;
    private int end;
}

1 comment:

  1. Intermediate Question Paper 2022 in Telangana You may download Model Question Papers for all subjects for old and TSBIE Inter 1st / 2nd Exam 2022 from Telangana Board 12th Question Paper 2022. To begin with, TS 12th Question Paper 2022 the Telangana State Sr Inter Sample Question Papers for 2022 Exam Preparer Students Using Old Impotent Papers Obtain Below Pages. Plus 2 Quarterly Model Questions Papers for the TS Intermediate Board.

    ReplyDelete