You are on page 1of 7

Computer Science

CLASS-XII SC
TERM-2
Code No. 083
2021-22
----------------------------------------------------------------------------------------------------
PROGRAMS FOR REPORT FILE (PRACTICAL RECORD)

1. Write a program that depending upon user’s choice either push or pop an element
in a stack.

def Push_Stack(STACK,item):
STACK.append(item)
top=len(STACK)-1

def Stack_Pop(STACK):
if STACK==[]:
return "underflow"
else:
item=STACK.pop()
if len(STACK)==0:
top=None
else:
top=len(STACK)-1
return item

def Stack_Display(STACK):
if STACK==[]:
return "underflow"
else:
top=len(STACK)
#print(STACK[top]," ")
for a in range(0,top,1):
print(STACK[a])

STACK=[]
top=None
while True :
print("[1] Push")
print("[2] Pop")

Vikash Residential School, Bargarh Page 65


print("[3] Dsiplay Stack")
print("[4] Exit")
ch=int(input("Enter your choice 1 to 4 "))
if ch==1:
item=input("Enter your item ")
Push_Stack(STACK,item)
elifch==2:
item=Stack_Pop(STACK)
if item=="underflow":
print("Stack is empty")
else:
print("popped item is ",item)
elifch==3:
Stack_Display(STACK)
else :
break
2. Write PUSH (Books) and POP (Books) methods, in puth on to add books and
remove
Booksconsidering them to act as Push & Pop operation of Stack.

def Push_Book(BOOK,bname):
BOOK.append(bname)
top=len(BOOK)-1

def Pop_Book(BOOK):
if BOOK==[]:
return "underflow"
else:
bname=BOOK.pop()
if len(BOOK)==0:
top=None
else:
top=len(BOOK)-1
return bname

def Display_Book(BOOK):
if BOOK==[]:
return "underflow"
else:
top=len(BOOK)
for a in range(0,top,1):

Vikash Residential School, Bargarh Page 66


print(BOOK[a])

BOOK=[]
top=None
while True :
print("[1] Push Book Name on Library")
print("[2] Pop Book Name from Library")
print("[3] Dsiplay Book Name")
print("[4] Exit")
ch=int(input("Enter your choice 1 to 4 "))
if ch==1:
bname=input("Enter your Book name ")
Push_Book(BOOK,bname)
elifch==2:
bname=Pop_Book(BOOK)
if bname=="underflow":
print("Book Library is Empty")
else:
print("popped Book is ",bname)

elifch==3:
Display_Book(BOOK)
else :
break
3. A line of text is read from the input terminal into a stack. Write an program to
output the
string in the reverse order, each character appearing twice.
(e.g a b c d e should be changed to ee dd cc bb aa).

def Push_Char(LOC,cname):
LOC.append(cname)
top=len(LOC)-1

def Display_Char(LOC):
if LOC==[]:
return "underflow"
else:
top=len(LOC)
for a in range(top-1,-1,-1):
print(LOC[a]*2," ")

Vikash Residential School, Bargarh Page 67


LOC=[]
top=None
while True:
print("[1] Enter the line of character one after another")
print("[2] Display the Character twice in reverse form")
print("[3] Exit")
ch=int(input("Enter your choice 1 to 4 "))
if ch==1:
a=int(input("Enter how many character you want to push in to the stack"))
while a!=0:
cname=input("Enter your character ")
Push_Char(LOC,cname)
a=a-1
elifch==2:
Display_Char(LOC)
else:
break

4. SQL Queries – Minimum 5 sets using one table / two tables.

Consider the following tables FACULTY and COURSES. Write the MySQL queries from
(i) to (v).
FACULTY
F_ID Fname Lname Join_date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000

COU
RSE
S
C_ID F_ID Cname Fees
C21 102 GridComputing 40000
C22 106 SystemDesign 16000
C23 104 ComputerSecurity 8000
C24 106 ComputerSecurity 15000
C25 102 SystemDesign 20000
C26 107 VisualBasic 6000

Vikash Residential School, Bargarh Page 68


a. Increase the salary to 5% more of those FACULTY who have joined in between
2001
to 2006.
MySql> update FACULTY set Salary=Salary+(Salary*20/100) where
year(Join_date) in between 2001 and 2006;
b. display all the record of FACULTY in ascending order based on their Joining date.
MySql>select * from FACULTY order by Join_date;
c. Display CourseName and TotalFee of each similar courses .
MySql>select Cname, sum(Fees)”TotalFee” from COURSES group by Cname;
d. Write the Sql query to add a new attribute LOCATION in a table TEACHER to store
the addressof teachers.
MySql> alter table TEACHER add column (LOCATION char(15));
e. Write the Sql query remove course details from the table COURSES which is/are not
preferred by any teachers
MySql> delete from COURSE C, TEACHER T where C.F_ID<>T.F_ID;

programs based on Python – SQL connectivity.

5. Consider the following tables STUDENTwhich is constructed under a database


STUDENTSDB in MySql.

Preview of the table STUDENT given below.

Vikash Residential School, Bargarh Page 69


Write a Python program to do the proper connectivity with the database STUDENTDB
exist
on MySql environment and write the query to update Fee 10% more of those student
whose
names starts with “Su” and “Sh” and display.

CODES

import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="STUDENTDB"
)
db_cursor = db_connection.cursor()
ST=UPDATE STUDENT SET price = price+(price*0.1) WHERE name LIKE "Su%"
OR "Sh%"; #Updating records
db_cursor.execute(ST)
db_connection.close()

6. Consider the following tables TEACHERwhich is constructed under a database


SCHOOLDB in MySql.

Preview of the table TEACHER given below.

No. Name Department Date_of_ Salary Sex


Joining
1. Raja Computer 21/5/1998 8000 M
2. Sangita History 21/5/1997 9000 F
3. Ritu Sociology 29/8/1998 8000 F
4. Kumar Linguistics 13/6/1996 10000 M
5. Venkatraman History 31/10/1999 8000 M
6. Sidhu Computer 21/5/1986 14000 M
7. Aishwarya Sociology 11/1/1988 12000 F

Vikash Residential School, Bargarh Page 70


Write a Python program to do the proper connectivity with the database SCHOOLDB
exist on MySql environment and write the query to display the Name, Department, and
Salary of the lady teacher having maximum salary.

CODE

import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="SCHOOLDB"
)
db_cursor = db_connection.cursor()
ST=SELECT Name, Department, MAX(Salary) FROM TEACHER WHERE
SEX="F"; #Updating records
db_cursor.execute(ST)
db_connection.close()

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

Vikash Residential School, Bargarh Page 71

You might also like