You are on page 1of 33

REPORT FILE IN COMPUTER SCIENCE FOR SESSION

2021-2022
CLASS :12TH
EAST DELHI PUBLIC SCHOOL

Submitted by :Deepak Singh


CERTIFICATE

This is to certify that ________________ ,


Roll No. _____ of Class 12th Session 2021-22
has prepared the Practical File as per the
prescribed Practical Syllabus of Computer
Science Code-083, Class-12 AISSCE (CBSE)
under my supervision.
It is the original work done by him/her. His/ her
work is really appreciable.
I wish him/her a very bright success..

______________ ______________
Signature of Signature of
Teacher. External
INDEX

■ Part A: 3 programs on data structure stacks


■ Part B: 5 sets of SQL queries using one/two tables
■ Queries Set 1 (Database Fetching records)
■ Queries Set 2 (Based on Functions)
■ Queries Set 3 (DDL Commands)
■ Queries set 4 (Based on Two Tables)
■ Queries Set 5 (Group by , Order By)
■ Part C: SQL Database Connectivity 2 Programs
Part A: 3 programs on data structure stack

1 : Write a program, with separate user defined functions to perform the following operations:

● Push the keys (name of the student) of the dictionary into a stack, where the corresponding value

(marks) is greater than75.

● Pop and display the content of the stack.For example:

If the sample content of the dictionary is as follows:

R={“OM”:76, “JAI”:45, “BOB”:89, “ALI”:65, “ANU”:90,”TOM”:82}

The output from the program should be:

TOM ANU BOB OM


PROGRAM:
OUTPUT:
# Stack Implementation
# Main program
R={“OM”:76, “JAI”:45, “BOB”:89,
“ALI”:65, “ANU”:90, “TOM”:82} ST=[]

# Function Push() for i in R:

def push(s,n): if R[i]>=75:

s.append(n) push(ST,i)

# Function pop() while True:

def pop(s): if ST!=[]:

if s!=[]: print(pop(ST),end=‘ ‘)

return s.pop() else:

else: break

return None
2 : Write a program with separate user defined functions to perform the following operations

based on this list.

● Traverse the content of the list and push the even numbersinto a stack.

● Pop and display the content of the stack.

For Example:

If the sample Content of the list is as follows:

N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]

Sample Output of the code should be:

38 22 98 56 34 12
PROGRAM
: OUTPUT
# Stack Implementation
# Main program
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
ST=[]
# Function Push()
for i in N:
def push(s,n):
if i%2==0:
s.append(n)
push(ST,i)
# Function pop()
while True:
def pop(s):
if ST!=[]:
if s!=[]:
print(pop(ST),end=‘ ‘)
return s.pop()
else:
else:
break
return None
3:Write a program to implement a stack for the employee details (empno,
name). PROGRAM:
stk=[] top=-1 def
Def display(): def main(): while
line():
global stk True: line()
print('~'*100) def global top
isEmpty(): global print("1. Push")
if top==-1:
stk if stk==[]: print("2. Pop")
isEmpty()
print("Stack is else: print("3.
empty!!!") else: top=len(stk)-1 Display")
None def push(): print(stk[top],”<- print("4. Exit")
global stk global top”) ch=int(input("Ent
for i in er your choice:"))
top
range(top-1,-1,-1): if ch==1:nm
empno=int(input( print(stk[i])
"Enter the push()
employee number print("Element
def pop_ele():
to push:")) global stk Pushed") elif
ename=input("En global top ch==2: pop_ele()
ter the employee if top==-1: elif ch==3:
name to push:") isEmpty() display() else:
else: print("Invalid
stk.append([empn stk.pop()
o,ename]) Choice")
top=top-1
top=len(stk)-1
OUTPUT:
Part B: 5 sets of SQL queries using one/two tables
Queries Set 1 (Database Fetching records)
[1] Consider the following MOVIE table and write the SQL queries based on it.
1-Display all information from movie.
2-Display the type of movies.
3-Display movieid, moviename, total_eraning by showing the business done by the movies. Claculate the business
done by movie using the sum of productioncost and businesscost.
4-Display movieid, moviename and productioncost for all movies with productioncost greater thatn 150000 and less
than 1000000.
5-Display the movie of type action and romance.
6-Display the list of movies which are going to release in February, 2022.
Answers:

[1] select * from movie;

OUTPUT:
2. Select distinct from a movie;

3. select movieid, moviename, productioncost


+ businesscost “total earning” from movie;
4. Select movie_id,moviename, productioncost from movie where producst is >150000 and <1000000

5. Select moviename from movie where type =’action’ or type=’romance’;

6. select moviename from moview where month(releasedate)=2;


Queries Set 2 (Based on Functions)
1-Write a query to display cube of 5.
2-Write a query to display the number 563.854741 rounding off to the next hnudred.
3-Write a query to display “put” from the word “Computer”.
4-Write a query to display today’s date into DD.MM.YYYY format.
5-Write a query to display ‘DIA’ from the word “MEDIA”.
6-Write a query to display moviename – type from the table movie.
7-Write a query to display first four digits of productioncost.
8-Write a query to display last four digits of businesscost.
9-Write a query to display weekday of release dates.
10-Write a query to display dayname on which movies are going to be released.
Answers:
[1] select pow(5,3);

[2] select round(563.854741,-2);


3] select mid(“Computer”,4,3);

[4] select concat(day(now()),concat(‘.’,month(now()),concat(‘.’,year(now()))))


“Date”;

[5] select right(“Media”,3);


[6] select concat(moviename,concat(‘ – ‘,type)) from movie;

[7] select left(productioncost,4) from movie;


[8] select right(businesscost,4) from movie

[9] select weekday(releasedate) from movie;


[10] select dayname(releasedate) from movie;

Queries Set 3 (DDL Commands)


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 the
following:
1-Create a database “Sports”.
2-Create a table “TEAM” with following
A-It should have a column TeamID for storing an integer
value between 1 to 9, which refers to unique identification
of a team.
B-Each TeamID should have its associated name
(TeamName), which should be a string of length not less
than 10 characters.
C-Using table level constraint, make TeamID as the
primary key.
D-Show the structure of the table TEAM using a SQL
statement.
E-As per the preferences of the students four teams were
formed as given below. Insert these four rows in TEAM
table:
Row 1: (1, Tehlka)
Row 2: (2, Toofan)
Row 3: (3, Aandhi)
Row 3: (4, Shailab)
F-Show the contents of the table TEAM using a DML
statement
3-Now create another table MATCH_DETAILS and insert
data as shown below. Choose appropriate data types and
constraints for each attribute.
Answers:

[1] create database sports

2] Creating table with the given specification

Showing the structure of table using SQL statement:


Inserting data:
Show the content of table – team:
Creating another table:
Queries set 4 (Based on Two Tables)
1-Display the matchid, teamid, teamscore whoscored
more than 70 in first ining along with team name.
2-Display matchid, teamname and secondteamscore
between 100 to 160.
3-Display matchid, teamnames along with matchdates.
4-Display unique team names
5-Display matchid and matchdate played by Anadhi
andAnswers
Shailab.:
[1] select match_details.matchid,
match_details.firstteamid,
team.teamname,match_details.firstteamscore from
match_details, team where
match_details.firstteamid=team.teamid and
match_details.firstteamscore>70;
[2] select matchid, teamname, secondteamscore from match_details, team where
match_details.secondteamid=team.teamid and match_details.secondteamscore between 100 and 160;

[3] select matchid,teamname,firstteamid,secondteamid,matchdate from match_details, team where


match_details.firstteamid=team.teamid;

[4] select distinct(teamname) from match_details, team where


match_details.firstteamid=team.teamid;
[5] select matchid,matchdate from match_details, team where
match_details.firstteamid=team.teamid and team.teamname in (‘Aandhi’,’Shailab’);

Queries Set 5 (Group by , Order By)


Consider the following table stock table to answer the queries:
1-Display all the items in the ascending order of stockdate.
2-Display maximum price of items for each dealer individually as per
dcode from stock.
3-Display all the items in descending orders of itemnames.
4-Display average price of items for each dealer individually as per
doce from stock which avergae price is more than 5.
5-Diisplay the sum of quantity for each dcode
Answers:
[1] select * from stock order by stockdate;

[2] select dcode,max(unitprice) from stock group by code;


[3] select * from stock order by item desc;

[4] select dcode,avg(unitprice) from stock group by dcode having avg(unitprice)>5;

[5] select dcode,sum(qty) from stock group by dcode


Part C: SQL Database Connectivity 2
1: Write a Program to show how to update a record in a database table Emp using
Programs
MySQL database connectivity in python.

PROGRAM:
import mysql.connector as conn
mydb=conn.connect(host="localhost",user="root",passwd="tiger",database="csfile")
# create new cursor
cur=mydb.cursor()
eno=int(input("Enter Employee number : "))
sl=float(input('Enter Salary : '))
sql="update emp set sal=%f where empno=%d" % (sl,eno)
try:
ans=input("Are you sure you want to update the record : ")
if ans=='y' or ans=='Y':
cur.execute(sql)
print("Emp no-",eno," salary updated successfully...")
mydb.commit()
except Exception as e:
print("Error! Perhaps Emp no is incorrect...",e)
mydb.rollback()
mydb.close()
OUTPUT:

2: Write a Program to show how to DELETE a record from a database table Emp
using

MySQL database connectivity in python.


PROGRAM:

Import mysql.connector as conn

mydb=conn.connect(host=“localhost”,user=“root”,passwd=“tiger”,database=“csfile”)

# create new cursor

cur=mydb.cursor()

eno=int(input(“Enter Employee number : “))

sql=“delete from emp where empno=%d” % (eno)


Try:

ans=input(“Are you sure you want to delete


the record : “)

if ans==‘y’ or ans==‘Y’:
OUTPUT:
cur.execute(sql)

print(“Emp no-”,eno,” record deleted


successfully...”)

mydb.commit()

except Exception as e:

print(“Error! Perhaps Emp no is


incorrect...”,e)

mydb.rollback()

mydb.close()

You might also like