Computer

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

CARE ENGLISH SCHOOL

CHHATARPUR

Session : 2022-23

Computer Science
Project File

Submitted To- Submitted By-


Abhinav Vishwakarma
Class XII (Biology)
CERTIFICATE

This is to certify that Abhinav Vishwakarma of class XII has


successfully completed his ‘Computer Science Project File’ during
academic session 2022-23 as per the guidelines issued by Central
Board of Secondary Education.

Internal Examiner’s Signature External Examiner’s Signature

Date :

Principal’ s Signature
ACKNOWLEDGEMENT

I would like to express my special thanks of gratitude to my teacher as


well as our Principal ma'am , who gave me the golden opportunity to do
this wonderful project. This project also helped me in doing a lot of
research and i came to know about so many new things.
I am extremely grateful to my parents and my friends who gave
valuable suggestions and guidance for completion of my project . This
co-operation and healthy criticism came handy and useful with them.
Hence, I would like to Thank all the above mentioned people once
again.
Table Of Contents

Sr. No. Topic Page Signature


No.
1 Program-1
Root of quadratic equation
2 Program-2
Call by reference/ Call by value
3 Program-3
Different types of arguments
4 Program-4
Demonstrate scope of variable
5 Program-5
Define a python package
6 Program-6
Counting no. Of lines in a file
7 Program-7
Fibonacci sequence
8 Program-8
Working with tell and seek function
9 Program-9
Finding lines containing a character in a file
10 Program-10
Stack implementation using list
11 Program-11
SQL queries
12 Program-12
SQL queries
13 Program-13
SQL queries
14 Program-14
SQL queries
15 Program-15
SQL queries
16 Program-16
Python to SQL connectivity
Program-1
Calculating roots of a quadratic equation

import math
print("For quadratic equation ax^2+bx+c=0, enter coefficients")
a= int(input("Enter a value for coefficient a: "))
b= int(input("Enter value for coefficient b : "))
c= int(input("Enter a value of constant c :"))
if a ==0:
print("Value of",a,"should not be zero")
print("Aborting!")
else :
delta= b*b-4*a*c
if delta > 0:
root1 = (-b+math.sqrt(delta))/(2*a)
root2 = (-b-math.sqrt(delta))/(2*a)
print("Roots are real and unequal")
print("Root=1",root1,"Root2",root2)
elif delta ==0:
root3=(-b+math.sqrt(delta))/(2*a)
print("Roots are real and equal")
print("roots=",root3,root3)
else:
print("Roots are complex and imaginary")

Output

For quadratic equation ax**2+bx+c=0,enter coefficients


Enter value of coefficient a :1
Enter value of coefficient b :-6
Enter value of constant c :5
Roots are real and unequal
Root1=5.0 Root2=1.0
Program-2
Call by reference and Call by value
#call by value
def f1(a,b):
a=a+1
b=b+1
print("Inside function f1:",a,b)
#call by reference
def f2(L):
L[1]=33
print("Inside function f2:",L)
#__main__
x,y= 10,20
f1(x,y)
print("In main function x,y:",x,y)
lst[10,20,30]
print("In main before function call lst:",lst)
f2(lst)
print("In main after function call lst:",lst)

Output

Inside function f1: 11 21


In main function x,y : 10 20
In main before function call lst:[10,20,30]
Inside function f2:[10,33,30]
In main after function call lst:[10,33,30]
Program-3
Demonstration of types of arguments
def positional(a,b):
print(a-b,end='\t')
def default(a,b=10):
print(a-b,end='\t')
def keyword (c1,c2,c3):
print("\tThe youngest child is:",c3)
def variable(*arg):
print(arg,end='\t')
#__main__
print('Positional Argument')
positional(100,200)
positional(200,100)
print("\nDefault Argument")
default(100,200)
default(100)
print("\nKeyword Argument")
keyword (c3='Amar', c1= 'Akbar', c2='Anthony')
print("Variable Length Argument")
variable(2,3,4)
Variable(1,2)

Output

Positional Argument
-100 100
Default Argument
-100 90
Keyword Argument
The youngest child is: Amar
Variable Length Argument
(2,3,4) (1,2)
Program-4
Demonstration of scope of variable [LEGB] rule
import math
p=5
def sum(q,r=2):
global p
p=r+q**2
return p
a,b=10,5
print('First function call sum(a,b):',sum(a,b))
print('First function call sum(r=5,q=1):',sum(r=5,q=1))
print("The value of Pi",math.pi) #Extended scope

Output

First function call sum(a,b): 105


First function call sum(r=5,q=1): 6
The value of Pi 3.141592653589793
Program-5
Creating a package and accessing two modules
from it

../
 Geometry Package
 area.py
 vol.py
 __init__.py
 Shape.py

area.py
def Cir(r):
'''Function for area of circle'''
print(__name__)#print current module name
return 3.14*r*r
def Rect(a,b):
return a*b

vol.py
def cuboid(l,b,h):
print(__name__)#print current module name
return l*b*h

__init__.py #this can be balnk

Shape.py
from geometry import area,vol
print(area.Cir(10)) # 314.0
print(help(area.Cir)) # function for area of circle
# print the doc string of function
print(area.Rect(10,20))
#200
print(vol.cuboid(10,20,5)) #10000
print(__name__) #print current module name
Output

3.14.0,200,1000
Program-6
Count number of lines in a text file
f=open("a.txt",'r')
line_count=0
for line in f:
line_count+=1
print("The number of lines in a.txt is:", line_count)

Output

The number of lines in a.txt is: 2


Program-7
Fibonacci Sequence
f=open("a.txt",'r')
word_count= 0
content= f.read()
word_lst= content.split( )
word_count= len(word_lst)
print("The number of words in poem.txt is : ",word_count)

Output

The number of word in a.txt is: 8


Program-8
Working with tell and seek function
f=open("a.txt",'w')
line='Welcome to KV Chhatarpur\n Regularly attend CS classes'
f.write(line)
f.close()
f=open("a.txt",'r+')
print((f.read(7)))
# read seven character
print(f.tell())
print(f.read())
print(f.tell())
f.seek(9,0)
# moves to 9 position from beginning
print(f.read(5))
f.close()

Output

0
Welcome
7
To Care English School
Regularly attend CS classes
54
O Ca
Program-9
Finding a character in a file and write it to another
file
file_inp=open('input.txt','r+')
for line in file_inp:
if 'a' in line:
file_out=open("output.txt",'a+')
file_out.write(line)
file_out.close( )
file_inp.close( )

Output
Program-10
Stack Implementation using list

def isEmpty(stk):
if stk==[]:
return True
else:
return False
def Push(stk,item):
stk.append(item)
top=len(stk)-1
def Pop(stk):
if isEmpty(stk):
return "Underflow"
else:
item=stk.pop()
if len(stk)==0:
Top=None
else:
top=len(stk)-1
return item
def Display(stk):
if isEmpty(stk):
print("Stack Empty")
else:
top=len(stk)-1
print(stk[top],"<--top")
for a in range(top-1,-1,-1):
print(stk[a])
#___main()____
Stack=[]
top=None
while True:
print("---Stack Operations---")
print("1. Push","2. Pop", "3. Display","4. Exit")
ch= int(input("Enter your choice(1-5):"))
if ch==1:
item=int(input("Enter item: "))
Push(Stack,item)
elif ch==2:
item=Pop(Stack)
if item=="Underflow":
print("Underflow :stack is empty")
else:
print("Popped item is",item)
elif ch==3:
Display(Stack)
elif ch==4:
break
else:
print("Please enter the correct number in range(1-5)")

Output
Program-11
SQL queries
1. show database;

create database if not exists xiia23;

use xiia23;

2. create table DEPT(

DCODE varchar(3) primary key,

DEPARTMENT varchar(5),

CITY varchar(12));

Output
0 rows affected

3. describe DEPT;

Output

4. create table WORKER(

WNO int(10) primary key,

NAME varchar(35),DOJ date,DOB date,

GENDER varchar(6), DCODE varchar(3) references\

DEPT(DCODE));

Output
0 rows affected
5. describe WORKER;

Output

6. insert into DEPT(DCODE,DEPARTMENT,CITY) values


(‘D01’,’MEDIA’,’Delhi’),
(‘D02’,’MARKETING’,’Delhi’),
(‘D03’,’INFRASTRUCTURE’,’Mumbai’),
(‘D04’,’FINANCE’,’Kolkata’),
(‘D05’,’HUMAN RESOURCE’,’Delhi’);

Output
5 rows affected

7. Display the details of all the departments

select * from DEPT;

Output

8. insert into WORKER values


(‘1001’,’George K’,’2013-09-02’,’1991-09-01’,’MALE’,’D01’),
(‘1002’,’Reema Sen’,’2012-12-11’,’1991-12-
15’,’FEMALE’,’D03’),
(‘1003’,’Mohitesh’,’2013-02-03’,’1987-09-04’,’MALE’,’D05’),
(‘1007’,’Anil Jha’,’2014-01-17’,’1984-10-19’,’MALE’,’D04’),
(‘1004’,’Manila Sahai’,’2012-12-09’,’1986-11-
14’,’FEMALE’,’D01’),
(‘1005’,’R Sahay’,’2013-11-18’,’1987-03-31’,’MALE’,’D02’),
(‘1001’,’Jaya Priya’,’2014–6-09’,’1985-06-
23’,’FEMALE’,’D05’),

Output
5 rows affected

9. Display all the details of the workers

select * from WORKER;

Output

10. Display all the details of the workers working in D01 Department

select * from WORKER where DCODE=’D01’;

Output

11. Display the female workers working in D05 Department

select * from WORKER where GENDER=’FEMALE’ and DCODE=’D05’;

Output
12. Display the workers name containing substring ‘ha’

select NAME from WORKER where NAME like ‘%ha%’;

Output

13. Display the details of the workers having birthday after 01.07.1990

select * from WORKER where DOB > ‘1990-07-01’;

Output

14. Display the details of the workers who have joined after 01.01.2013
and before 01.01.2014
select * from WORKER where DOJ between ‘2013-01-01’ and
‘2014-01-01’;

Output

15. Display the details of female workers in descending order of their


joining date
select * from WORKER where GENDER=’FEMALE’ order by DOJ desc;

Output
16. Display the names and worker number of the workers who live in
delhi
select NAME,WNO from WORKER W,DEPT D where W.DCODE=D>DCODE
and D.CITY=’Delhi’;

Output

17. Display the employees working in marketing deprtment

select NAME,WNO from WORKER W,DEPT D where W.DCODE=D>DCODE


and D.DEPARTMENT=’MARKETING’;

Output
Program-12
SQL queries
1. show databases;

create database if not exists xiia23;

use xiia23;

2. create table if not exist movie

No int(10) primary key,

Title varchar(30),

type varchar(30),

Rating varchar(15),

stars varchar(10),

qty int,

price float(10)

);

Output:

0 rows affected

3. describe movie;

Output:
4. insert into movie values

(1,"gone with wind ","drama","G","gable",4,39.95),

(2,"friday the 13th ","horror","R","jason",2,69.95),

(3,"top gun","drama","PG","cruise",7,49.95),

(4,"splash","comedy","PG13","hanks",3,29.95),

(5,"independence day ","drama","R","tumer",3,19.95),

(6,"risky business ","comedy","R","cruise",2,44.95),

(7,"cocoon ","scifi","PG","amecho",2,31.95),

(8,"crocodile dundee ","comedy","PG13","harris",2,69.95),

(9,"101 dalmatians ","comedy","G","",3,59.95),

(10,"tootsie ","comedy","PG","hoffman",1,29.95);

Output:

10 rows affected

5. Display a list of all movies with price over 20 & sorted by price

select * from movie where price>20 order by price;

Output:

6. Display all the movies sorted by qty in descending order

select * from movie order by qty desc;

Output:
7. Display a report using a movie number ,current value &
replacement value for each movie in the above table calculate the
replacement value for all movies as QTY*price*1.15
Select no, qty*price*1.15 as replacement_value from movie;

Output:

8. Display the count of different type of the movies


select count(distinct type) from movie;

Output:

9. Display the all stars available in movies


select distinct stars from movie;

Output:
Program-13
SQL queries
1. show databases;

create database if not exists xiia23;

use xiia23;

2. create table employee(

empno integer(5) primary key,

ename varchar(50) not null,

job varchar(100) not null,

mgr integer(5),

hiredate date,

sal decimal(6,2),

comm decimal(6,2),

deptno int(3)

);

Output:
0 rows affected

3. Display table structure

describe employee;

Output
4. Insert the values into table

insert into employee values

( 7369,'Smith','clerk',7902,'1980-12-17',800,NULL,20),

(7499,'Allen','salesman',7698,'1981-02-20',1600,300,30),

(7521,'Ward','salesman',7698,'1981-02-22',1250,500,30),

(7566,'Jones','manager',7839,'1981-04-02',2975,NULL,20),

(7654,'Martin','salesman',7698,'1981-09-28',1250,1400,30),

(7698,'Black','manager',7839,'1981-05-01',2850,NULL,30),

(7782,'Clark','manager',7839,'1981-06-09',2450,NULL,10),

(7788,'Scott','analyst',7566,'1981-04-19',3000,NULL,20),

29(7839,'King','precedent', NULL,'1981-11-09',5000,NULL,10),

(7844,'Turner','salesman',7688,'1981-09-08',1500,0,30),

(7876,'Adams','clerk',7788,'1987-05-23',1100,null,20),

(7900,'James','clerk',7698,'1981-12-03',950,null,30),

(7920,'Ford','analyst',7566,'1981-12-03',3000,null,20),

(7934,'Miller','clerk',7782,'1982-01-23',1300,null,10);

Output
14 rows affected

5. Display department wise s um of salary


SELECT SUM(sal) ,deptno FROM employee GROUP BY deptno;

Output

6. Display total salary given for each job profile


SELECT job,SUM(sal) FROM employee GROUP BY job;

Output
7. Display job wise salary sum min max average and count from
employee table
SELECT job,SUM(sal),AVG(sal),MAX(sal), COUNT(*) as employee_count
FROM employee group by job;

Output

8. Display department number 10 and 20 average salary


SELECT deptno,AVG(sal)FROM employee GROUP BY deptno HAVING
deptno IN (10,20);

Output

9. Display maximum ,minimum salary and number of employees in


each department if there are more than 2 employees
SELECT deptno,MAX(sal),MIN(sal),COUNT(*) FROM employee GROUP
BY deptno HAVING COUNT(*)>2;

Output

10. Display maximum and minimum salary in departments numbers 20


and 30
SELECT deptno,MAX(sal),MIN(sal)FROM employee WHERE sal>=2000
GROUP BY deptno HAVING deptno IN (20,30);

Output
Program-14
SQL queries
1. show databases;

create database if not exists xiia23;

use xiia23;

2. create table item(

itemno integer(5) primary key,

item varchar(50) NOT NULL,

dcode integer(5),

qty integer(5),

unitprice decimal(5,2),

stockdate date

);

Output
0 rows affected

3. insert into item values

(5004,'Ball Pen 0.5',102,100,16,'2018-03-10'),

(5003,'Ball Pen 0.25',102,150,20,'2017-05-17'),

(5002,'Gel Pen Premium',101,125,14,'2018-04-20'),

(5005,'Gel Pen Classic',101,200,22,'2018-10-08'),

(5001,'Eraser Small',102,210,5,'2018-03-11'),

(5006,'Eraser Big',102,60,10,'2017-11-18'),

(5007,'Sharpener Classic',NULL,160,8,'2017-06-12');

Output
7 rows affected
4. Select all record of table
Select * from item;

Output

5. Select ItemNo, name and Unitprice


select itemno, item, unitprice from item;

Output

6. Select all item record where Unitprice is more than 20


select * from item where unitprice > 20;

Output

7. Select Item name of those items which are quantity between 100-
200
select * from item where qty between 100 and 200;

Output
8. Select all record of Items which contains pen word in it
select * from item where item like '%pen%';

Output

9. Select unique dcode of all items


select distinct dcode from item;

Output

10. Display all record in the descending order of UnitPrice


select * from item order by unitprice desc;

Output
11. Display all items which are stocked in the month of March
select * from item where stockdate like '%03%';

Output

12. Change the unitprice to 20 for itemno 5005


update item set unitprice=20 where itemno=5005;

Output
1 row affected

13. Delete the record of itemno 5001


delete from item where itemno=5001;

Output
8 rows affected

14. Display all the item name in capital letters


select upper(item) from item;

Output

15. Display first 4 character of every item name


select substring(item,1,4) from item;

select left(item,4) from item;


Output

16. Display all record whose dcode is not assigned


select * from item where dcode is null;

Output
Program-15
SQL queries

1. show database;

create database if not exists xiia23;

use xiia23;

2. create table if not exists student1(

no int(10) primary key,

name varchar(15),

stipend float(30),

stream varchar(15),

avgmark float(10),

grade char(3),

class varchar(3));

Output
0 rows affected

3. describe student1;

Output
4. Display all student details

select * from student1;

Output

5. Display all non-medical stream students

select * from student1 where stream=”nonmedical”;

Output

6. Display class 12 students ordered by stipend

select Name from student1 where class like “12_” order by\
stipend;
Output

7. List all students stored by average marks in descending order

select * from student1 order avgmark desc;

Output
8. Display student details along with yearly stipend

select Name, stream, stipend, stipend*12 as yearly_stipend\


from student1 order;

Output

9. Display minimum and maximum average marks of the students

select min(avgmark),max(avgmark) from student1;

Output

10. Display the sum of stipend for students which get B grade

select sum(stipend) from student1 where grade=”B”;

Output
Program-16
Python to SQL database connectivity
import mysql.connector
from mysql.connector import Error

try:
global connection
Connection=\
mysql.connector.connect(host='localhost',database='mydatabase',\
user='root',password='care')
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor()
cursor.execute("select database();")
record = cursor.fetchone()
print("You're connected to database: ", record)
cursor.execute("select * from Student")
data = cursor.fetchall()
for i in data:
for j in i:
print(' \t|',j,end=" | ")
print()
except Error as e:
print("Error while connecting to MySQL", e)
finally:
if connection.is_connected():
cursor.close()
connection.close()
print("MySQL connection is closed")
Output
Connected to MySQL Server version 8.0.31-0ubuntu0.22.04.1
You're connected to database: ('mydatabase',)
| 1 | | Atharv Ahuja | | 2003-05-15 | | 444444444444 |
| 2 | | Daisy Bhutia | | 2002-02-28 | | 111111111111 |
| 3 | | Tahleem Shah | | 2002-02-28 | | 101010101010 |
MySQL connection is closed

You might also like