Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
27 views

Computer Science File

This document contains the practical file of a Class 12 student named Aayush Chandra Jha. It includes 20 questions on topics like functions, files, SQL, and databases. For each question, the student's input and output are listed. The file demonstrates the various programming concepts and problems the student has practiced.

Uploaded by

Zooper l
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Computer Science File

This document contains the practical file of a Class 12 student named Aayush Chandra Jha. It includes 20 questions on topics like functions, files, SQL, and databases. For each question, the student's input and output are listed. The file demonstrates the various programming concepts and problems the student has practiced.

Uploaded by

Zooper l
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

BAL BHAVAN PUBLIC SCHOOL

SESSION-2023-24

COMPUTER SCIENCE

PRACTICAL FILE

NAME- Aayush Chandra Jha

CLASS- XII-A

ROLL NO.- 34
Q.1 WAP to compute xn of given two integers x and n.

Ans- Input

Output
Q.2 WAP to print Fibonacci series up to a certain limit
using a user-defined module.
Ans- Input-

Output-
Q,3 Write a Program to find factorial of entered
number using user-defined module fact().
Ans- Input

Output
Q.4 WAP to accept a number, find and display whether
it’s an Armstrong number or not.
Ans- Input

Output
Q.5 WAP to accept a number and find out whether it is
a perfect number or not.
Ans- Input-

Output-
Q.6 WAP to print the following pattern:
1
12
123
1234
1 2 3 4 5.
Ans- Input-

Output-
Q.7 WAP that counts the number of alphabets and
digits, uppercase letters, lowercase letters, spaces and
other characters in the string entered.
Ans- Input-
Output-
Q.8 WAP to accept a string ( a sentence) and returns a
string having the first letter of each word in capital
letter.
Ans- Input-

Output-
Q.9 WAP to remove all odd numbers from the given
Index list.
Ans- Input-

Output-
Q.10 WAP to display cumulative elements of a given
list.
Ans- Input-

Output-
Q.11 WAP to display frequencies of all the elements of
a list.
Ans- Input-

Output-
Q.12 WAP to create a CSV file to store student
data(Rollno, Name, Marks). Obtain data from the user
and write 5 records into file.
Ans- Input-
Output-
Q.13 Write a function in Python to count the number of
lines in a text file “STORY.TXT” which is starting with
an alphabet ‘A’.
Ans- Input-

Output-
Q.14 Write a function that reads a text file and prints
only the numbers or digits from the file.
Ans- Input-

Output-
Q.15 Write a function that copies a text file source.txt
onto target.txt barring the lines starting with ‘a’.
Ans- Input-

Output-
Q.16 A binary file “Book.dat” has structure
[bookno.,Book_name, Author, Price].
Write a menu driven program.
a. To write a function CreateFile() to input data and
add in Book.dat.
b. To write a function CountRec(Author) in python
which accepts the Author name as parameter and
counts and returns the number of books by the given
Author are stored in the binary file.
c. To write a function to update the price of a book
having bookno. passed as parameter Update(bookno.).
Ans- Input-
Output-
Q.17 A csv file teacher.csv contains details (Teacherid,
Teachername, subjects taught and salary) and write a
menu driven python program a. To take input from the
user and add records in the csv file. b. To update the
salary of a teacher.
Ans- Input-
Output-
Q.18 Write a menu based program to Maintaining
Book details like bcode, btitle and price using stacks in
python. Write functions to perform push, pop and
display methods.
Ans- Input-
Output-
Q.19 Write a menu based program to add, delete and
display the record of a hostel using a list as stack data
structure in python. Record of the hostel contains the
fields :Hostel number, Total Students and Total Rooms.
Ans- Input-
Output-
Q.20 Create the following tables.

Write the command and find the output of the


following commands:-
Write the SQL query for questions from (i) to (iv) &
write the output of SQL command for questions from
(v) to (viii) given below:-
a. Display the Mobile company, name & price .
b. Display the Mobile supplier & quantity of all
mobiles OF M_Id= MB003.
c. List showing the name of mobile company having
price between 3000 & 5000,
d. SELECT M_Id, SUM(M_Qty) FROM MobileStock
GROUP BY M_Id; e. SELECT AVG(M_Price) FROM
MobileMaster;
Ans- Input-
(a)
SELECT M_Company, M_Name, M_Price
FROM MobileMaster;
(b)
SELECT M_Supplier, M_Qty
FROM MobileStock
WHERE M_Id = 'MB003';
(c)
SELECT M_Company
FROM MobileMaster
WHERE M_Price BETWEEN 3000 AND 5000;
(d)
SELECT M_Id, SUM(M_Qty)
FROM MobileStock
GROUP BY M_Id;
(e)
SELECT AVG(M_Price)
FROM MobileMaster;
Q.21 Create the following tables. Write the command
and find the output of the following commands:-

a. To display the watch's name and price of those


watches which have a price range in between
5000-15000.
b. To display total quantity in store IN watches
c. To display watch names and their quantity sold in
the first quarter. v. select max(price), min(qty_store)
from watches;
d. select quarter, sum(qty_sold) from sale group by
quarter.
Ans- a. To display the watch's name and price of those watches
which have a price range between 5000 and 15000.
SELECT Watch_Name, Watch_Price
FROM Watches
WHERE Watch_Price BETWEEN 5000 AND 15000;

B. To display the total quantity in store for watches.

SELECT SUM(Qty_Store) AS Total_Quantity_In_Store


FROM Watches;

C. To display watch names and their quantity sold in the first


quarter.

SELECT W.Watch_Name, S.Qty_Sold


FROM Watches W
JOIN Sale S ON W.Watch_Id = S.Watch_Id
WHERE S.Quarter = 1;

D. To display the quarter and the sum of quantities sold from the
Sale table.

SELECT Quarter, SUM(Qty_Sold) AS Total_Quantity_Sold


FROM Sale
GROUP BY Quarter;
22. Create the following tables. Write the command
and find the output of the following commands:-

a. Display the Trainer Name, City & Salary in


descending order of their Hiredate.
b. To display the TNAME and CITY of Trainer who
joined the Institute in the month of December 2001
c. SELECT COUNT(*), SUM(FEES) FROM
COURSE WHERE STARTDATE< ‘2018-09-15’;
d. SELECT TID, COUNT(*), MIN(FEES) FROM
COURSE GROUP BY TID HAVING COUNT(*)>1;
e. To display the number of Trainers from each city.
Ans-

a. Display the Trainer Name, City & Salary in


descending order of their Hiredate.

SELECT Trainer_Name, City, Salary

FROM Trainer

ORDER BY Hiredate DESC;

b. To display the TNAME and CITY of Trainer who


joined the Institute in the month of December 2001.

SELECT Trainer_Name, City

FROM Trainer

WHERE MONTH(Hiredate) = 12 AND


YEAR(Hiredate) = 2001;
c. SELECT COUNT(*), SUM(FEES) FROM COURSE
WHERE STARTDATE < '2018-09-15';

SELECT COUNT(*), SUM(FEES)

FROM COURSE

WHERE STARTDATE < '2018-09-15';

d. SELECT TID, COUNT(), MIN(FEES) FROM


COURSE GROUP BY TID HAVING COUNT() > 1;

SELECT TID, COUNT(*), MIN(FEES)

FROM COURSE

GROUP BY TID

HAVING COUNT(*) > 1;


e. To display the number of Trainers from each
city.

SELECT City, COUNT(*) AS Trainer_Count

FROM Trainer

GROUP BY City;
23. Create the following tables and find the output of
the following commands:-

(i) SELECT COUNT(*), City FROM STUDENT


GROUP BY CITY HAVING COUNT(*)>1;
(ii) SELECT MAX(DOB),MIN(DOB) FROM
STUDENT;
(iii) SELECT NAME,GENDER FROM STUDENT
WHERE CITY=”Delhi”;
Ans-
(i) To count the number of students in each city where
the count is greater than 1:
SELECT COUNT(*), City
FROM STUDENT
GROUP BY CITY
HAVING COUNT(*) > 1;
(ii) To find the maximum and minimum date of birth
(DOB) among all students:
SELECT MAX(DOB) AS Max_DOB, MIN(DOB) AS
Min_DOB
FROM STUDENT;

(iii) To select the name and gender of students from the


city of Delhi:
SELECT NAME, GENDER
FROM STUDENT
WHERE CITY = 'Delhi';
24. Create the following tables and find the output of
the following commands:-

a. SELECT Department, count(*) FROM Teacher


GROUP BY Department;
b. SELECT Max(Date_of_Join),Min(Date_of_Join)
FROM Teacher
c. SELECT Teacher.name,Teacher.Department,
Posting.Place FROM Teacher, Posting WHERE
Teacher.Department = Posting.Department AND
Posting.Place=”Delhi”;
Ans-
a. To count the number of teachers in each department:
SELECT Department, COUNT(*) AS Teacher_Count
FROM Teacher
GROUP BY Department;

b. To find the maximum and minimum date of join


(Date_of_Join) among all teachers:
SELECT MAX(Date_of_Join) AS Max_Date_of_Join,
MIN(Date_of_Join) AS Min_Date_of_Join
FROM Teacher;

c. To select the name, department, and posting place of


teachers for those who are in the department with
postings in Delhi:
SELECT Teacher.name, Teacher.Department,
Posting.Place
FROM Teacher
JOIN Posting ON Teacher.Department =
Posting.Department
WHERE Posting.Place = 'Delhi';
25. Create the following tables. Write the command
and find the output of the following commands:-

(i) To display details of those Faculties whose salary is


greater than 12000.
(ii) To display the details of courses whose fees are in
the range of 15000 to 50000 (both values included).
(iii) AVG fee from COURSES
(iv) To increase the fees of all courses by 500 of
“System Design” courses.
(v) Min fee from the COURSES.
Ans-
(i) To display details of those faculties whose salary is greater
than 12000:
SELECT *
FROM Faculties
WHERE Salary > 12000;
(ii) To display the details of courses whose fees are in the range
of 15000 to 50000 (both values included):
SELECT *
FROM Courses
WHERE Fees BETWEEN 15000 AND 50000;

(iii) To calculate the average fee from the Courses table:


SELECT AVG(Fees) AS Avg_Fee
FROM Courses;

(iv) To increase the fees of all courses by 500 for the "System
Design" course:
UPDATE Courses
SET Fees = Fees + 500
WHERE Course_Name = 'System Design';

(v)
To find the minimum fee from the Courses table:
SELECT MIN(Fees) AS Min_Fee
FROM Courses;
26. Create the following tables. Write the command
and find the output of the following commands:-

(a) Identify the attribute best suitable to be declared as


a primary key.
(b) Insert the following data into the attributes ItemNo,
ItemName and Scode respectively in the given table
STORE. ItemNo = 2010, ItemName = ‘Note Book’ and
Scode = 25
(c) Abhay wants to remove the table STORE from the
database MyStore. Which command will he use from
the following:
a) DELETE FROM store;
b) DROP TABLE store;
c) DROP DATABASE mystore;
d) DELETE store FROM mystore;
(d) Now Abhay wants to display the structure of the
table STORE, i.e name of the attributes and their
respective data types that he has used in the table.
Write the query to display the same.
Ans- (a) To identify the attribute best suitable to be declared as a
primary key, you typically look for a unique identifier for each
record. Commonly, attributes like "ItemNo" or any attribute that
uniquely identifies each item could be suitable.

(b) To insert the given data into the attributes ItemNo,


ItemName, and Scode in the table STORE:

INSERT INTO STORE (ItemNo, ItemName, Scode)


VALUES (2010, 'Note Book', 25);

(c) To remove the table STORE from the database MyStore,


Abhay would use the following command:

DROP TABLE STORE;


So, the correct option is:
b) DROP TABLE store;
(d) To display the structure of the table STORE:
SHOW COLUMNS FROM STORE;
27. Write a complete menu driven Python MySql Connectivity
program
1. Write a function to create a database Employee.
2. Write a function to open database Employee.
3. Write a function to create following Table name empl.

4. Write a function to input data from the user and insert records
in the table.
5. Write a function to display all the records from table empl.
6. Write a function to update the employee record of entered
empno.
7. Write a function to search employee number in table
employee and display record, if empno not found display
appropriate message.
8. Write a function to delete the employee record of entered
empno.
Ans-

You might also like