Term 2 CS Practical File 2021-22
Term 2 CS Practical File 2021-22
CBSE
Logo
School Name
Address
[Name of Student]
CERTIFICATE
ExternalExaminer Principal
Signature Seal andSignature
No. Practical Date Signature
Write a menu-driven python program to implement stack
1
operation.
2 Write a program to implement a stack for the employee details
(empno, name).
3 Write a python program to check whether a string is a
palindrome or not using stack.
4 Queries Set 1 (Database Fetching records)
5 Queries Set 2 (Based on Functions)
6 Queries Set 3 (DDL Commands)
7 Queries set 4 (Based on Two Tables)
8 Queries Set 5 (Group by , Order By)
o
PartADataStructure
1. Write a menu-driven python program to implement stackoperation.
C ode:
def check_stack_isEmpty(stk):
if stk==[]:
return True
else:
return False
# An empty list to store stack elements, initially empty
s=[]
top = None # This is top pointer for push and pop
def main_menu():
while True:
print("Stack Implementation")
print("1 - Push")
print("2 - Pop")
print("3 - Peek")
print("4 - Display")
print("5 - Exit")
ch = int(input("Enter the your choice:"))
if ch==1:
el = int(input("Enter the value to push an
element:"))
push(s,el)
elifch==2:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("Element popped:",e)
elifch==3:
e=pop_stack(s)
if e=="UnderFlow":
print("Stack is underflow!")
else:
print("The element on top is:",e)
elifch==4:
display(s)
elifch==5:
break
else:
print("Sorry, You have entered invalid option")
def push(stk,e):
stk.append(e)
top =len(stk)-1
def display(stk):
if check_stack_isEmpty(stk):
print("Stack is Empty")
else:
top = len(stk)-1
print(stk[top],"-Top")
for i in range(top-1,-1,-1):
print(stk[i])
def pop_stack(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
e = stk.pop()
iflen(stk)==0:
top = None
else:
top = len(stk)-1
return e
def peek(stk):
if check_stack_isEmpty(stk):
return "UnderFlow"
else:
top = len(stk)-1
return stk[top]
Output:
2. Write a program to implement a stack for the employee details (empno,name).
Code:
stk=[]
top=-1
def line():
print('~'*100)
def isEmpty():
global stk
ifstk==[]:
print("Stack is empty!!!")
else:
None
def push():
global stk
global top
empno=int(input("Enter the employee number to push:"))
ename=input("Enter the employee name to push:")
stk.append([empno,ename])
top=len(stk)-1
def display():
global stk
global top
iftop==-1:
isEmpty()
else:
top=len(stk)-1
print(stk[top],"<-top")
for i in range(top-1,-1,-1):
print(stk[i])
def pop_ele():
global stk
global top
iftop==-1:
isEmpty()
else:
stk.pop()
top=top-1
def main():
whileTrue:
line()
print("1.Push")
print("2. Pop")
print("3. Display")
print("4.Exit")
ch=int(input("Enter your choice:"))
if ch==1:nm
push()
print("Element Pushed")
elifch==2:
pop_ele()
elifch==3:d
isplay()
elifch==4:
break
else:
print("Invalid Choice")
Output:
3. Write a python program to check whether a string is a palindrome or notusing
stack.
Code:
stack = []
top = -1
# push function
def push(ele):
global top
top += 1
stack[top] = ele
# pop function
def pop():
global top
ele = stack[top]
top -= 1
return ele
# Finding the
mid mid = length
// 2 i = 0
while i< mid:
push(string[i])
i += 1
if isPalindrome(string):
print("Yes, the string is a palindrome")
else:
1. Consider the following MOVIE table and write the SQL queries based onit.
Movie_ID MovieName Type ReleaseDate ProductionCost BusinessCost
M001 The Kashmir Files Action 2022/01/26 1245000 1300000
M002 Attack Action 2022/01/28 1120000 1250000
M003 LooopLapeta Thriller 2022/02/01 250000 300000
M004 Badhai Do Drama 2022/02/04 720000 68000
M005 ShabaashMithu Biography 2022/02/04 1000000 800000
M006 Gehraiyaan Romance 2022/02/11 150000 120000
a) Display all information from movie.
b) Display the type of movies.
c) Display movieid, movie name, total_eraning by showing the business done by the
movies. Claculate the business done by movie using the sum of production cost
and business cost.
d) Display movieid, moviename and productioncost for all movieswith
productioncost greater thatn 150000 and less than1000000.
e) Display the movie of type action and romance.
f) Display the list of movies which are going to release in February,2022.
Answers:
a)select * frommovie;
b) select distinct from amovie;
2. Write followingqueries:
a) Write a query to display cube of5.
b) Write a query to display the number 563.854741 rounding off to the nexthnudred.
c) Write a query to display "put" from the word"Computer".
d) Write a query to display today's date into DD.MM.YYYYformat.
e) Write a query to display 'DIA' from the word"MEDIA".
f) Write a query to display moviename - type from the tablemovie.
g) Write a query to display first four digits ofproductioncost.
h) Write a query to display last four digits ofbusinesscost.
i) Write a query to display weekday of releasedates.
j) Write a query to display dayname on which movies are going to bereleased.
Answers:
a)selectpow(5,3);
b)select round(563.854741,-2);
c)selectmid("Computer",4,3);
e)selectright("Media",3);
3. Suppose your school management has decided to conduct cricket matches between
students of Class XI and Class XII. Students of each class are asked to join any
one of the four teams – Team Titan, Team Rockers, Team Magnet and Team
Hurricane. During summer vacations, various matches will be conducted between
these teams. Help your sports teacher to do thefollowing:
a) Create a database “Sports”.
b) Create a table “TEAM” with followingconsiderations:
a. It should have a column TeamID for storing an integer value between 1 to9,
which refers to unique identification of ateam.
b. Each TeamID should have its associated name (TeamName), which should be
a string of length not less than 10characters.
c. Using table level constraint, make TeamID as the primarykey.
c) Show the structure of the table TEAM using a SQLstatement.
d) As per the preferences of the students four teams were formed as given below.
Insert these four rows in TEAMtable:
a. Row 1: (1,Tehlka)
b. Row 2: (2,Toofan)
c. Row 3: (3,Aandhi)
d. Row 3: (4,Shailab)
e) Show the contents of the table TEAM using a DMLstatement.
f) Now create another table MATCH_DETAILS and insert data as shown below.Choose
appropriate data types and constraints for eachattribute.
Answers:
a) create databasesports;
c) descteam;
Inserting data:
Creating anothertable:
create table match_details
-> (matchidvarchar(2) primary key,
->matchdate date,
->firstteamidint(1) references team(teamid),
->secondteamidint(1) references team(teamid),
->firstteamscoreint(3),
->secondteamscoreint(3));
4. Write followingqueries:
a) Display the matchid, teamid, teamscorewhoscored more than 70 in firstining
along with teamname.
b) Display matchid, teamname and secondteamscore between 100 to160.
c) Display matchid, teamnames along withmatchdates.
d) Display unique teamnames
e) Display matchid and matchdate played by Anadhi andShailab.
Answers:
a)select match_details.matchid,match_details.firstteamid,
team.teamname,match_details.firstteamscore from
match_details, team where match_details.firstteamid =
team.teamid andmatch_details.first
b)select match_details.matchid,match_details.firstteamid,
team.teamname,match_details.firstteamscore from
match_details, team where match_details.firstteamid =
team.teamid andmatch_details.firstteamscore>70;