0% found this document useful (0 votes)
12 views

ST ANDREWS PUBLIC SCHOOL CS

Uploaded by

nightmayorsharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

ST ANDREWS PUBLIC SCHOOL CS

Uploaded by

nightmayorsharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

ST ANDREWS PUBLIC SCHOOL

Affilated to C.B.S.E. New Delhi


A.I.S.S.C.E

SESSION=2024-25

Subject- Computer Science Subject Code:083

A Report File
On
The Text File , Binary File , CSV File , SQL
Queries

Subimitted by-Lavkush Tyagi Submitted to-Mr Vikas Goyal


CERTIFICATE

The is to certify that Lavkush Tyagi of Class XII Science of St.


Andrews Public School,Kamla Nagar Agra has completed his
file under my supervision on The Report file on Text File,
Binary File etc..He has taken Proper care and shown utmost
sincerity in completion of this project .I certify that this
project Is upto my exceptation And as per the guidelines
issued by C.B.S.E. during year 2024-25

Examiner Signature- Teacher Signature-


ACKNOWLEDGEMENT

I would like to express my greatest gratitude


to all those who directly or indirectly helped
and supported me throughout the project.
Firstly, I am highly indebted to my Computer
Science Teacher Mr Vikas Goyal for his
guidance and constant supervision as well as
for providing necessary information regarding
the project. I would also like to extend my
gratitude to our principal for giving me a
chance to work on this project.
Finally, I would like to thank my parents,
friends & team members for their continued
support and coordination in this project
INDEX

S NO. TOPIC
1. Binary File

2. Text File

3. CSV Files

4. SQL Queries

5. SQL Connectivity
PHYTHON PROGRAMS
1. write a function that take two no and returns
the number that has minimum ones digit.

Coding

output:
2. write a function namely nth root () that
receives two parameters x and n and returns nth
root of x I.e x*l/n The default value of n is 2.

Coding

output:
3. write a method that take a filename and display
the longest line from the file.

Coding

output:
4. write a method that take file name with
extensions and create a new file in which line
that begins with capita/ are inserted.

Coding

output:
Let us consider using this file Poem.Txt
there will be some following programs:
5. write a program that print the line of text file
poem. txt with line no.

Coding

output:
6. write a program that print the data from csv file in
the form of table.

Coding

output:
7. write a program that read a text file and creates
another file that is identical except that every
sequence of consecutive blank spaces is replaced by
a single space.

Coding

output:
8. write a method disp/aywords() in python to read
the lines from poem. txt and display those words
which are less than 4 characters.

Coding

output:
9.write a program that count no of to and To
present in poem. txt

Coding

output:
10. write a program to create a csv file op. csv
containing s.no,name,age.

Coding:

Output:

Op. csv:
11.Write a program to implement stack to enter
marks of students and perform push and display
operator with the help of stack.

Coding:

Output:
12. write a program to implement stack to
perform push and display operation. The stack
contain rollno and marks of student.

Coding:

Output:
13. write a program to implement stack that
contains the information of book details ,book
no,book name to perform pop and display
operations.

Coding:

Output:
14.write a program to implement stack to perform
push and pop operation . The stack contain the
information of employ (id,name,posts).

Coding:

Output
15. write a program with the help of stack
of even no with 70 elements input only
those element which are divisible by 2. Just
implement push and display options.

Coding:

Output
SQL Query regarding Table
• 1. From the following tables, write a SQL query to find the
salespeople and customers who live in the same city. Return
customer name, salesperson name and salesperson city.

• Sample table: salesman


Salesman Id Name City Commission
5001 James Wong New York 0.15
5002 Nail Knite Paris 0.13
5005 Pit Alex London 0.11
5006 Mc Lyon Paris 0.14
5007 Paul Adam Rome 0.13
5003 Lauson Hen San Jose 0.12

• Sample table: customer

customer_id cust_name city grade salesman_id


3002 Nick New york 100 5001
Rimando
3007 Brad Davis New york 200 5001
3005 Graham Zusi California 200 5002
3008 Julian Green London 300 5002
3004 Fabian Paris 300 5006
Johnsson
3009 Geoff Berlin 100 5003
Cameron
3003 Jozy Altidor Moscow 200 5007
3001 Brad Guzan London 200 5005
Sample Output: 1
cust_name name city
Nick Rimando James Hoog New York
Brad Davis James Hoog New York
Julian Green Pit Alex London
Fabian Johnson Mc Lyon Paris
Fabian Johnson Nail Knite Paris
Brad Guzan Pit Alex London

Queries Set 2 (Database Fetching records)


ProductionCos
Movie_ID MovieName Type ReleaseDate BusinessCost
t

The Kashmir
M001 Action 2022/01/26 1245000 1300000
Files

M002 Attack Action 2022/01/28 1120000 1250000

M003 Looop Lapeta Thriller 2022/02/01 250000 300000

M004 Badhai Do Drama 2022/02/04 720000 68000

Shabaash
M005 Biography 2022/02/04 1000000 800000
Mithu

M006 Gehraiyaan Romance 2022/02/11 150000 120000

Display all information from movie.


Display the type of movies.
Display movie id, 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.
Display movie id, movie name and production cost for all movies
with production cost greater that 150000 and less than 1000000.
Display the movie of type action and romance.
Display the list of movies which are going to release in February,
2022.
[1] select * from movie;

Output:

2. select distinct from a movie;

3. select movie id, movie name,


production cost + business cost
“total earning” from movie;
4. select movie_id, moviename, production cost from movie where
product is >150000 and <1000000;

5. select movie name from movie where type =’action’ or


type=’romance’;
6. select movie name from moview where month(release date)=2;

Queries Set 3 (Based on Functions)

. Write a query to display cube of 5.


. Write a query to display the number 563.854741 rounding off to the
next hnudred.
. Write a query to display “put” from the word “Computer”.
. Write a query to display today’s date into DD.MM.YYYY format.
. Write a query to display ‘DIA’ from the word “MEDIA”.

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);

Queries set 4 (Based on Two Tables)

1. Display the match id, team id, team score who scored more than
70 in first inning along with team name.
2. Display match id, team name and second team score between
100 to 160.
3. Display match id, team names along with match dates.
4. Display unique team names
5. Display match id and match date played by Aadhi and Shailab.

Answers:

[1] select match_details.match id, match_details.first teamid, team.


team name,match_details.first team score from match_details, team
where match_details.first team id=team.team id and match_details.
first teamscore>70;
[2] select match id, team name, second teamscore from
match_details, team where match_details.secondteamid=team.teamid
and match_details. second team score between 100 and 160;

[3] select match id,team name,first teamid ,second team id,match


date from match_details, team where match_details.first
teamid=team.teamid;
[4] select distinct (team name) from match_details, team where
match_details.first teamid=team.teamid;

[5] select match id,matchdate from match_details, team where


match_details.first teamid=team.team id and team.team name in
(‘Aandhi’,’Shailab’);
Queries Set 5 (Group by , Order By)

Consider the following table stock table to answer the queries:

itemno item dcode qty unitprice stockdate

S005 Ballpen 102 100 10 2018/04/22

S003 Gel Pen 101 150 15 2018/03/18

S002 Pencil 102 125 5 2018/02/25

S006 Eraser 101 200 3 2018/01/12

S001 Sharpner 103 210 5 2018/06/11

S004 Compass 102 60 35 2018/05/10

S009 A4 Papers 102 160 5 2018/07/17

. Display all the items in the ascending order of stock date.


. Display maximum price of items for each dealer individually as per
dcode from stock.
. Display all the items in descending orders of item names.
. Display average price of items for each dealer individually as per
doce from stock which avergae price is more than 5.
. Display the sum of quantity for each dcode.

Answers:

[1] select * from stock order by stockdate;


[2] select dcode,max(unit price) from stock group by
code

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


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

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


SQL Database Connectivity 2 Programs

PROGRAM 1: Write a program to connect python with my sql


using database connectivity and perform the following
operations in database: A)Create the table B) Insert the records
C) Display the records using fetchall function [table name is
student]
SOURCE CODE:
import mysql.connector
Mycon=mysql.connector.connect(
host='localhost’,
user='root’,
password='password’,
database='School’) if mycon.
is_connected():
print('Database connected’)
cursor = mycon.cursor()
sql=‘‘’
CREATE TABLE IF NOT EXISTS STUDENT (
ID INT PRIMARY KEY,
Name CHAR(10),
Stream CHAR(10) , AvgMark FLOAT,
Grade CHAR(2),
Class CHAR(5))'‘’
cursor.execute(sql)
Sql=‘‘’
INSERT INTO STUDENT (ID, Name, Stream, AvgMark, Grade,
Class) VALUES
(1, 'Karan', 'Medical', 78.5, 'B', '128’),
(2, 'Divakar', 'Commerce', 89.2, 'A', '11C’) , (3, 'Divya', 'Commerce',
68.6, 'C', '12C’), (4, 'Arun',
'Computers', 89.9, 'A', '12A’),
(5, 'Sabina', 'Medical', 83.3, 'B', '128') ’‘’
cursor.execute(sql)
# Commit the changes
mycon.commit()
# Retrieve and display records
cursor.execute
('SELECT * FROM STUDENT’)
data = cursor.fetchall()
for recin data:
print(rec)
# Close the connection
mycon.close()

OUTPUT:

PROGRAM 2:
Write a program to connect python with mysql using
database connectivity and perform the following
operations in database:
a) Display all the records of students who are in Medical
stream
b) b) Change the Class of Divakar to 12C
c) c) Display the maximum mark of 12B students
SOURCE CODE:

import mysql.connector
# Establish a connection to the MySQL server
mycon=mysql.connector.connect(
host='localhost’,
user='root’,
password='password’,
database='School')
if mycon.is_connected():
print('Database connected')
cursor = mycon.cursor()
# a) Display all the records of students who are in the
Medicalstream
sql ="SELECT * FROM STUDENT WHERE Stream='Medical’”
cursor.execute(sql)
records =.fetchall()
print("Answer for a):")
for recin records.
print(rec)
# b) Change the Class of Divakar to 12C
sql = "UPDATE STUDENT SET Class='12C' WHERE
Name='Divakar’”
cursor.execute(sql)
mycon.commit()
print("Record Updated")

# c) Display the maximum mark of students in class 12


sql ="SELECT MAX(AvgMark) FROM STUDENT WHERE
Class='12’”
cursor.execute(sql)
max_mark = cursor.fetchone()[0]
print("Answer for c):")
print("The maximum mark in class 12 is: {max_mark}")
# Close the connection
mycon.close()
OUTPUT:

PROGRAM 3: Write a program to connect python with mysql


using database connecvity andperform the following
operaons in database:

a) Display all the records of students in


the ascending order of Name of the
student
b) b) Display the number of records
whose name starts with D
c) c) Delete the record whose ID is 3
SOURCE CODE:
import mysql.connector
# Establish a connection to the MySQL server
mycon=mysql.connector.connect(
host='localhost’,
user='root’,
password='password’,
database='School')
if mycon.is_connected():
print('Database connected’)
# Create a cursor object
cursor = mycon.cursor()
# a) Display all the records of students in ascending order of Name
sql ="SELECT * FROM STUDENT ORDER BY Name“
cursor.execute(sql)
data = cursor.fetchall()
print("Answer for a):")
for rec in data:
print(rec)
# b) Display the number of records whose name starts with 'D’
sql ="SELECT COUNT(*) FROM STUDENT WHERE Name LIKE
'D%’”
cursor.execute(sql)
count = cursor.fetchone()[0]
print("The number of records whose name starts with 'D' is{count}")
# c) Delete the record whose ID is 3
sql ="DELETE FROM STUDENT WHERE ID = 3“
cursor.execute(sql)
mycon.commit()
print("Record Deleted")
# Close the connection
mycon.close()
OUTPUT:
PROGRAM 4: Write a program to connect python with mysql
using database connectivity and perform the following
operations in database:

a) Count the number of records in


each stream and display it
b) Display the number of students who
have secured ‘A’ Grade
c) Add a new column called Rank in the
table

SOURCE CODE:
import mysql.connector
# Establish a connection to the MySQL server
mycon=mysql.connector.connect(
host='localhost’,
user='root’,
password='password’,
database='School’)
if mycon.is_connected():
print('Database connected’)
# Create a cursor object
cursor = mycon.cursor()
# a) Count the number of records in each stream and display it
sql ='SELECT Stream, COUNT(*) FROM STUDENT GROUP BY
Stream’
cursor.execute(sql)
data = cursor.fetchall()
print("Answer for a):")
for recin data:
print(rec)
# b) Display the number of students who have secured 'A' Grade
sql ="SELECT COUNT(*) FROM STUDENT WHERE Grade='A’”
cursor.execute(sql)
count = cursor.fetchone()[0]
print("The number of students with 'A' grade is {count}")
# c) Add a new column called Rank in the table.
sql ='ALTER TABLE STUDENT ADD Rank CHAR(3)’
cursor.execute(sql)
mycon.commit()
print('Field Added’)
# Close the connection
mycon.close()

OUTPUT

You might also like