Professional Documents
Culture Documents
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))
text="malayalam"
print("Given text is "+text)
rev=reversed(text)
if list(text)==list(rev):
print("its a palindrome")
else:
print("its not a palindrome")
def main():
# call freq function
freq(sentence)
Output:
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3
student.py
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
Name :- MAGAR OMKAR BHAUSAHEB
Class :- S.E. Computer
Subject :- DSL
Roll No :- 35
k = 0
while k < m: # Fix: Change to m instead of n
if row_min < a[k][ci]:
break
k += 1
if k == m:
print("The saddle point is:", row_min)
f = 1
break # Fix: Add break to exit the loop if
saddle point is found
if f == 0:
print("Saddle point does not exist")
Output:-
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3
student.py
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
Name :- MAGAR OMKAR BHAUSAHEB
Class :- S.E. Computer
Subject :- DSL
Roll No :- 35
'''
def Selection_Sort(marks):
for i in range(len(marks)):
#<------------------------------------------------------------
--------------------------->
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):
#<------------------------------------------------------------
--------------------------->
#<------------------------------------------------------------
---------------------------->
# 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
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
#<----------------------------------------END OF PROGRAM------
------------------------------------------->
Output:-
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3
student.py
---------------MENU---------------
1. Selection Sort of the marks
2. Bubble Sort of the marks
3. Exit
Do you want to display top marks from the list (yes/no) : yes
Top 5 Marks are :
90
84
77
63
25
---------------MENU---------------
1. Selection Sort of the marks
2. Bubble Sort of the marks
3. Exit
Do you want to display top five marks from the list (yes/no) : no
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
Name :- MAGAR OMKAR BHAUSAHEB
Class :- S.E. Computer
Subject :- DSL
Roll No :- 35
#include<iostream>
using namespace std;
int main()
{
float marks[20];
int i, n, ch;
cout << "\n Enter the total no.of students:";
cin >> n;
return 0;
}
Output:-
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3
student.py
#Write a python program to store first year percentage of students in array. Write function
for sorting array of floating point numbers in ascending order using quick sort and display
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
while True:
while lower_bound <= upper_bound and perc[lower_bound]
<= pivot:
lower_bound += 1
# Main
unsorted_percentage = []
sorted_percentage = []
flag = 1
while flag == 1:
print("\nMENU")
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")
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
student.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 : 3
Enter the percentage of Student 1 : 89
Enter the percentage of Student 2 : 77
Enter the percentage of Student 3 : 56
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
89.0
77.0
56.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 :
56.0,77.0,89.0
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
Name :- MAGAR OMKAR BHAUSAHEB
Class :- S.E. Computer
Subject :- DSL
Roll No :- 35
#include <iostream>
#include <stdlib.h>
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;
void cinemax::display()
{
int r = 1;
node* temp = head;
int count = 0;
if (temp->status == 0)
cout << "| | ";
else
cout << "|_B_| ";
count++;
if (count % 7 == 0)
{
cout << endl;
r++;
}
temp = temp->next;
}
void cinemax::book()
{
int x;
string y;
label:
cout << "\n\n\nEnter seat number to be booked\n";
cin >> x;
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 your ID\n";
cin >> y;
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 = head;
int count = 0;
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. Cancel Seat\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:-
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3
student.py
Enter Choice
1. Current SeatStatus
2. Book Seat
3. Available Seat
4. Cancel Seat
Screen this way
Enter Choice
1. Current SeatStatus
2. Book Seat
3. Available Seat
4. Cancel Seat
2
#include <stdio.h>
#include <stdlib.h>
node *createnode()
{
int n, i;
node *p, *head, *t;
head = NULL;
printf("Enter the number of students: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
p = (node *)malloc(sizeof(node));
printf("Enter the student's data: ");
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;
}
if (found != 1)
{
printf("\t %d", q->data);
}
count++;
}
return count;
}
if (found == 1)
{
printf("\t %d", q->data);
}
}
}
if (found != 1)
{
printf("\t %d", p->data);
}
}
}
if (found != 1)
{
printf("\t %d", q->data);
}
}
}
int main()
{
node *head, *head1;
int ch = 0, m, count;
while (ch != 8)
{
printf("\n************* Sets using singly linked list
*************************");
printf("\n1] Create\n2] Print\n3] Students like either
vanilla or butterscotch\n");
printf("4] Students like both vanilla &
butterscotch\n5] Students like vanilla only\n");
printf("6] Students like only butterscotch\n7]
Students like neither vanilla nor butterscotch\n");
printf("8] Exit\nEnter your choice: ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Students like vanilla\n");
head = createnode();
printf("Students like butterscotch\n");
head1 = createnode();
break;
case 2:
printf("Students like vanilla\n");
print(head);
printf("Students like butterscotch\n");
print(head1);
break;
case 3:
printf("Students like either vanilla or
butterscotch\n");
count = uni(head, head1);
printf("\nTotal students like neither vanilla nor
butterscotch=%d\n", m - count);
break;
case 4:
printf("Students like both vanilla &
butterscotch\n");
inter(head, head1);
break;
case 5:
printf("Students like vanilla only\n");
sub1(head, head1);
break;
case 6:
printf("Students like butterscotch only\n");
sub2(head, head1);
break;
case 7:
printf("Students like neither vanilla nor
butterscotch=%d\n", m - count);
break;
case 8:
printf("Exiting the program\n");
break;
default:
printf("Invalid choice\n");
}
}
return 0;
}
Output:-
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3
student.py
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
Name :- MAGAR OMKAR BHAUSAHEB
Class :- S.E. Computer
Subject :- DSL
Roll No :- 35
#include<iostream>
#include<string.h>
#define max 50
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];
}
str[top + 1] = '\0';
}
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 << "\nString is palindrome...";
else
cout << "\nString is not palindrome...";
}
int main() {
STACK stack;
char str[max];
int i = 0;
stack.convert(str);
stack.palindrome();
stack.reverse();
return 0;
}
Output:-
root@root123-HP-ProDesk-600-G3-SFF:/home/root123# python3
student.py
Computer Engineering
#include <iostream>
#include <stack>
#include <string>
using namespace std;
while (!st.empty()) {
postfix += st.top();
st.pop();
}
return postfix;
}
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;
return 0;
}
Output:-
Enter an infix expression: A*b+D
Postfix expression: Ab*D+
Result: 870
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
NAME :- MAGAR OMKAR BHAUSAHEB
Class :- S.E. Computer
Subject :- DSL
Roll No :- 35
#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() {
return (q.front == q.rear) ? 1 : 0;
}
int isfull() {
return (q.rear == MAX - 1) ? 1 : 0;
}
void enqueue(int);
int delqueue();
void display();
};
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.";
break;
}
} while (ch != 4);
return 0;
}
Output:-
root@root123-HP-ProDesk-600-G3-SFF:/home/root123#
1.Insert Job
2.Delete Job
3.Display
4.Exit
Enter your choice : 1
Enter data :
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 : 2
Deleted Element = 23
Remaining Jobs :
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 :- MAGAR OMKAR BHAUSAHEB
Class :- S.E. Computer
Subject :- DSL
Roll No :- 35
#include<iostream>
#include<stdio.h>
#define MAX 10
using namespace std;
struct que
{
int arr[MAX];
int front, rear;
};
while (i != q.rear)
{
cout << "\t" << q.arr[i];
i = (i + 1) % MAX;
}
if (q->front == q->rear)
init(q);
else
q->front = (q->front + 1) % MAX;
return data1;
}
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# python3
student.py
1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 1
1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 2
1.Insert front
2.Insert rear
3.Delete front
4.Delete rear
5.Print
6.Exit
Enter your choice : 5
#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 ";
}
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# python3
student.py
* * * * PIZZA PARLOUR * * * *
1. Add a Pizza
2. Display the Orders
3. Serve a pizza
4. Exit
Enter your choice : 2
* * * * PIZZA PARLOUR * * * *
1. Add a Pizza
2. Display the Orders
3. Serve a pizza
4. Exit
Enter your choice : 3
* * * * PIZZA PARLOUR * * * *
1. Add a Pizza
2. Display the Orders
3. Serve a pizza
4. Exit
Enter your choice : 1