From 54c4f4308ea2e600f4b32062cc94fa542c9679e5 Mon Sep 17 00:00:00 2001 From: Kshitij Date: Fri, 29 Sep 2023 15:56:14 +0530 Subject: [PATCH] Moved assignment-29 file from main branch to testing branch --- assignment-29 (Early access).cpp | 190 +++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 assignment-29 (Early access).cpp diff --git a/assignment-29 (Early access).cpp b/assignment-29 (Early access).cpp new file mode 100644 index 0000000..482a1e6 --- /dev/null +++ b/assignment-29 (Early access).cpp @@ -0,0 +1,190 @@ +#include +using namespace std; + +class queue +{ + int data[20]; + int f, r; + +public: + queue() + { + f = -1; + r = -1; + } + + int isempty() + { + if (f == -1) + { + return 1; + } + else + { + return 0; + } + } + + int isfull() + { + if (r >= 20) + { + return 1; + } + else + { + return 0; + } + } + + void enqueue(int x) + { + if (isfull() == 1) + { + cout << "job queue is full" << endl; + } + else + { + if (f == -1) + f++; + r++; + data[r] = x; + } + } + + void dequeue() + { + int x; + if (isempty()) + { + cout << "job queue is empty" << endl; + } + else + { + x = data[f]; + f++; + cout << x << "Job deleted " << endl; + } + } + + void disp() + { + cout << "job queue is as :" << endl; + for (int i = f; i <= r; i++) + { + cout << data[i] << " "; + } + cout << endl; + } +}; + +int main() +{ + int ch, n, x, d; + queue q; + cout << "Enter the no. of jobs in queue. " << endl; + cin >> n; + cout << "Enter jobs " << endl; + for (int i = 0; i < n; i++) + { + cin >> d; + q.enqueue(d); + } + do + { + cout << "**********MENU**********" << endl; + cout << "1)Add job " << endl; + cout << "2)Delete job " << endl; + cout << "3)Display" << endl; + cout << endl; + cout << "Enter your choice " << endl; + cin >> ch; + + switch (ch) + { + case 1: + cout << "Enter the job to be added " << endl; + cin >> d; + q.enqueue(d); + cout << "Job added" << endl; + q.disp(); + break; + + case 2: + q.dequeue(); + q.disp(); + break; + + case 3: + q.disp(); + break; + + default: + cout << "Invalid choice" << endl; + break; + } + cout << "Do you want to continue" << endl; + cout << "1. YES" << endl; + cout << "2. NO" << endl; + cin >> x; + + } while (x == 1); +} + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~ Output ~~~~~~~~~~~~~~~~~~~~~~~~~ + +Enter the no. of jobs in queue. +10 +Enter jobs +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +**********MENU********** +1)Add job +2)Delete job +3)Display + +Enter your choice +3 +job queue is as : +1 2 3 4 5 6 7 8 9 10 +Do you want to continue +1. YES +2. NO +1 +**********MENU********** +1)Add job +2)Delete job +3)Display + +Enter your choice +11 +Invalid choice +Do you want to continue +1. YES +2. NO +1 +**********MENU********** +1)Add job +2)Delete job +3)Display + +Enter your choice +2 +1Job deleted +job queue is as : +2 3 4 5 6 7 8 9 10 +Do you want to continue +1. YES +2. NO +2 + + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */