0% found this document useful (0 votes)
2 views

FDS_CODES

The document contains four separate Python programs. Program 1 calculates statistics based on student marks, Program 2 performs operations on square matrices, Program 3 manages student participation in sports, and Program 4 sorts student scores and displays the top five. Each program includes user input and various functionalities, with outputs demonstrating their operations.

Uploaded by

amkslade101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

FDS_CODES

The document contains four separate Python programs. Program 1 calculates statistics based on student marks, Program 2 performs operations on square matrices, Program 3 manages student participation in sports, and Program 4 sorts student scores and displays the top five. Each program includes user input and various functionalities, with outputs demonstrating their operations.

Uploaded by

amkslade101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

Program 1

--------------------------------------------------
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

print("\nThe marks with highest frequency of ",marks,"= ",cnt)


while(True):
print("\n Choose what you want to perform: \n1 = average score of class\n2
= Highest score and Lowest score of class\n3 = Count of students who were
absent for the test\n4 = Display marks with highest frequency \n5=Exit")
ch=int(input("\n Enter choice= "))
if(ch==1):
av(l)
elif(ch==2):
maxmin(l)
elif(ch==3):
abse(l)
elif(ch==4):
freq(l)
elif ch==5:
break
else:
print("Invalid Choice")

------------------------------------------------------------------
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

Choose what you want to perform:


1 = average score of class
2 = Highest score and Lowest score of class
3 = Count of students who were absent for the test
4 = Display marks with highest frequency
5 = Exit

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()

m=int(input("enter no of rows and columns of square matrix1="))


l1=[]
for i in range(m):
list1=[]
for j in range(m):
list1.append(int(input("enter element=")))
l1.append(list1)

disp(l1,m)

n=int(input("enter no of rows and columns of square matrix2="))


l2=[]
for i in range(n):
list2=[]
for j in range(n):
list2.append(int(input("enter element=")))
l2.append(list2)

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

enter no of rows and columns of square matrix2=3


enter element=11
enter element=72
enter element=3
enter element=6
enter element=21
enter element=8
enter element=1
enter element=0
enter element=12

matrix:
11 72 3
6 21 8
1 0 12

Choose what you want to perform :


1 = Addition of two matrices
2 = Subtraction of two matrices
3 = multiplication of two matrices
4 = Transpose of matrix
5 = Exit

Enter choice= 1
addition of matrix1 and matrix2:

23 85 4
10 34 20
19 3 17

Enter choice= 2

subtraction of matrix1 and matrix2:

1 -59 -2
-2 -8 4
17 3 -7

Enter choice= 3

multiplication of matrix1 and matrix2:

211 1137 152


134 561 260
221 1359 138

Enter choice= 4

Enter 1 for transpose of matrix 1


2 for transpose of matrix 2
3 for both

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 student name= a


enter student name= b
enter student name= c
enter student name= d

list of students= ['a', 'b', 'c', 'd']

a is playing cricket (y/n)= y


b is playing cricket (y/n)= n
c is playing cricket (y/n)= y
d is playing cricket (y/n)= n
list of students playing cricket= ['a', 'c']

a is playing badminton (y/n)= n


b is playing badminton (y/n)= n
c is playing badminton (y/n)= y
d is playing badminton (y/n)= y
list of students playing badminton= ['c', 'd']

a is playing football (y/n)= y


b is playing football (y/n)= y
c is playing football (y/n)= y
d is playing football (y/n)= y
list of students playing football= ['a', 'b', 'c', 'd']

Choose what you want to perform:


1 = List of students who play both cricket and badminton
2 = List of students who play either cricket or badminton but not both
3 = Number of students who play neither cricket nor badminton
4 = Number of students who play cricket and football but not badminton

enter choice=1

list of students playing both cricket and badminton= ['c']

Do you want to continue(1-yes/0-no)=1

Choose what you want to perform:


1 = List of students who play both cricket and badminton
2 = List of students who play either cricket or badminton but not both
3 = Number of students who play neither cricket nor badminton
4 = Number of students who play cricket and football but not badminton

enter choice=2

list of students playing either cricket or badminton but not both= ['a', 'd']

Do you want to continue(1-yes/0-no)=1

Choose what you want to perform:


1 = List of students who play both cricket and badminton
2 = List of students who play either cricket or badminton but not both
3 = Number of students who play neither cricket nor badminton
4 = Number of students who play cricket and football but not badminton

enter choice=3

number of students playing neither cricket nor badminton= 1

Do you want to continue(1-yes/0-no)=1

Choose what you want to perform:


1 = List of students who play both cricket and badminton
2 = List of students who play either cricket or badminton but not both
3 = Number of students who play neither cricket nor badminton
4 = Number of students who play cricket and football but not badminton

enter choice=4

number of students playing cricket and football but not badminton= 1

Do you want to continue(1-yes/0-no)=1

Choose what you want to perform:


1 = List of students who play both cricket and badminton
2 = List of students who play either cricket or badminton but not both
3 = Number of students who play neither cricket nor badminton
4 = Number of students who play cricket and football but not badminton

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)

n=int(input("Enter the no of students present in the class:"))


print("Enter the percentages:(in float point)")
Score_list=[]
for i in range(n):
data=float(input())
Score_list.append(data)
print("Unsorted percentages:",Score_list)
while(1):

print("\nChoose \n 1.Selection Sort \n 2.Bubble Sort \n 3.Display Top Five


Scores")
ch=input("Enter option:")

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

def binary_search(array, rollno):


low = 0
high = len(array) - 1

while low <= high:


mid = (low + high) // 2

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).")

def fibonacci_search(array, rollno):


f2 = 0
f1 = 1
f0 = f2 + f1

while f0 < len(array):


f2 = f1
f1 = f0
f0 = f2 + f1

offset = -1

for i in range(len(array)):
if f0 <= 1:
break

index = min(offset + f2, len(array) - 1)

if array[index] < rollno:


f0 = f1
f1 = f2
f2 = f0 - f1
offset = index
elif array[index] > rollno:
f0 = f2
f1 = f1 - f2
f2 = f0 - f1
else:
print(f"Roll number {rollno} attended the training program (Fibonacci
Search).")
return

if f1 and offset + 1 < len(array) and array[offset + 1] == rollno:


print(f"Roll number {rollno} attended the training program (Fibonacci
Search).")
else:
print(f"Roll number {rollno} did not attend the training program
(Fibonacci Search).")

n=int(input("enter no of students: "))


rollnos = []
for i in range(0,n,1):
val=int(input("enter roll no: "))
rollnos.append(val)
print("unsorted array: ",rollnos)

# Sorting
rollnos = selection_sort(rollnos)
print("Roll numbers of students who attended the training program in sorted
array:", rollnos)

sch = int(input("Enter roll number to search: "))

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)

n=int(input("Enter the no of students present in the class:"))


print("Enter the percentages:(in float point)")
Score_list=[]
for i in range(n):
data=float(input())
Score_list.append(data)
print("Unsorted percentages:",Score_list)
Quick_sort(Score_list,0,len(Score_list)-1)
print("Sorted percentages:",Score_list)
print("Top Five percentages:")
top_five(Score_list)
------------------------------------------------------------------

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

Enter seat number to be booked


60
Enter your ID number
id45
Seat 60 booked!

Do you want to perform any other operation : (y/n)


y

*********************************************
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!

Do you want to perform any other operation : (y/n)


y

*********************************************
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 insertAtTail(T val) {


Node<T>* new_node = new Node<T>(val);
if (head == nullptr) {
head = new_node;
return;
}

Node<T>* temp = head;


while (temp->next != nullptr) {
temp = temp->next;
}
temp->next = new_node;
}

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;
}

Node<T>* intersection(Node<T>* head1, Node<T>* head2) {


LinkedList<T> intersected;
Node<T>* ptr1 = head1;
Node<T>* ptr2 = head2;

while (ptr1 != nullptr) {


while (ptr2 != nullptr) {
if (ptr1->val == ptr2->val) {
intersected.insertAtTail(ptr1->val);
}
ptr2 = ptr2->next;
}
ptr2 = head2;
ptr1 = ptr1->next;
}
return intersected.head;
}

Node<T>* unionList(Node<T>* head1, Node<T>* head2) {


LinkedList<T> united;
Node<T>* ptr1 = head1;
Node<T>* ptr2 = head2;
int flag;

while (ptr1 != nullptr) {


united.insertAtTail(ptr1->val);
ptr1 = ptr1->next;
}

while (ptr2 != nullptr) {


flag = 0;
ptr1 = head1;
while (ptr1 != nullptr) {
if (ptr1->val == ptr2->val) {
flag = 1;
break;
}
ptr1 = ptr1->next;
}
if (flag == 0) {
united.insertAtTail(ptr2->val);
}
ptr2 = ptr2->next;
}
return united.head;
}

Node<T>* difference(Node<T>* head1, Node<T>* head2) {


LinkedList<T> diff;
Node<T>* ptr1 = head1;
Node<T>* ptr2 = head2;
int flag;

while (ptr1 != nullptr) {


flag = 0;
ptr2 = head2;
while (ptr2 != nullptr) {
if (ptr1->val == ptr2->val) {
flag = 1;
break;
}
ptr2 = ptr2->next;
}
if (flag == 0) {
diff.insertAtTail(ptr1->val);
}
ptr1 = ptr1->next;
}
return diff.head;
}
};

int main() {
int n, v, b;
string name;

LinkedList<string> total;
LinkedList<string> vanilla;
LinkedList<string> butterscotch;

cout << "Enter Total Number of Students: ";


cin >> n;
cout << "Enter Name of Students:\n";
for (int i = 0; i < n; i++) {
cin >> name;
total.insertAtTail(name);
}
cout << "Enter Number of Students liking Vanilla Ice-cream: ";
cin >> v;
cout << "Enter Name of Students liking Vanilla:\n";
for (int i = 0; i < v; i++) {
cin >> name;
vanilla.insertAtTail(name);
}

cout << "Enter Number of Students liking Butterscotch Ice-cream: ";


cin >> b;
cout << "Enter Name of Students liking Butterscotch:\n";
for (int i = 0; i < b; i++) {
cin >> name;
butterscotch.insertAtTail(name);
}

cout << "\nTotal Students: ";


total.display();
cout << "\nStudents Liking Vanilla: ";
vanilla.display();
cout << "\nStudents Liking Butterscotch: ";
butterscotch.display();

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

Students Liking Vanilla: d c e


Students Liking Butterscotch: e a c
1) Set of students who like both vanilla and butterscotch.
2) Set of students who like either vanilla or butterscotch but not both.
3) Number of students who like neither vanilla nor butterscotch.
4) Exit.
Choose Operation: 1
Students who like both Vanilla and Butterscotch: c e

1) Set of students who like both vanilla and butterscotch.


2) Set of students who like either vanilla or butterscotch but not both.
3) Number of students who like neither vanilla nor butterscotch.
4) Exit.
Choose Operation: 2
Students who like either Vanilla or Butterscotch but not both: d a

1) Set of students who like both vanilla and butterscotch.


2) Set of students who like either vanilla or butterscotch but not both.
3) Number of students who like neither vanilla nor butterscotch.
4) Exit.
Choose Operation: 3
Students who like neither Vanilla nor Butterscotch: b
Number of students: 1

1) Set of students who like both vanilla and butterscotch.


2) Set of students who like either vanilla or butterscotch but not both.
3) Number of students who like neither vanilla nor butterscotch.
4) Exit.
Choose Operation: 4
------------------------------------------------------------------
PROGRAM 9
------------------------------------------------------------------
#include<iostream>
using namespace std;

class Queue {
public:
const static int size = 10;
int front = -1;
int rear = -1;
string queue[size];

void enqueue(string job) {


if (rear == size - 1) {
cout << "Overflow!!! (Queue is Full)" << endl;
}
else {
if (front == -1) {
front = 0;
}
rear++;
queue[rear] = job;
cout << "Job \"" << job << "\" added to the queue." << endl;
}
}

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.

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: of
Job "of" added to the queue.

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: data
Job "data" added to the queue.

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: structure
Job "structure" added to the queue.

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: subject
Job "subject" added to the queue.

Enter the option number to perform the operations:


1. To Add Job
2. To Delete Job
3. To Display Queue
4. Exit
2
The Deleted Job: "fundamentals"

Enter the option number to perform the operations:


1. To Add Job
2. To Delete Job
3. To Display Queue
4. Exit
3
Jobs in the Queue: "of" "data" "structure" "subject"

Enter the option number to perform the operations:


1. To Add Job
2. To Delete Job
3. To Display Queue
4. Exit
2
The Deleted Job: "of"

Enter the option number to perform the operations:


1. To Add Job
2. To Delete Job
3. To Display Queue
4. Exit
3
Jobs in the Queue: "data" "structure" "subject"

Enter the option number to perform the operations:


1. To Add Job
2. To Delete Job
3. To Display Queue
4. Exit
4
Exiting program.

------------------------------------------------------------------
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;

cin >> choice;


switch(choice)
{
case 0:
break;
case 1:
int val;
cout<<"Pizza types:1.Margherita 2.Paneer 3.Cheese 4.Italian"<<endl;
cout<<"Pizza order for:"<<endl;
cin>>val;
if(val>4)
{
cout<<"Sorry this can't be ordered"<<endl;
}
else
{
cout<<"Your ordered pizza "<<val<<" Placed"<<endl;
q.Place_order(val);
}
break;
case 2:
q.display();
break;
case 3:
q.delivered_order();

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

template <class T>


class Data {
public:
T val;
int priority;

bool operator <= (int v) {


return v <= priority;
}
};

template <class T>


class prQueue {
int front = -1, rear = -1;
Data<T> queue[MAX];

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;
}

if (front == -1 && rear == -1) {


front = rear = 0;
queue[rear] = D;
return;
} else {
int i;
for (i = rear; i >= front; i--) {
if (priority <= queue[i].priority) {
queue[i + 1] = queue[i];
} else {
break;
}
}
queue[i + 1] = D;
rear++;
}
}

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;
}

} while (opt != 5);

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;

const int Max = 30;

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;
}

string InfixtoPostfix(Stack& s, const string& infix) {


string postfix;
for (int i = 0; i < infix.length(); i++) {
if ((infix[i] >= 'a' && infix[i] <= 'z') || (infix[i] >= 'A' && infix[i] <= 'Z'))
{
postfix += infix[i];
} else if (infix[i] == '(') {
s.Push(infix[i]);
} else if (infix[i] == ')') {
while (!s.Empty() && s.top1() != '(') {
postfix += s.top1();
s.Pop();
}
if (!s.Empty() && s.top1() == '(') {
s.Pop();
}
} else if (isOperator(infix[i])) {
while (!s.Empty() && precedence(infix[i]) <= precedence(s.top1())) {
postfix += s.top1();
s.Pop();
}
s.Push(infix[i]);
}
}

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
------------------------------------------------------------------

Enter infix expression: (A-B)*(C+D)


INFIX EXPRESSION: (A-B)*(C+D)
POSTFIX EXPRESSION: AB-CD+*

Enter infix expression: (A+B)/(C+D)-(D*E)


INFIX EXPRESSION: (A+B)/(C+D)-(D*E)
POSTFIX EXPRESSION: AB+CD+/DE*-

------------------------------------------------------------------
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;
}

void Stack :: display()


{
if(isEmpty()==1)
cout<<"\nStack is empty";
else
{
for(int i=0;i<=top;i++)
{
cout<<" "<<str[i];
}
}
}
void Stack::push(char ch)
{
if(!isFull())
{
top++;
str[top]=ch;
}
}

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)

Enter Expression: (A-B)*(C+D)#

Expression is Well Parenthesized.


DO you want to continue?{1/0)1

Enter # as a deliminator after expression(At the end)

Enter Expression: A*((A-B)*(C+D)#

Expression is not Well Parenthesized.


DO you want to continue?{1/0)0

------------------------------------------------------------------

You might also like