Sri Sivasubramaniya Nadar College of Engineering Iii Sem Bme Academic Year: 2021-22

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Sri Sivasubramaniya Nadar College of Engineering

III SEM BME


Academic Year: 2021-22
Queue class with necessary exception handling
Date: 13-12-2021
Expt. No.: 22
Aim:
To write a C++ program to implement the queue class with necessary exception handling.
Algorithm:
1. Start program
2. Define a constant ‘Max_size’ to have the value 100. Then declare and define a class ‘queue’ which has
…3 int type variables [‘rear’, ‘front’, ‘insnum’], 1 int type array ‘Queue’ of ‘Max_size’ size. It also …
contains a default constructor which initiazlizes the values of both ‘rear’ and ‘front’ to zero. This class …
contains 4 void functions [‘enqueue()’, ‘dequeue()’, ‘displayqueue()’, ‘una()’]. ‘enqueue’() uses a try …
block to insert a number into the immediately available position and if it can’t, it uses a catch block to …
display that the queue has reached its maximum size. ‘dequeue()’ uses a try block to delete the oldest of
…the entered numbers from the queue and if it can’t, it uses a catch block to display that the queue has no
…members and hence won’t be able to dequeue a number. ‘displayqueue()’ displays the number of …
members in the queue and then lists them with the positions in which they are stored. ‘una()’ displays …
the number of used up positions in comparison to the maximum number of positions initially available …
and the number of positions currently available
3. Declare 2 int type variables [‘choice’, ‘exitpass’] of which ‘exitpass’ is initialized to 1. Then, declare a
…queue type object ‘q’. Then, using a while block as long as exitpass equals 1 do the following: Display
…the available queue operations and then get and store the user’s choice in ‘choice’. Then, using a switch
…case block, the appropriate function is run if the value of choice is between 1 and 4, else, the default …
statement is run and then the program is terminated by changing the value of ‘exitpass’ to zero and …
then, the while loop is also terminated
4. End program

Name of the Student: Abishek P.S.


Register Number: 203003003
Sri Sivasubramaniya Nadar College of Engineering
III SEM BME
Academic Year: 2021-22
Program:

Name of the Student: Abishek P.S.


Register Number: 203003003
Sri Sivasubramaniya Nadar College of Engineering
III SEM BME
Academic Year: 2021-22
Sample Input and Output:

Result:
The C++ program is successfully executed after compilation.

Name of the Student: Abishek P.S.


Register Number: 203003003

You might also like