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

PR1 Output

ooop

Uploaded by

nileshlawande09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PR1 Output

ooop

Uploaded by

nileshlawande09
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 48

Name : Bhalerao Kunal Balu

Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 01
marks=[]
def stud_get():
print("Enter no of students in SE class")
N=int(input())
global marks
for i in range(N):
print("Enter the marks")
M=int(input())
marks.append(M)
print(marks)
def avg_marks():
sum=0
cnt=0
for i in range(len(marks)):
if marks[i] is not -1:
sum=sum+marks[i]
cnt+=1
print("total marks=",sum)
print("avg in float=",sum/cnt)
print("avg in integer=",sum//cnt)
def high_low():
temp=marks[0]
for i in range(len(marks)):
if temp < marks[i]:
temp=marks[i]
print("highest marks=",temp)
temp = marks[0]
for i in range(len(marks)):
if marks[i] is not -1:
if temp > marks[i]:
temp=marks[i]
print("lowest marks=",temp)
def count_abs():
cnt=0;
for i in range(len(marks)):
if marks[i] is -1:
cnt+=1
print("no of absent stu=",cnt)
def high_freq():
freq=[]
for i in range(len(marks)):
if marks[i] is not -1:
freq.append(marks.count(marks[i]))
print(freq)
k=max(freq)
print("highest frequency=",k)
print("lowest marks=",marks[k])
if __name__ == '__main__':
print("****************Take input******************************")
stud_get()
while(True):
print("1.the average score of class")
print("2.highest score and lowest score of class")
print("3.count of students who were absent for the test")
print("4.display marks with highest frequency")
print("enter choice")
choice=int(input())
if(choice==1):
avg_marks()
if(choice==2):
high_low()
if(choice==3):
count_abs()
if(choice==4):
high_freq()
if(choice==5):
exit()
***********************************OUTPUT********************************
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3 a2.py
Enter no of students in SE class
5
Enter the marks
96
Enter the marks
89
Enter the marks
56
Enter the marks
45
Enter the marks
78
[96, 89, 56, 45, 78]
1.the 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
enter choice
1
total marks= 364
avg in float= 72.8
avg in integer= 72
1.the 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
enter choice
2
highest marks= 96
lowest marks= 45
1.the 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
enter choice
3
no of absent stu= 0
1.the 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
enter choice
4
[1, 1, 1, 1, 1]
highest frequency= 1
lowest marks= 89
1.the 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
enter choice
5
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 02
sentence = input("Enter sentence: ")
longest = max(sentence.split(), key=len)
print("Longest word is: ", longest)
print("And its length is: ", len(longest))
# b) To determines the frequency of occurrence of particular character in the string
# using naive method to get count of each element in string
all_freq = {}
for i in sentence:
if i in all_freq:
all_freq[i] += 1
else:
all_freq[i] = 1
# printing result
print("Count of all characters in sentence is :\n "
+ str(all_freq))
# c) To check whether given string is palindrome or not
string=input(("Enter a word:"))
if(string==string[::-1]):
print("The letter is a palindrome")
else:
print("The letter is not a palindrome")
# d) To display index of first appearance of the substring
sub_str=input("Enter word" )
def check(sentence,sub_str):
if(sentence.find(sub_str)==-1):
print("substring is found")
else:
print("substring is not found")
check(sentence,sub_str)
# e) To count the occurrences of each word in a given string.
print("Following are the count the frequency of each word in a given string")
def freq(sentence):
# break the string into list of words
sentence = sentence.split()
str2 = []
# loop till string values present in list str
for i in sentence:
# checking for the duplicacy
if i not in str2:
# insert value in str2
str2.append(i)
for i in range(0, len(str2)):
# count the frequency of each word(present in str2) in sentence and print
print('count of frequency', str2[i], 'is :', sentence.count(str2[i]))
def main():
# call freq function
freq(sentence)
main() # call main function
*****************************************OUTPUT******************************************
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3 a5.py
Enter sentence: WELCOME TO ADSUL EDUCATIONAL CAMPUS
Longest word is: EDUCATIONAL
And its length is: 11
Count of all characters in sentence is :
{'W': 1, 'E': 3, 'L': 3, 'C': 3, 'O': 3, 'M': 2, ' ': 4, 'T': 2, 'A': 4, 'D': 2, 'S': 2, 'U': 3, 'I': 1, 'N': 1, 'P': 1}
Enter a word: ADSUL
The letter is not a palindrome
Enter word WELCOME
substring is found
Following are the count the frequency of each word in a given string
count of frequency WELCOME is : 1
count of frequency TO is : 1
count of frequency ADSUL is : 1
count of frequency EDUCATIONAL is : 1
count of frequency CAMPUS is : 1
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 03
m=int(input("Enter the number of rows:"))
n=int(input("Enter the number of columns:"))
a=[]
f=0
print("Enter the elements:")
for i in range(m):
t=[]
for j in range(n):
t.append(int(input()))
a.append(t)
print("The original matrix is:")
for i in range(m) :
for j in range(n):
print(a[i][j],end=" ")
print()
for i in range(n):
row_min=a[i][0]
ci=0
for j in range(1,n):
if row_min>a[i][j]:
row_min=a[i][j]
ci=j
k=0
while k<n:
if row_min<a[k][ci]:
break
k+=1
if k==n:
print("the saddle point is:",row_min)
f=1
if f==0:
print("Saddle point does not exist")
*****************************************OUTPUT******************************************
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3 a8.py
Enter the number of rows: 3
Enter the number of columns:3
Enter the elements:
1
2
3
4
5
6
7
8
9
The original matrix is:
123
456
789
the saddle point is: 7
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 04
def Selection_Sort(marks):
for i in range(len(marks)):
# Find the minimum element in remaining unsorted array
min_idx = i
for j in range(i + 1, len(marks)):
if marks[min_idx] > marks[j]:
min_idx = j
# Swap the minimum element with the first element
marks[i], marks[min_idx] = marks[min_idx], marks[i]
print("Marks of students after performing Selection Sort on the list : ")
for i in range(len(marks)):
print(marks[i])
#<--------------------------------------------------------------------------------------->
# Function for Bubble Sort of elements
def Bubble_Sort(marks):
n = len(marks);

# Traverse through all array elements


for i in range(n - 1):
# Last i elements are already in place
for j in range(0, n - i - 1):
# Traverse the array from 0 to n-i-1
# Swap if the element found is greater than the next element
if marks[j] > marks[j + 1]:
marks[j], marks[j + 1] = marks[j + 1], marks[j]
print("Marks of students after performing Bubble Sort on the list :")
for i in range(len(marks)):
print(marks[i])
#<--------------------------------------------------------------------------------------->
# Function for displaying top five marks
def top_five_marks(marks):
print("Top 5 Marks from",len(marks),"Marks are : ")
top_five_marks = [];
while len(top_five_marks) < 5:
max_marks = max(marks)
top_five_marks.append(max_marks)
marks.remove(max_marks)
print(top_five_marks)
#<---------------------------------------------------------------------------------------->
# Main
marks=[]
n = int(input("Enter number of students whose marks are to be displayed : "))
print("Enter marks for",n,"students (Press ENTER after every students marks): ")
for i in range(0, n):
ele = int(input())
marks.append(ele) # adding the element
print("The marks of",n,"students are : ")
print(marks)
flag=1;
while flag==1:
print("\n---------------MENU---------------")
print("1. Selection Sort of the marks")
print("2. Bubble Sort of the marks")
print("3. Exit")
ch=int(input("\n\nEnter your choice (from 1 to 3) : "))
if ch==1:
Selection_Sort(marks)
a=input("\nDo you want to display top marks from the list (yes/no) : ")
if a=='yes':
top_five_marks(marks)
else:
print("\nThanks for using this program!")
flag=0
elif ch==2:
Bubble_Sort(marks)
a = input("\nDo you want to display top five marks from the list (yes/no) : ")
if a == 'yes':
top_five_marks(marks)
else:
print("\nThanks for using this program!")
flag = 0
elif ch==3:
print("\nThanks for using this program!!")
flag=0
else:
print("\nEnter a valid choice!!")
print("\nThanks for using this program!!")
flag=0
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3 b14.py
Enter number of students whose marks are to be displayed : 5
Enter marks for 5 students (Press ENTER after every students marks):
89
75
84
96
51
The marks of 5 students are :
[89, 75, 84, 96, 51]
---------------MENU---------------
1. Selection Sort of the marks
2. Bubble Sort of the marks
3. Exit
Enter your choice (from 1 to 3) : 1
Marks of students after performing Selection Sort on the list :
51
75
84
89
96
Do you want to display top marks from the list (yes/no) : yes
Top 5 Marks from 5 Marks are :
[96, 89, 84, 75, 51]
---------------MENU---------------
1. Selection Sort of the marks
2. Bubble Sort of the marks
3. Exit
Enter your choice (from 1 to 3) : 2
Marks of students after performing Bubble Sort on the list :
Do you want to display top five marks from the list (yes/no) : no
Thanks for using this program!
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 05
#include<iostream>
using namespace std;
void in(float marks[20],int n)
{
int i,j;
float temp;
for(i=1;i<n;i++)
{
temp=marks[i];
for(j=i-1;j>=0&& marks[j]>temp;j--)
marks[j+1]=marks[j];
marks[j+1]=temp;
}
cout<<"\n Top five scores are:";
for(i=n-1;i>=0;i--)
cout<<"\t"<<marks[i];
}
void shell(float marks[20],int n)
{
int i,j,step;
float temp;
for(step=n/2;step>0;step=step/2)
for(i=step ;i<n;i++)
{
temp=marks[i];
for(j=i;j>=step;j=j-step)
if(temp<marks[j-step])
marks[j]=marks[j-step];
else
break;
marks[j]=temp;
}
cout<<"\n Top five scores are:";
for(i=n-1;i>=n-5;i--)
cout<<"\t"<<marks[i];
}
int main()
{
float marks[20];
int i,n,ch;
cout<<"\n Enter the total no.of students:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\n Ener the percentage marks of second year student"<<i+1<<"::";
cin>>marks[i];
}
while(ch!=3)
{
cout<<"\n1. Insertion sort \n 2. Shell sort 3.Exit";
cout<<"\n Enter your choice:";
cin>>ch;
switch(ch)
{
case 1:
in(marks,n);
break;
case 2:
shell(marks,n);
break;
default:
cout<<"Oops! Wrong choice. \nTerminating...\nTerminated!\n";
}
}
return 0;
}
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ b15.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out
Enter the total no.of students:6
Ener the percentage marks of second year student1::78
Ener the percentage marks of second year student2::98
Ener the percentage marks of second year student3::48
Ener the percentage marks of second year student4::75
Ener the percentage marks of second year student5::86
Ener the percentage marks of second year student6::56
1. Insertion sort
2. Shell sort 3.Exit
Enter your choice:1
Top five scores are: 98 86 78 75 56 48
1. Insertion sort
2. Shell sort 3.Exit
Enter your choice:2
Top five scores are: 98 86 78 75 56
1. Insertion sort
2. Shell sort 3.Exit
Enter your choice:6
Oops! Wrong choice.
Terminating...
Terminated!
1. Insertion sort
2. Shell sort 3.Exit
Enter your choice:3
Oops! Wrong choice.
Terminating...
Terminated!
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 06
def input_percentage():
perc = []
number_of_students = int(input("Enter the number of Students : "))
for i in range(number_of_students):
perc.append(float(input("Enter the percentage of Student {0} : ".format(i+1))))
return perc
# Function for printing the percentage of the Students
def print_percentage(perc):
for i in range(len(perc)):
print(perc[i],sep = "\n")
# Function for performing partition of the Data
def percentage_partition(perc,start,end):
pivot = perc[start]
lower_bound = start + 1
upper_bound = end
while True:
while lower_bound <= upper_bound and perc[lower_bound] <= pivot:
lower_bound += 1
while lower_bound <= upper_bound and perc[upper_bound] >= pivot:
upper_bound -= 1
if lower_bound <= upper_bound:
perc[lower_bound],perc[upper_bound] = perc[upper_bound],perc[lower_bound]
else:
break
perc[start],perc[upper_bound] = perc[upper_bound],perc[start]
return upper_bound
# Function for performing Quick Sort on the Data
def Quick_Sort(perc,start,end):
while start < end:
partition = percentage_partition(perc,start,end)
Quick_Sort(perc,start,partition-1)
Quick_Sort(perc,partition+1,end)
return perc
# Function for Displaying Top Five Percentages of Students
def display_top_five(perc):
print("Top Five Percentages are : ")
if len(perc) < 5:
start, stop = len(perc) - 1, -1
else:
start, stop = len(perc) - 1, len(perc) - 6
for i in range(start, stop, -1):
print(perc[i],sep = "\n")
# Main
unsorted_percentage = []
sorted_percentage = []
flag = 1
while flag == 1:
print("\n--------------------MENU--------------------")
print("1. Accept the Percentage of Students")
print("2. Display the Percentages of Students")
print("3. Perform Quick Sort on the Data")
print("4. Exit")
ch = int(input("Enter your choice (from 1 to 4) : "))
if ch == 1:
unsorted_percentage = input_percentage()
elif ch == 2:
print_percentage(unsorted_percentage)
elif ch == 3:
print("Percentages of Students after performing Quick Sort : ")
sorted_percentage = Quick_Sort(unsorted_percentage,0,len(unsorted_percentage)-1)
print_percentage(sorted_percentage)
a = input("Do you want to display the Top 5 Percentages of Students (yes/no) : ")
if a == 'yes':
display_top_five(sorted_percentage)
elif ch == 4:
print("Thanks for using this program!!")
flag = 0
else:
print("Invalid Choice!!")
*****************************************OUTPUT***********************************
*******

root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3 b16.py


--------------------MENU--------------------
1. Accept the Percentage of Students
2. Display the Percentages of Students
3. Perform Quick Sort on the Data
4. Exit
Enter your choice (from 1 to 4) : 1
Enter the number of Students : 5
Enter the percentage of Student 1 : 96
Enter the percentage of Student 2 : 86
Enter the percentage of Student 3 : 76
Enter the percentage of Student 4 : 43
Enter the percentage of Student 5 : 85
--------------------MENU--------------------
1. Accept the Percentage of Students
2. Display the Percentages of Students
3. Perform Quick Sort on the Data
4. Exit
Enter your choice (from 1 to 4) : 2
96.0
86.0
76.0
43.0
85.0
--------------------MENU--------------------
1. Accept the Percentage of Students
2. Display the Percentages of Students
3. Perform Quick Sort on the Data
4. Exit
Enter your choice (from 1 to 4) : 3
Percentages of Students after performing Quick Sort :
43.0
76.0
85.0
86.0
96.0
Do you want to display the Top 5 Percentages of Students (yes/no) : NO
--------------------MENU--------------------
1. Accept the Percentage of Students
2. Display the Percentages of Students
3. Perform Quick Sort on the Data
4. Exit
Enter your choice (from 1 to 4) : 4
Thanks for using this program!!
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 07
#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 avail();
};
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";
}
}
void cinemax::avail()
{
int r=1;
node* temp;
temp=head;
int count=0;
cout<<"\n\n\n\n";
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 if(temp->status==1)
cout<<" ";
count++;
if(count%7==0)
{
cout<<endl;
}
}
temp=temp->next;
}
if(temp->status==0)
{
cout<<"S"<<temp->seat<<" :";
if(temp->status==0)
cout<<"|___| ";
}
}
int main()
{ cinemax obj;
obj.create_list();
int ch;
char c='y';
while(c=='y')
{ obj.display();
cout<<"\n*********************************************\n";
cout<<" CINEMAX MOVIE THEATRE\n";
cout<<"*********************************************\n";
cout<<"\nEnter Choice\n1.Current SeatStatus\n2.Book Seat \n3.Available Seat\n4.CancelSeat\n";
cin>>ch;
switch(ch)
{
case 1:obj.display();
break;
case 2: obj.book();
break;
case 3:obj.avail();
break;
case 4: 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***********************************
*******
root123@root123-HP-ProDesk-600-G3-SFF:~$ su
Password:
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ c20.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out
------------------------------------------------------------------------------------
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 :|___|
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.Available Seat
4.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)
y
------------------------------------------------------------------------------------
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 :|___|
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.Available Seat
4.CancelSeat
2
Enter seat number to be booked
8
Enter your ID number
8
Seat 8 booked!
Do you want to perform any other operation : (y/n)
y
------------------------------------------------------------------------------------
Screen this way
------------------------------------------------------------------------------------
S01 :|___| S02 :|___| S03 :|___| S04 :|___| S05 :|___| S06 :|___| S07 :|___|
S08 :|_B_| 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 :|___|
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.Available Seat
4.CancelSeat
2
Enter seat number to be booked
58
Enter your ID number
58
Seat 58 booked!
Do you want to perform any other operation : (y/n)
y
------------------------------------------------------------------------------------
Screen this way
------------------------------------------------------------------------------------
S01 :|___| S02 :|___| S03 :|___| S04 :|___| S05 :|___| S06 :|___| S07 :|___|
S08 :|_B_| 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 :|_B_| S59 :|___| S60 :|___| S61 :|___| S62 :|___| S63 :|___|
S64 :|___| S65 :|___| S66 :|___| S67 :|___| S68 :|___| S69 :|___| S70 :|___|
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.Available Seat
4.CancelSeat

2
Enter seat number to be booked
9
Enter your ID number
9
Seat 9 booked!
Do you want to perform any other operation : (y/n)
y
------------------------------------------------------------------------------------
Screen this way
------------------------------------------------------------------------------------
S01 :|___| S02 :|___| S03 :|___| S04 :|___| S05 :|___| S06 :|___| S07 :|___|
S08 :|_B_| S09 :|_B_| 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 :|_B_| S59 :|___| S60 :|___| S61 :|___| S62 :|___| S63 :|___|
S64 :|___| S65 :|___| S66 :|___| S67 :|___| S68 :|___| S69 :|___| S70 :|___|
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.Available Seat
4.CancelSeat
3
------------------------------------------------------------------------------------
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)
y
------------------------------------------------------------------------------------
Screen this way
------------------------------------------------------------------------------------
S01 :|___| S02 :|___| S03 :|___| S04 :|___| S05 :|___| S06 :|___| S07 :|___|
S08 :|_B_| S09 :|_B_| 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 :|_B_| S59 :|___| S60 :|___| S61 :|___| S62 :|___| S63 :|___|
S64 :|___| S65 :|___| S66 :|___| S67 :|___| S68 :|___| S69 :|___| S70 :|___|
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.Available Seat
4.CancelSeat
4
Enter seat number to cancel booking
58
Enter you ID
58
Seat Cancelled!
Do you want to perform any other operation : (y/n)
y
------------------------------------------------------------------------------------
Screen this way
------------------------------------------------------------------------------------
S01 :|___| S02 :|___| S03 :|___| S04 :|___| S05 :|___| S06 :|___| S07 :|___|
S08 :|_B_| S09 :|_B_| 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 :|___|
*********************************************
CINEMAX MOVIE THEATRE
*********************************************
Enter Choice
1.Current SeatStatus
2.Book Seat
3.Available Seat
4.CancelSeat
5
Wrong choice input
Do you want to perform any other operation : (y/n)
n
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 08
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}node;
node *createnode()
{
int n,i;
node *p,*head,*t;
head=NULL;
printf("enter the no of students");
scanf("%d",&n);
for(i=0;i<n;i++)
{
p=(node*)malloc(sizeof(node));
printf("enter the students ");
scanf("%d",&(p->data));
p->next=NULL;
if(head==NULL)
head=p;
else
{
t=head;
while(t->next!=NULL)
t=t->next;
t->next=p;
}
}
return head;
}
void print(node *head)
{
node *p;
int cnt=0;
p=head;
while(p!=NULL)
{
printf("\t %d",p->data);
p=p->next;
}cnt++;
printf("total no of students=%d",cnt);
}
int uni(node *head,node *head1)
{
node *p,*q;
int found=0,count=0;
p=head;
while(p!=NULL)
{
printf("\t %d",p->data);
p=p->next;
};
for(q=head1;q!=NULL;q=q->next)
{
found=0;
for(p=head;p!=NULL;p=p->next)
{
if(q->data==p->data)
{
found=1;
break;
}
}
if(found!=1)
{
printf("\t %d",q->data);
}
count++;
}
return count;
}
void inter(node *head1,node *head2)
{
node *p,*q;
int found=0;
for(q=head2;q!=NULL;q=q->next)
{
found=0;
for(p=head1;p!=NULL;p=p->next)
{
if(q->data==p->data)
{
found=1;
break;
}
}
if(found==1)
{
printf("\t %d",q->data);
}
}
}
void sub1(node *head1,node *head2)
{
node *p,*q;
int found=0;
for(p=head1;p!=NULL;p=p->next)
{
found=0;
for(q=head2;q!=NULL;q=q->next)
{
if(p->data==q->data)
{
found=1;
break;
}
}
if(found!=1)
{
printf("\t %d",p->data);
}
}
}
void sub2(node *head1,node *head2)
{
node *p,*q;
int found=0;
for(q=head2;q!=NULL;q=q->next)
{
found=0;
for(p=head1;p!=NULL;p=p->next)
{
if(p->data==q->data)
{
found=1;
break;
}
}
if(found!=1)
{
printf("\t %d",q->data);
}
}
}
int main()
{
node *head,*head1;
int ch=0,m,count;
head=head1=NULL;
printf("\n enter the no of students");
scanf("%d",&m);
head=NULL;
while(ch!=8)
{
printf("\n *************sets using singly linked list*************************");
printf("\n 1]create");
printf("\n 2]print");
printf("\n 3]students like either vanilla or butterscotch");
printf("\n 4]students like both vanilla & butterscotch");
printf("\n 5]students like vanilla only");
printf("\n 6]students like only butterscotch");
printf("\n 7]students like neither vanilla nor butterscotch");
printf("\n enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n students like vanilla" );
head=createnode();
printf("\n students like butterscotch");
head1=createnode();
break;
case 2:
printf("students like vanilla");
print(head);
printf("students like butter scotch");
print(head1);
break;
case 3:
printf("\n students like either vanilla or butterscotch");
count=uni(head,head1);
break;
case 4:
printf("\n students like both vanilla & butterscotch");
inter(head,head1);
break;
case 5:
printf("\n students like vanilla only");
sub1(head,head1);
break;
case 6:
printf("\n students like butterscotch only");
sub2(head,head1);
break;
case 7:
printf("\n students like neither vanilla nor butterscotch=%d",m-count);
break;
}
}
return 0;
}
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ c22.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out
enter the no of students6
*************sets using singly linked list*************************
1]create
2]print
3]students like either vanilla or butterscotch
4]students like both vanilla & butterscotch
5]students like vanilla only
6]students like only butterscotch
7]students like neither vanilla nor butterscotch
enter your choice 1
students like vanillaenter the no of students 3
enter the students 5
enter the students 6
enter the students 2
students like butterscotchenter the no of students 2
enter the students 1
enter the students 3
*************sets using singly linked list*************************
1]create
2]print
3]students like either vanilla or butterscotch
4]students like both vanilla & butterscotch
5]students like vanilla only
6]students like only butterscotch
7]students like neither vanilla nor butterscotch
enter your choice3
students like either vanilla or butterscotch 5 6 2 1 3
*************sets using singly linked list*************************
1]create
2]print
3]students like either vanilla or butterscotch
4]students like both vanilla & butterscotch
5]students like vanilla only
6]students like only butterscotch
7]students like neither vanilla nor butterscotch
enter your choice4
students like both vanilla & butterscotch
*************sets using singly linked list*************************
1]create
2]print
3]students like either vanilla or butterscotch
4]students like both vanilla & butterscotch
5]students like vanilla only
6]students like only butterscotch
7]students like neither vanilla nor butterscotch
enter your choice5
students like vanilla only 5 6 2
*************sets using singly linked list*************************
1]create
2]print
3]students like either vanilla or butterscotch
4]students like both vanilla & butterscotch
5]students like vanilla only
6]students like only butterscotch
7]students like neither vanilla nor butterscotch
enter your choice6
students like butterscotch only 1 3
*************sets using singly linked list*************************
1]create
2]print
3]students like either vanilla or butterscotch
4]students like both vanilla & butterscotch
5]students like vanilla only
6]students like only butterscotch
7]students like neither vanilla nor butterscotch
enter your choice7
students like neither vanilla nor butterscotch=4
*************sets using singly linked list*************************
1]create
2]print
3]students like either vanilla or butterscotch
4]students like both vanilla & butterscotch
5]students like vanilla only
6]students like only butterscotch
7]students like neither vanilla nor butterscotch
enter your choice8
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ^C

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 09
#include<iostream>
#include<string.h>
#define max 50
using namespace std;
class STACK
{
private:
char a[max];
int top;
public:
STACK()
{
top=-1;
}

void push(char);
void reverse();
void convert(char[]);
void palindrome();
};
void STACK::push(char c)
{
top++;
a[top] = c;
a[top+1]='\0';

cout<<endl<<c<<" is pushed on stack ...";


}
void STACK::reverse()
{
char str[max];

cout<<"\n\nReverse string is : ";

for(int i=top,j=0; i>=0; i--,j++)


{
cout<<a[i];
str[j]=a[i];
}

cout<<endl;
}
void STACK::convert(char str[])
{
int j,k,len = strlen(str);
for(j=0, k=0; j<len; j++)
{
if( ( (int)str[j] >= 97 && (int)str[j] <=122 ) || ( (int)str[j] >= 65 && (int)str[j] <=90 ))
{
if( (int)str[j] <=90 )
{
str[k] = (char)( (int)str[j] + 32 );
}else
{
str[k] = str[j];
}
k++;
}
}
str[k]='\0';
cout<<endl<<"Converted String : "<<str<<"\n";
}
void STACK::palindrome()
{
char str[max];
int i,j;
for(i=top,j=0; i>=0; i--,j++)
{
str[j]=a[i];
}
str[j]='\0';
if(strcmp(str,a) == 0)
cout<<"\n\nString is palindrome...";
else
cout<<"\n\nString is not palindrome...";
}
int main()
{
STACK stack;
char str[max];
int i=0;

cout<<"\nEnter string to be reversed and check is it palindrome or not : \n\n";

cin.getline(str , 50);

stack.convert(str);

while(str[i] != '\0')
{
stack.push(str[i]);
i++;
}
stack.palindrome();
stack.reverse();

}
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ d25.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out
Enter string to be reversed and check is it palindrome or not :
technical
Converted String : technical
t is pushed on stack ...
e is pushed on stack ...
c is pushed on stack ...
h is pushed on stack ...
n is pushed on stack ...
i is pushed on stack ...
c is pushed on stack ...
a is pushed on stack ...
l is pushed on stack ...
String is not palindrome...
Reverse string is : lacinhcet
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ^C

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 10
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int precedence(char op) {
if (op == '+' || op == '-') {
return 1;
} else if (op == '*' || op == '/') {
return 2;
}
return 0; // Assuming all other characters have lower precedence
}
string infixToPostfix(string infix) {
string postfix = "";
stack<char> st;
for (char c : infix) {
if (isalnum(c)) {
postfix += c; // Operand, append to postfix expression
} else if (c == '(') {
st.push(c); // Left parenthesis, push onto stack
} else if (c == ')') {
while (!st.empty() && st.top() != '(') {
postfix += st.top();
st.pop();
}
st.pop(); // Pop the left parenthesis
} else {
while (!st.empty() && precedence(st.top()) >= precedence(c)) {
postfix += st.top();
st.pop();
}
st.push(c); // Operator, push onto stack
}
}
while (!st.empty()) {
postfix += st.top();
st.pop();
}
return postfix;
}
int evaluatePostfix(string postfix) {
stack<int> st;
for (char c : postfix) {
if (isalnum(c)) {
st.push(c - '0'); // Convert character to integer and push onto stack
} else {
int operand2 = st.top();
st.pop();
int operand1 = st.top();
st.pop();
switch (c) {
case '+':
st.push(operand1 + operand2);
break;
case '-':
st.push(operand1 - operand2);
break;
case '*':
st.push(operand1 * operand2);
break;
case '/':
st.push(operand1 / operand2);
break;
}
}
}
return st.top();
}
int main() {
string infix_expression;
cout << "Enter an infix expression: ";
cin >> infix_expression;
string postfix_expression = infixToPostfix(infix_expression);
cout << "Postfix expression: " << postfix_expression << endl;
int result = evaluatePostfix(postfix_expression);
cout << "Result: " << result << endl;
return 0;
}
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ d27.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out
Enter an infix expression: A*B(C+D)*E
Postfix expression: ABCD+*E*
Result: 14742
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ^C

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 11
#include <iostream>
#define MAX 10
using namespace std;
struct queue
{ int data[MAX];
int front,rear;
};
class Queue
{ struct queue q;
public:
Queue(){q.front=q.rear=-1;}
int isempty();
int isfull();
void enqueue(int);
int delqueue();
void display();
};
int Queue::isempty()
{
return(q.front==q.rear)?1:0;
}
int Queue::isfull()
{ return(q.rear==MAX-1)?1:0;}
void Queue::enqueue(int x)
{q.data[++q.rear]=x;}
int Queue::delqueue()
{return q.data[++q.front];}
void Queue::display()
{ int i;
cout<<"\n";
for(i=q.front+1;i<=q.rear;i++)
cout<<q.data[i]<<" ";
}
int main()
{ Queue obj;
int ch,x;
do{ cout<<"\n 1.Insert Job\n 2.Delete Job\n 3.Display\n 4.Exit\n Enter your choice : ";
cin>>ch;
switch(ch)
{ case 1: if (!obj.isfull())
{ cout<<"\n Enter data : \n";
cin>>x;
obj.enqueue(x);
cout<<endl;
}
else
cout<< "Queue is overflow!!!\n\n";
break;
case 2: if(!obj.isempty())
cout<<"\n Deleted Element = "<<obj.delqueue()<<endl;
else
{ cout<<"\n Queue is underflow!!!\n\n"; }
cout<<"\nRemaining Jobs : \n";
obj.display();
break;
case 3: if (!obj.isempty())
{ cout<<"\n Queue contains : \n";
obj.display();
}
else
cout<<"\n Queue is empty!!!\n\n";
break;
case 4: cout<<"\n Exiting Program.....";
}
}while(ch!=4);
return 0;
}
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ e29.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out
1.Insert Job
2.Delete Job
3.Display
4.Exit
Enter your choice : 1
Enter data :
5
1.Insert Job
2.Delete Job
3.Display
4.Exit
Enter your choice : 1
Enter data :
2
1.Insert Job
2.Delete Job
3.Display
4.Exit
Enter your choice : 1
Enter data :
3
1.Insert Job
2.Delete Job
3.Display
4.Exit
Enter your choice : 2
Deleted Element = 5
Remaining Jobs :
23
1.Insert Job
2.Delete Job
3.Display
4.Exit
Enter your choice : 3
Queue contains :
23
1.Insert Job
2.Delete Job
3.Display
4.Exit
Enter your choice : 4
Exiting Program.....root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 12
#include<iostream>
#include<stdio.h>
#define MAX 10
using namespace std;
struct que
{
int arr[MAX];
int front,rear;
};
void init(struct que *q)
{
q->front=-1;
q->rear=-1;
}
void print(struct que q)
{
int i;
i=q.front;
while(i!=q.rear)
{
cout<<"\t"<<q.arr[i];
i=(i+1)%MAX;
}
cout<<"\t"<<q.arr[q.rear];
}
int isempty(struct que q)
{
return q.rear==-1?1:0;
}
int isfull(struct que q)
{
return (q.rear+1)%MAX==q.front?1:0;
}
void addf(struct que *q,int data)
{
if(isempty(*q))
{
q->front=q->rear=0;
q->arr[q->front]=data;
}
else
{
q->front=(q->front-1+MAX)%MAX;
q->arr[q->front]=data;
}
}
void addr(struct que *q,int data)
{
if(isempty(*q))
{
q->front=q->rear=0;
q->arr[q->rear]=data;
}
else
{
q->rear=(q->rear+1)%MAX;
q->arr[q->rear]=data;
}
}
int delf(struct que *q)
{
int data1;
data1=q->arr[q->front];
if(q->front==q->rear)
init(q);
else
q->front=(q->front+1)%MAX;
return data1;
}
int delr(struct que *q)
{
int data1;
data1=q->arr[q->rear];
if(q->front==q->rear)
init(q);
else
q->rear=(q->rear-1+MAX)%MAX;
return data1;
}
int main()
{
struct que q;
int data,ch;
init(&q);
while(ch!=6)
{
cout<<"\t\n1.Insert front"
"\t\n2.Insert rear"
"\t\n3.Delete front"
"\t\n4.Delete rear"
"\t\n5.Print"
"\t\n6.Exit";
cout<<"\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\nEnter data to insert front : ";
cin>>data;
addf(&q,data);
break;
case 2:
cout<<"\nEnter the data to insert rear : ";
cin>>data;
addr(&q,data);
break;
case 3:
if(isempty(q))
cout<<"\nDequeue is empty!!!";
else
{
data=delf(&q);
cout<<"\nDeleted data is : "<<data;
}
break;
case 4:
if(isempty(q))
cout<<"\nDequeue is empty!!!";
else
{
data=delr(&q);
cout<<"\nDeleted data is : "<<data;
}
break;
case 5:
if(isempty(q))
cout<<"\nDequeue is empty!!!";
else
{
cout<<"\nDequeue elements are : ";
print(q);
}
break;
}
}
return 0;
}
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ e31.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out

1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 1
Enter data to insert front : 6

1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 1
Enter data to insert front : 5

1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 2
Enter the data to insert rear : 8

1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 2
Enter the data to insert rear : 7

1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 3
Deleted data is : 5
1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 4
Deleted data is : 7
1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 5
Dequeue elements are : 6 8
1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 6
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

***
Name : Bhalerao Kunal Balu
Class : SE Div : A
Roll No : 16 Subject : DSL
***************************************************************************************************
*
Practicle : 13
#include<iostream>
#include<cstdlib>
using namespace std;
class pizza
{
int front,rear,q[5];
public:
pizza()
{
front=-1;
rear=-1;
}
int isfull()
{
if((front==0&&rear==4)||front==rear+1)
{
return 1;
}
else
{
return 0;
}
}
int isempty()
{
if(front==-1&&rear==-1)
{
return 1;
}
else
{
return 0;
}
}
void add()
{
if(isfull()==0)
{
cout<<"\n Enter the Pizza ID: ";
if(front==-1&&rear==-1)
{
front=0;
rear=0;
cin>>q[rear];
}
else
{
rear=(rear+1)%5;
cin>>q[rear];
}
char c;
cout<<" Do you want to add another order ? ";
cin>>c;
if(c=='y'||c=='Y')
add();
}
else
{
cout<<"\n Orders are full ";
}
}
void serve()
{
if(isempty()==0)
{
if(front==rear)
{
cout<<"\n Order served is : "<<q[front];
front=-1;
rear=-1;
}
else
{
cout<<"\n Order served is : "<<q[front];
front=(front+1)%5;
}
}
else
{
cout<<"\n Orders are empty ";
}
}
void display()
{
if(isempty()==0)
{
for(int
i=front;i!=rear;i=(i+1)%5)
{
cout<<q[i]<<"<- ";
}
cout<<q[rear];
}
else
{
cout<<"\n Orders are empty";
}
}
void check()
{
int ch;
cout<<"\n\n * * * * PIZZA PARLOUR * * * * \n\n";
cout<<"\n 1. Add a Pizza \n 2. Display the Orders \n 3. Serve a pizza \n 4. Exit \n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
add();
break;
case 2:
display();
break;
case 3:
serve();
break;
case 4:
exit(0);
default:
cout<<"Invalid choice ";
check();
}
char ch1;
cout<<"\n Do you want to continue? ";
cin>>ch1;
if(ch1=='y'||ch1=='Y')
check();
}
};
int main()
{
pizza p1;
p1.check();
return 0;
}
*****************************************OUTPUT***********************************
*******
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# g++ e32.cpp
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# ./a.out
* * * * PIZZA PARLOUR * * * *
1. Add a Pizza
2. Display the Orders
3. Serve a pizza
4. Exit
Enter your choice : 1
Enter the Pizza ID: 1
Do you want to add another order ? Y
Enter the Pizza ID: 2
Do you want to add another order ? N
Do you want to continue? Y
* * * * PIZZA PARLOUR * * * *
1. Add a Pizza
2. Display the Orders
3. Serve a pizza
4. Exit
Enter your choice : 2
1<- 2
Do you want to continue? Y
* * * * PIZZA PARLOUR * * * *
1. Add a Pizza
2. Display the Orders
3. Serve a pizza
4. Exit
Enter your choice : 3
Order served is : 1
Do you want to continue? Y

* * * * PIZZA PARLOUR * * * *

1. Add a Pizza
2. Display the Orders
3. Serve a pizza
4. Exit
Enter your choice : 4
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#

You might also like