FDS_CODES
FDS_CODES
--------------------------------------------------
n=int(input("Number of students in class : "))
l=[]
for i in range(n):
l.append(int(input("Enter marks scored in FDS : ")))
def av(l):
cnt=0
add=0
for i in range(n):
if(l[i]>0):
add+=l[i]
cnt+=1
avg=add/cnt
print("\nThe average score of class= ",avg)
def maxmin(l):
mx=l[0]
mn=l[0]
for i in range(n):
if(l[i]>0):
if(l[i]>mx):
mx=l[i]
elif(l[i]<mn):
mn=l[i]
print("\nHighest score of class= ",mx)
print("\nLowest score of class= ",mn)
def abse(l):
cnt=0
for i in range(n):
if(l[i]==-1):
cnt+=1
print("\nCount of absent students= ",cnt)
def freq(l):
cnt=0
for i in l:
c=l.count(i)
if c>cnt:
cnt=c
marks=i
------------------------------------------------------------------
OUTPUT
Number of students in class : 5
Enter marks scored in FDS : 12
Enter marks scored in FDS : 12
Enter marks scored in FDS : 16
Enter marks scored in FDS : 19
Enter marks scored in FDS : -1
Enter choice= 1
The average score of class= 14.75
Enter choice= 2
Highest score of class= 19
Lowest score of class= 12
Enter choice= 3
Count of absent students= 1
Enter choice= 4
The marks with highest frequency of 12 = 2
Enter choice= 5
------------------------------------------------------------------
Program 2
--------------------------------------------------
def disp(l,m):
print("matrix:")
for i in range(m):
for j in range(m):
print(l[i][j],end=" ")
print()
disp(l1,m)
disp(l2,n)
def add(l1,l2):
if(m==n):
print("addition of matrix1 and matrix2:")
for i in range(m):
for j in range(m):
print(l1[i][j]+l2[i][j],end=" ")
print()
else:
print("matrices cannot be added")
def sub(l1,l2):
if(m==n):
print("subtraction of matrix1 and matrix2:")
for i in range(m):
for j in range(m):
print(l1[i][j]-l2[i][j],end=" ")
print()
else:
print("matrices cannot be subtracted")
def multi(l1,l2,m,n):
if(m==n):
l3=[]
for i in range(m):
list3=[]
for j in range(m):
s=0
for k in range(m):
s=s+(l1[i][k]*l2[k][j])
list3.append(s)
l3.append(list3)
print("multiplication of matrix1 and matrix2:")
disp(l3,m)
else:print("matrices cannot be multiplied")
def trans(l,m):
print("transpose of matrix:")
for i in range(m):
for j in range(m):
print(l[j][i],end=" ")
print()
while(True):
print("\nChoose what you want to perform : \n1 = Addition of two matrices
\n2 = Subtraction of two matrices \n3 = multiplication of two matrices \n4 =
Transpose of matrix \n5 = Exit")
ch=int(input("\nEnter choice= "))
if(ch==1):
add(l1,l2)
elif(ch==2):
sub(l1,l2)
elif(ch==3):
multi(l1,l2,m,n)
elif(ch==4):
print("\nEnter 1 for transpose of matrix 1 \n2 for transpose of matrix 2
\n3 for both")
c=int(input("\nEnter Choice ="))
if c==1:
trans(l1,m)
elif c==2:
trans(l2,n)
elif c==3:
trans(l1,m)
trans(l2,n)
else :
print("invlid input")
elif ch==5:
break
else:print("Invalid Choice")
------------------------------------------------------------------
OUTPUT
--------------------------------------------------
enter no of rows and columns of square matrix1=3
enter element=12
enter element=13
enter element=1
enter element=4
enter element=13
enter element=12
enter element=18
enter element=3
enter element=5
matrix:
12 13 1
4 13 12
18 3 5
matrix:
11 72 3
6 21 8
1 0 12
Enter choice= 1
addition of matrix1 and matrix2:
23 85 4
10 34 20
19 3 17
Enter choice= 2
1 -59 -2
-2 -8 4
17 3 -7
Enter choice= 3
Enter choice= 4
Enter Choice =3
transpose of matrix:
12 4 18
13 13 3
1 12 5
transpose of matrix:
11 6 1
72 21 0
3 8 12
Enter choice= 5
------------------------------------------------------------------
PROGRAM 3
------------------------------------------------------------------
l1=[]
n=int(input("enter no of students= "))
print()
for i in range(0,n,1):
name=input("enter student name= ")
l1.append(name)
print()
print("list of students= ",l1)
print()
c=[]
cs=[]
for i in range(0,n,1):
print(l1[i],end=" ")
res=input("is playing cricket (y/n)= ")
c.append(res)
if(res=="y"):
cs.append(l1[i])
print("list of students playing cricket= ",cs)
print()
b=[]
bs=[]
for i in range(0,n,1):
print(l1[i],end=" ")
res=input("is playing badminton (y/n)= ")
b.append(res)
if(res=="y"):
bs.append(l1[i])
print("list of students playing badminton= ",bs)
print()
f=[]
fs=[]
for i in range(0,n,1):
print(l1[i],end=" ")
res=input("is playing football (y/n)= ")
f.append(res)
if(res=="y"):
fs.append(l1[i])
print("list of students playing football= ",fs)
print()
def lcb(l1):
cb=[]
for i in range(0,n,1):
if(c[i]=="y" and b[i]=="y"):
cb.append(l1[i])
print("\nlist of students playing both cricket and badminton= ",cb)
print()
def lcb1(l1):
cb1=[]
for i in range(0,n,1):
if((c[i]=="y" or b[i]=="y") and not (c[i]=="y" and b[i]=="y")):
cb1.append(l1[i])
print("\nlist of students playing either cricket or badminton but not both=
",cb1)
print()
def ncb2(l1):
cb2=[]
for i in range(0,n,1):
if(c[i]=="n" and b[i]=="n"):
cb2.append(l1[i])
print("\nnumber of students playing neither cricket nor badminton=
",len(cb2))
print()
def ncf(l1):
cf=[]
for i in range(0,n,1):
if((c[i]=="y" and f[i]=="y") and not b[i]=="y"):
cf.append(l1[i])
print("\nnumber of students playing cricket and football but not badminton=
",len(cf))
print()
ch1=1
while(ch1==1):
print("\nChoose what you want to perform:\n1 = List of students who play
both cricket and badminton\n2 = List of students who play either cricket or
badminton but not both\n3 = Number of students who play neither cricket nor
badminton\n4 = Number of students who play cricket and football but not
badminton ")
ch=int(input("\nenter choice="))
if(ch==1):
lcb(l1)
elif(ch==2):
lcb1(l1)
elif(ch==3):
ncb2(l1)
elif(ch==4):
ncf(l1)
else:
print("Invalid Choice")
ch1=int(input("\nDo you want to continue(1-yes/0-no)="))
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
enter no of students= 4
enter choice=1
enter choice=2
list of students playing either cricket or badminton but not both= ['a', 'd']
enter choice=3
enter choice=4
enter choice=5
Invalid Choice
------------------------------------------------------------------
PROGRAM 4
------------------------------------------------------------------
def Selection_Sort(Score_list):
for i in range(len(Score_list)-1):
min_score=i
for j in range(i+1,len(Score_list)):
if Score_list[min_score]>Score_list[j]:
min_score=j
Score_list[i],Score_list[min_score]=Score_list[min_score],Score_list[i]
def Bubble_sort(Score_list):
for i in range(len(Score_list)):
for j in range(len(Score_list)-1):
if Score_list[j]>Score_list[j+1]:
Score_list[j],Score_list[j+1]=Score_list[j+1],Score_list[j]
def reverse_sort(Score_list):
for i in range(len(Score_list)):
min_score=i
for j in range(i+1,len(Score_list)):
Score_list[j]>min_score
min_score=j
Score_list[i],Score_list[min_score]=Score_list[min_score],Score_list[i]
def top_five(Score_list):
Selection_Sort(Score_list)
reverse_sort(Score_list)
temp=[]
for i in range(5):
temp=Score_list[i]
print(temp)
if ch=="1":
Selection_Sort(Score_list)
print("Sorted percentages:",Score_list)
elif ch=="2":
Bubble_sort(Score_list)
print("Sorted percentages:",Score_list)
elif ch=="3":
Selection_Sort(Score_list)
print("Sorted percentages:",Score_list)
print("Top Five percentages are:")
top_five(Score_list)
else:
exit(0)
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
Enter the no of students present in the class:7
Enter the percentages:(in float point) 50 30 70 20 60 10 40
Unsorted percentages: [50.0, 30.0, 70.0, 20.0, 60.0, 10.0, 40.0]
Choose
1.Selection Sort
2.Bubble Sort
3.Display Top Five Scores
Enter option:1
Sorted percentages: [10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0]
Choose
1.Selection Sort
2.Bubble Sort
3.Display Top Five Scores
Enter option:2
Sorted percentages: [10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0]
Choose
1.Selection Sort
2.Bubble Sort
3.Display Top Five Scores
Enter option:3
Sorted percentages: [10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0]
Top Five percentages are:
70.0 60.0 50.0 40.0 30.0
------------------------------------------------------------------
PROGRAM 5
------------------------------------------------------------------
def selection_sort(array):
n = len(array)
for i in range(n):
min_index = i
for j in range(i + 1, n):
if array[j] < array[min_index]:
min_index = j
array[i], array[min_index] = array[min_index], array[i]
return array
if array[mid] == rollno:
print(f"Roll number {rollno} attended the training program (Binary
Search).")
return
elif array[mid] < rollno:
low = mid + 1
else:
high = mid - 1
print(f"Roll number {rollno} did not attend the training program (Binary
Search).")
offset = -1
for i in range(len(array)):
if f0 <= 1:
break
# Sorting
rollnos = selection_sort(rollnos)
print("Roll numbers of students who attended the training program in sorted
array:", rollnos)
binary_search(rollnos, sch)
fibonacci_search(rollnos, sch)
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
enter no of students: 6
enter roll no: 50
enter roll no: 17
enter roll no: 33
enter roll no: 19
enter roll no: 41
enter roll no: 64
unsorted array: [50, 17, 33, 19, 41, 64]
Roll numbers of students who attended the training program in sorted array:
[17, 19, 33, 41, 50, 64]
Enter roll number to search: 50
Roll number 50 attended the training program (Binary Search).
Roll number 50 attended the training program (Fibonacci Search).
enter no of students: 6
enter roll no: 50
enter roll no: 17
enter roll no: 33
enter roll no: 19
enter roll no: 41
enter roll no: 64
unsorted array: [50, 17, 33, 19, 41, 64]
Roll numbers of students who attended the training program in sorted array:
[17, 19, 33, 41, 50, 64]
Enter roll number to search: 51
Roll number 51 did not attend the training program (Binary Search).
Roll number 51 did not attend the training program (Fibonacci Search).
PROGRAM 6
------------------------------------------------------------------
def Quick_sort(arr,left,right):
if left<right:
partition_pos=partition(arr,left,right)
Quick_sort(arr,left,partition_pos-1)
Quick_sort(arr,partition_pos+1,right)
def partition(arr,left,right):
i=left
j=right-1
pivot=arr[right]
while i<j:
while(i<right) and arr[i]<pivot:
i+=1
while(j>left) and arr[j]>=pivot:
j-=1
if i<j:
arr[i],arr[j]=arr[j],arr[i]
if arr[i]>pivot:
arr[i],arr[right]=arr[right],arr[i]
return i
def reverse_sort(Score_list):
for i in range(len(Score_list)):
min_score=i
for j in range(i+1,len(Score_list)):
Score_list[j]>min_score
min_score=j
Score_list[i],Score_list[min_score]=Score_list[min_score],Score_list[i]
def top_five(Score_list):
Quick_sort(Score_list,0,len(Score_list)-1)
reverse_sort(Score_list)
temp=[]
for i in range(5):
temp=Score_list[i]
print(temp)
OUTPUT
------------------------------------------------------------------
Enter the no of students present in the class:7
Enter the percentages:(in float point) 50 40 70 10 30 20 60
Unsorted percentages: [50.0, 40.0, 70.0, 10.0, 30.0, 20.0, 60.0]
Sorted percentages: [10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0]
Top Five percentages: 70.0 60.0 50.0 40.0 30.0
PROGRAM 7
------------------------------------------------------------------
#include <iostream>
#include<stdlib.h>
using namespace std;
class node
{
public:
node* next;
node* prev;
int seat;
string id;
int status;
};
class cinemax
{
public:
node* head,* tail ,* temp;
cinemax()
{
head=NULL;
}
void create_list();
void display();
void book();
void cancel();
};
void cinemax::create_list()
{
int i=1;
temp=new node;
temp->seat=1;
temp->status=0;
temp->id="null";
tail=head=temp;
for(int i=2;i<=70;i++)
{
node *p;
p= new node;
p->seat=i;
p->status=0;
p->id="null";
tail->next=p;
p->prev=tail;
tail=p;
tail->next=head;
head->prev=tail;
}
}
void cinemax::display()
{
int r=1;
node* temp;
temp=head;
int count=0;
cout<<"\n-------------------------------------------------------------\n";
cout<<" Screen this way \n";
cout<<"-------------------------------------------------------\n";
while(temp->next!=head)
{
if(temp->seat/10==0)
cout<<"S0"<<temp->seat<<" :";
else
cout<<"S"<<temp->seat<<" :";
if(temp->status==0)
cout<<"|___| ";
else
cout<<"|_B_| ";
count++;
if(count%7==0)
{
cout<<endl;
r++;
}
temp=temp->next;
}
cout<<"S"<<temp->seat<<" :";
if(temp->status==0)
cout<<"|___| ";
else
cout<<"|_B_| ";
}
void cinemax::book()
{
int x;
string y;
label:
cout<<"\n\n\nEnter seat number to be booked\n";
cin>>x;
cout<<"Enter your ID number\n";
cin>>y;
if(x<1||x>70)
{
cout<<"Enter correct seat number to book (1-70)\n";
goto label;
}
node *temp;
temp=new node;
temp=head;
while(temp->seat!=x)
{
temp=temp->next;
}
if(temp->status==1)
cout<<"Seat already booked!\n";
else
{
temp->status=1;
temp->id=y;
cout<<"Seat "<<x<<" booked!\n";
}
}
void cinemax::cancel()
{
int x;
string y;
label1:
cout<<"Enter seat number to cancel booking\n";
cin>>x;
cout<<"Enter you ID\n";
cin>>y;
if(x<1||x>70)
{
cout<<"Enter correct seat number to cancel (1-70)\n";
goto label1;
}
node *temp;
temp=new node;
temp=head;
while(temp->seat!=x)
{
temp=temp->next;
}
if(temp->status==0)
{
cout<<"Seat not booked yet!!\n";
}
else
{
if(temp->id==y)
{
temp->status=0;
cout<<"Seat Cancelled!\n";
}
else
cout<<"Wrong User ID !!! Seat cannot be cancelled!!!\n";
}
}
int main()
{
cinemax obj;
obj.create_list();
int ch;
char c='y';
while(c=='y')
{
cout<<"\n*********************************************\n";
cout<<" CINEMAX MOVIE THEATRE\n";
cout<<"*********************************************\n";
cout<<"\nEnter Choice\n1.Current SeatStatus\n2.Book Seat
\n3.CancelSeat\n";
cin>>ch;
switch(ch)
{
case 1:obj.display();
break;
case 2: obj.book();
break;
case 3: obj.cancel();
break;
default: cout<<"Wrong choice input\n";
}
cout<<"\nDo you want to perform any other operation : (y/n)\n";
cin>>c;
}
return 0;
}
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.CancelSeat
2
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.CancelSeat
1
------------------------------------------------------------------
Screen this way
------------------------------------------------------------------
S01 :|___| S02 :|___| S03 :|___| S04 :|___| S05 :|___| S06 :|___|
S07 :|___|
S08 :|___| S09 :|___| S10 :|___| S11 :|___| S12 :|___| S13 :|___|
S14 :|___|
S15 :|___| S16 :|___| S17 :|___| S18 :|___| S19 :|___| S20 :|___|
S21 :|___|
S22 :|___| S23 :|___| S24 :|___| S25 :|___| S26 :|___| S27 :|___|
S28 :|___|
S29 :|___| S30 :|___| S31 :|___| S32 :|___| S33 :|___| S34 :|___|
S35 :|___|
S36 :|___| S37 :|___| S38 :|___| S39 :|___| S40 :|___| S41 :|___|
S42 :|___|
S43 :|___| S44 :|___| S45 :|___| S46 :|___| S47 :|___| S48 :|___|
S49 :|___|
S50 :|___| S51 :|___| S52 :|___| S53 :|___| S54 :|___| S55 :|___|
S56 :|___|
S57 :|___| S58 :|___| S59 :|___| S60 :|_B_| S61 :|___| S62 :|___|
S63 :|___|
S64 :|___| S65 :|___| S66 :|___| S67 :|___| S68 :|___| S69 :|___|
S70 :|___|
Do you want to perform any other operation : (y/n)
y
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.CancelSeat
3
Enter seat number to cancel booking
60
Enter you ID
id45
Seat Cancelled!
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.CancelSeat
1
------------------------------------------------------------------
Screen this way
------------------------------------------------------------------
S01 :|___| S02 :|___| S03 :|___| S04 :|___| S05 :|___| S06 :|___|
S07 :|___|
S08 :|___| S09 :|___| S10 :|___| S11 :|___| S12 :|___| S13 :|___|
S14 :|___|
S15 :|___| S16 :|___| S17 :|___| S18 :|___| S19 :|___| S20 :|___|
S21 :|___|
S22 :|___| S23 :|___| S24 :|___| S25 :|___| S26 :|___| S27 :|___|
S28 :|___|
S29 :|___| S30 :|___| S31 :|___| S32 :|___| S33 :|___| S34 :|___|
S35 :|___|
S36 :|___| S37 :|___| S38 :|___| S39 :|___| S40 :|___| S41 :|___|
S42 :|___|
S43 :|___| S44 :|___| S45 :|___| S46 :|___| S47 :|___| S48 :|___|
S49 :|___|
S50 :|___| S51 :|___| S52 :|___| S53 :|___| S54 :|___| S55 :|___|
S56 :|___|
S57 :|___| S58 :|___| S59 :|___| S60 :|___| S61 :|___| S62 :|___|
S63 :|___|
S64 :|___| S65 :|___| S66 :|___| S67 :|___| S68 :|___| S69 :|___|
S70 :|___|
Do you want to perform any other operation : (y/n)
n
PROGRAM 8
------------------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;
template<class T>
class Node {
public:
T val;
Node* next;
Node(T data) {
val = data;
next = nullptr;
}
};
template<class T>
class LinkedList {
public:
Node<T>* head;
LinkedList() {
head = nullptr;
}
void display() {
Node<T>* temp = head;
while (temp != nullptr) {
cout << temp->val << " ";
temp = temp->next;
}
cout << "NULL" << endl;
}
int count() {
Node<T>* temp = head;
int c = 0;
while (temp != nullptr) {
c++;
temp = temp->next;
}
return c;
}
int main() {
int n, v, b;
string name;
LinkedList<string> total;
LinkedList<string> vanilla;
LinkedList<string> butterscotch;
int opt;
LinkedList<string> result;
do {
cout << "\n1) Set of students who like both vanilla and butterscotch.\n";
cout << "2) Set of students who like either vanilla or butterscotch but
not both.\n";
cout << "3) Number of students who like neither vanilla nor
butterscotch.\n";
cout << "4) Exit.\n";
cout << "Choose Operation: ";
cin >> opt;
switch (opt) {
case 1:
result.head = result.intersection(vanilla.head, butterscotch.head);
cout << "Students who like both Vanilla and Butterscotch: ";
result.display();
break;
case 2:
result.head = result.difference(result.unionList(vanilla.head,
butterscotch.head),
result.intersection(vanilla.head,
butterscotch.head));
cout << "Students who like either Vanilla or Butterscotch but not
both: ";
result.display();
break;
case 3:
result.head = result.difference(total.head,
result.unionList(vanilla.head,
butterscotch.head));
cout << "Students who like neither Vanilla nor Butterscotch: ";
result.display();
cout << "Number of students: " << result.count() << endl;
break;
case 4:
break;
default:
cout << "Invalid Option!" << endl;
}
} while (opt != 4);
return 0;
}
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
Enter Total Number of Students: 5
Enter Name of Students:
a
b
c
d
e
Enter Number of Students liking Vanilla Ice-cream: 3
Enter Name of Students liking Vanilla:
d
c
e
Enter Number of Students liking Butterscotch Ice-cream: 3
Enter Name of Students liking Butterscotch:
e
a
c
Total Students: a b c d e
class Queue {
public:
const static int size = 10;
int front = -1;
int rear = -1;
string queue[size];
void dequeue() {
if (front == -1 || front > rear) {
cout << "Underflow!!! (Queue is Empty)" << endl;
}
else {
cout << "The Deleted Job: \"" << queue[front] << "\"" << endl;
front++;
}
}
void display() {
if (front == -1 || front > rear) {
cout << "Queue is Empty!" << endl;
}
else {
cout << "Jobs in the Queue: ";
for (int i = front; i <= rear; i++) {
cout << "\"" << queue[i] << "\" ";
}
cout << endl;
}
}
};
int main() {
Queue jobQueue;
int choice;
string job;
do {
cout << "\nEnter the option number to perform the operations:" <<
endl;
cout << "1. To Add Job" << endl;
cout << "2. To Delete Job" << endl;
cout << "3. To Display Queue" << endl;
cout << "4. Exit" << endl;
cin >> choice;
switch (choice) {
case 1:
cout << "Enter Job Name to Add: ";
cin.ignore();
getline(cin, job);
jobQueue.enqueue(job);
break;
case 2:
jobQueue.dequeue();
break;
case 3:
jobQueue.display();
break;
case 4:
cout << "Exiting program." << endl;
break;
default:
cout << "Invalid option! Please enter a valid option." << endl;
}
} while (choice != 4);
return 0;
}
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
Enter the option number to perform the operations:
1. To Add Job
2. To Delete Job
3. To Display Queue
4. Exit
1
Enter Job Name to Add: fundamentals
Job "fundamentals" added to the queue.
------------------------------------------------------------------
PROGRAM 10
------------------------------------------------------------------
#include<iostream>
using namespace std;
class Queue{
public:
const static int size=5;
int rear=-1;
int front=-1;
int queue[size];
void Place_order(int x)
{
if(front==-1 and rear==-1)
{
front=rear=0;
queue[rear]=x;
}
else if(((rear+1)%size)==front)
{
cout<<"Sorry, You Can't order as the orders are reached to the
maximum."<<endl;
}
else
{
rear=(rear+1)%size;
queue[rear]=x;
}
}
void delivered_order()
{
if(front==-1 and rear==-1)
{
cout<<"All the Pizzas are Delivered"<<endl;
}
else if(front==rear)
{
front=rear=-1;
}
else
{
cout<<"Delivered Pizza:"<<queue[front];
front=(front+1)%size;
}
}
void display()
{
int i=front;
if(front==-1 and rear==-1)
{
cout<<"All the Pizzas are Delivered"<<endl;
}
else
{
while(i!=rear)
{
cout<<"The ordered Pizzas are:"<<queue[i]<<endl;
i=(i+1)%size;
}
cout<<"The ordered Pizzas are:"<<queue[rear];
}
}
};
int main()
{
Queue q;
int val,choice;
do{
cout << "\n\nWelcome To Pizza Parlor. Enter option number for Order.
Enter 0 to exit" << endl;
cout << "1.Place an Order" << endl;
cout << "2.Display Order" << endl;
cout << "3.Deliver Order" << endl;
break;
default:
cout<<"Plz enter valid no"<<endl;
}
}while(choice!=0);
return 0;
}
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
1
Pizza types:1.Margherita 2.Paneer 3.Cheese 4.Italian
Pizza order for:
3
Your ordered pizza 3 Placed
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
2
The ordered Pizzas are:3
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
1
Pizza types:1.Margherita 2.Paneer 3.Cheese 4.Italian
Pizza order for:
1
Your ordered pizza 1 Placed
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
2
The ordered Pizzas are:3
The ordered Pizzas are:1
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
3
Delivered Pizza:3
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
3
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
2
All the Pizzas are Delivered
Welcome To Pizza Parlor. Enter option number for Order. Enter 0 to exit
1.Place an Order
2.Display Order
3.Deliver Order
0
------------------------------------------------------------------
PROGRAM 11
------------------------------------------------------------------
#include <iostream>
using namespace std;
#define MAX 50
public:
void enqueue(T d, int priority) {
Data<T> D;
D.val = d;
D.priority = priority;
if (rear == MAX - 1) {
cout << "Queue Overflow" << endl;
return;
}
Data<T> dequeue() {
Data<T> gar;
if (front == -1) {
cout << "Queue Underflow" << endl;
return gar;
} else {
gar = queue[front];
if (front == rear) {
front = rear = -1;
} else {
front++;
}
return gar;
}
}
void peek() {
if (front == -1) {
cout << "Queue is Empty" << endl;
} else {
cout << "Front element is: " << queue[front].val
<< " with priority " << queue[front].priority << endl;
}
}
void display() {
if (front == -1) {
cout << "Queue is Empty" << endl;
} else {
cout << "Queue elements: " << endl;
for (int i = front; i <= rear; i++) {
cout << "Value: " << queue[i].val << " with Priority: " <<
queue[i].priority << endl;
}
}
}
};
int main() {
prQueue<char> p;
int opt, pr;
char val;
Data<char> G;
do {
cout << "\nMENU\n";
cout << "1) Enqueue\n";
cout << "2) Dequeue\n";
cout << "3) Display\n";
cout << "4) Peek\n";
cout << "5) Exit\n";
cout << "Enter your option: ";
cin >> opt;
switch (opt) {
case 1:
cout << "Enter Data Value: ";
cin >> val;
cout << "Enter its Priority: ";
cin >> pr;
p.enqueue(val, pr);
break;
case 2:
G = p.dequeue();
cout << "Dequeued: " << G.val << " with priority " << G.priority
<< endl;
break;
case 3:
p.display();
break;
case 4:
p.peek();
break;
case 5:
break;
default:
cout << "Invalid Option!" << endl;
}
return 0;
}
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 1
Enter Data Value: D
Enter its Priority: 2
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 1
Enter Data Value: F
Enter its Priority: 1
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 1
Enter Data Value: S
Enter its Priority: 3
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 3
Queue elements:
Value: F with Priority: 1
Value: D with Priority: 2
Value: S with Priority: 3
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 2
Dequeued: F with priority 1
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 4
Front element is: D with priority 2
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 3
Queue elements:
Value: D with Priority: 2
Value: S with Priority: 3
MENU
1) Enqueue
2) Dequeue
3) Display
4) Peek
5) Exit
Enter your option: 5
------------------------------------------------------------------
PROGRAM 12
------------------------------------------------------------------
#include<iostream>
#include<string>
using namespace std;
class Stack {
public:
int top;
char arr[Max];
Stack() {
top = -1;
}
bool Empty() {
return top == -1;
}
bool Full() {
return top == Max - 1;
}
void Push(char x) {
if (Full())
cout << "Stack overflow" << endl;
else {
top++;
arr[top] = x;
}
}
void Pop() {
if (Empty())
cout << "Stack underflow" << endl;
else {
arr[top] = 0; // Optional: Clear the popped value
top--;
}
}
char top1() {
if (!Empty())
return arr[top];
return '\0'; // Return a null character if the stack is empty
}
};
bool isOperator(char c) {
return c == '+' || c == '-' || c == '/' || c == '*';
}
int precedence(char c) {
if (c == '*' || c == '/')
return 2;
else if (c == '+' || c == '-')
return 1;
return -1;
}
while (!s.Empty()) {
postfix += s.top1();
s.Pop();
}
return postfix;
}
int main() {
string infix_exp, postfix_exp;
cout << "Enter infix expression: ";
getline(cin, infix_exp);
Stack st;
cout << "INFIX EXPRESSION: " << infix_exp << endl;
postfix_exp = InfixtoPostfix(st, infix_exp);
cout << "POSTFIX EXPRESSION: " << postfix_exp << endl;
return 0;
}
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
------------------------------------------------------------------
PROGRAM 13
------------------------------------------------------------------
#include<iostream>
using namespace std;
const int MAX=20;
class Stack
{
char str[MAX];
int top;
public:
Stack()
{
top=-1;
}
void push(char ch);
char pop();
// char getTop();
bool isEmpty();
bool isFull();
void display();
void checkParenthesis();
};
bool Stack::isEmpty()
{
if(top==-1)
return 1;
else return 0;
}
bool Stack::isFull()
{
if(top==MAX-1)
return 1;
else
return 0;
}
char Stack::pop()
{
if(!isEmpty())
{
char ch=str[top];
top--;
return ch;
}
else
{
return '\0';
}
}
void Stack::checkParenthesis()
{
cout<<"\nEnter # as a deliminator after expression(At the end)\n";
cout<<"\nEnter Expression: ";
cin.getline(str,MAX,'#');
char ch;
bool flag=0;
for(int i=0;str[i]!='\0';i++)
{
if(str[i]=='(' || str[i]=='[' || str[i]=='{')
push(str[i]);
if(str[i]==')'||str[i]==']'||str[i]=='}')
{
ch=pop();
if((str[i]==')'&& ch!='(') ||(str[i]==']'&&
ch!='[')||(str[i]=='}'&& ch!='{'))
{
cout<<"\nNot parenthesized At "<<i<<" = "<<str[i];
flag=1;
break;
}
}
}
if(isEmpty()==1 && flag==0)
cout<<"\nExpression is Well Parenthesized.";
else
cout<<"\nExpression is not Well Parenthesized.";
}
int main()
{
int choice;
do
{
Stack s;
s.checkParenthesis();
cout<<"\nDO you want to continue?{1/0)";
cin>>choice;
}while(choice!=0);
return 0;
}
------------------------------------------------------------------
OUTPUT
------------------------------------------------------------------
Enter # as a deliminator after expression(At the end)
------------------------------------------------------------------