added assignment 31, 32

This commit is contained in:
K 2023-10-26 20:35:33 +05:30
parent 4d229935db
commit c56cdf2b5c
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F
3 changed files with 402 additions and 0 deletions

2
.gitignore vendored
View File

@ -194,3 +194,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# VIM swap file
*.swp

210
assignment-31.cpp Normal file
View File

@ -0,0 +1,210 @@
#include <iostream>
using namespace std;
#define SIZE 5
class Dequeue
{
int a[10], front, rear, count;
public:
Dequeue()
{
front = -1;
rear = -1;
count = 0;
}
void addBegin(int item)
{
int i;
if (front == -1)
{
front++;
rear++;
a[rear] = item;
count++;
}
else if (rear >= SIZE - 1)
{
cout << "\nInsertion is not possible,overflow!!!!";
}
else
{
for (i = count; i >= 0; i--)
{
a[i] = a[i - 1];
}
a[i] = item;
count++;
rear++;
}
}
void addEnd(int item)
{
if (front == -1)
{
front++;
rear++;
a[rear] = item;
count++;
}
else if (rear >= SIZE - 1)
{
cout << "\nInsertion is not possible,overflow!!!";
return;
}
else
{
a[++rear] = item;
}
}
void deleteFront()
{
if (front == -1)
{
cout << "Deletion is not possible:: Dequeue is empty";
return;
}
else
{
if (front == rear)
{
front = rear = -1;
return;
}
cout << "The deleted element is " << a[front];
front = front + 1;
}
}
void deleteEnd()
{
if (front == -1)
{
cout << "Deletion is not possible:Dequeue is empty";
return;
}
else
{
if (front == rear)
{
front = rear = -1;
}
cout << "The deleted element is " << a[rear];
rear = rear - 1;
}
}
void display()
{
for (int i = front; i <= rear; i++)
{
cout << a[i] << " ";
}
}
};
int main()
{
int c, item;
Dequeue d1;
do
{
cout << "\n\n****DEQUEUE OPERATION****\n";
cout << "\n1-Insert at beginning";
cout << "\n2-Insert at end";
cout << "\n3_Display";
cout << "\n4_Deletion from front";
cout << "\n5-Deletion from rear";
cout << "\n6_Exit";
cout << "\nEnter your choice<1-6>:";
cin >> c;
switch (c)
{
case 1:
cout << "Enter the element to be inserted:";
cin >> item;
d1.addBegin(item);
break;
case 2:
cout << "Enter the element to be inserted:";
cin >> item;
d1.addEnd(item);
break;
case 3:
d1.display();
break;
case 4:
d1.deleteFront();
break;
case 5:
d1.deleteEnd();
break;
case 6:
exit(1);
break;
default:
cout << "Invalid choice";
break;
}
} while (c != 7);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~ Output ~~~~~~~~~~~~~~~~~~~~~~~~~
****DEQUEUE OPERATION****
1-Insert at beginning
2-Insert at end
3_Display
4_Deletion from front
5-Deletion from rear
6_Exit
Enter your choice<1-6>:1
Enter the element to be inserted:10
****DEQUEUE OPERATION****
1-Insert at beginning
2-Insert at end
3_Display
4_Deletion from front
5-Deletion from rear
6_Exit
Enter your choice<1-6>:2
Enter the element to be inserted:50
****DEQUEUE OPERATION****
1-Insert at beginning
2-Insert at end
3_Display
4_Deletion from front
5-Deletion from rear
6_Exit
Enter your choice<1-6>:4
The deleted element is 10
****DEQUEUE OPERATION****
1-Insert at beginning
2-Insert at end
3_Display
4_Deletion from front
5-Deletion from rear
6_Exit
Enter your choice<1-6>:6
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

190
assignment-32.cpp Normal file
View File

@ -0,0 +1,190 @@
#include <iostream>
using namespace std;
#define size 5
class pizza
{
int porder[size];
int front, rear;
public:
pizza()
{
front = rear = -1;
}
int qfull()
{
if (front == (rear + 1) % size)
return 1;
else
return 0;
}
int qempty()
{
if (front == -1)
return 1;
else
return 0;
}
void accept_order(int item)
{
if (qfull())
cout << "\nVery Sorry !!!! No more orders....\n";
else
{
if (front == -1)
{
front = rear = 0;
}
else
{
rear = (rear + 1) % size;
}
porder[rear] = item;
}
}
void make_payment(int n)
{
int item;
char ans;
if (qempty())
cout << "\nSorry !!! order is not there...\n";
else
{
cout << "\nDeliverd orders as follows...\n";
for (int i = 0; i < n; i++)
{
item = porder[front];
if (front == rear)
{
front = rear = -1;
}
else
{
front = (front + 1) % size;
}
cout << "\t" << item;
}
cout << "\nTotal amount to pay : " << n * 100;
cout << "\nThank you visit Again....\n";
}
}
void order_in_queue()
{
int temp;
if (qempty())
{
cout << "\nSorry !! There is no pending order...\n";
}
else
{
temp = front;
cout << "\nPending Order as follows..\n";
while (temp != rear)
{
cout << "\t" << porder[temp];
temp = (temp + 1) % size;
}
cout << "\t" << porder[temp];
}
}
};
int main()
{
pizza p1;
int ch, k, n;
do
{
cout << "\n\t***** Welcome To Pizza Parlor *******\n";
cout << "\n1.Accept order\n2.Make_payment\n3.Pending Orders\nEnter u r choice:";
cin >> ch;
switch (ch)
{
case 1:
cout << "\nWhich Pizza would do u like to have today\n";
cout << "\n1.Veg Soya Pizza\n2.Veg butter Pizza\n3.Egg_Pizza";
cout << "\nPlease enter your order: ";
cin >> k;
p1.accept_order(k);
break;
case 2:
cout << "\nHow many Pizza ?";
cin >> n;
p1.make_payment(n);
break;
case 3:
cout << "\n Following orders are in queue to deliver....as follows..\n";
p1.order_in_queue();
break;
}
} while (ch != 4);
return 0;
}
/* ~~~~~~~~~~~~~~~~~~~~~~~ Output ~~~~~~~~~~~~~~~~~~~~~~~
***** Welcome To Pizza Parlor *******
1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice:1
Which Pizza would do u like to have today
1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter your order: 1
***** Welcome To Pizza Parlor *******
1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice:2
How many Pizza ?10
Deliverd orders as follows...
1 2 2 2 2 2 2 2 2 2
Total amount to pay : 1000
Thank you visit Again....
***** Welcome To Pizza Parlor *******
1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice:3
Following orders are in queue to deliver....as follows..
Sorry !! There is no pending order...
***** Welcome To Pizza Parlor *******
1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice:1
Which Pizza would do u like to have today
1.Veg Soya Pizza
2.Veg butter Pizza
3.Egg_Pizza
Please enter your order: 3
***** Welcome To Pizza Parlor *******
1.Accept order
2.Make_payment
3.Pending Orders
Enter u r choice:
4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */