XII CS ALL Chapters Questions
XII CS ALL Chapters Questions
8. Roshni of class 12 is writing a program in Python for her project work to create a CSV file “Teachers.csv”
which will contain information for every teacher’s identification Number , Name for some entries.She
has written the following code.However, she is unable to figure out the correct statements in few lines of
code,hence she has left them blank. Help her write the statements correctly for the missing parts in the
code.
Unit-1: Data Structures – Stack (Questions)
Multiple Choice Questions
1. Which end we use in stack to perform Push and Pop operation?
A. Front B. Rear C. Top D. Sop
2. Which principle followed by Stack?
A. FIFO B. LIFO C. FIOF D. TIPO
3. Which operation take place by stack?
A. Push B. Pop C. Traversal D. All of these
4. Which method we use to add an element in stack using list?
A. insert B. append C. add D. None of these
5. When we delete an element, the value of top will be
A. increment B. decrement C. Both A&B D. None of these
6. Process of inserting an element in stack is called _____________
a) Create b) Push c) Evaluation d) Pop
7. Process of removing an element from stack is called
a) Create b) Push c) Evaluation d) Pop
8. In a stack, if a user tries to remove an element from empty stack it is called _____________
a) Underflow b) Empty collection c) Overflow d) Garbage Collection
9. Pushing an element into stack already having five elements and stack size of 5, then stack becomes
a) Overflow b) Crash c) Underflow d) Userflow
10. Entries in a stack are “ordered”. What is the meaning of this statement?
a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<’ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one
11. Which of the following applications may use a stack?
a) A parenthesis balancing program b) Tracking of local variables at runtime
c)Compiler Syntax Analyzer d) All of the mentioned
12. Sanya wants to remove an element from empty stack. Which of the following term is related to this?
(a) Empty Stack (b) Overflow (c) Underflow (d) Clear Stack
13. TRUE/FALSE:
1.LIFO stands for Last in First Out. (TRUE)
2. Can we perform Pop operation if stack is empty. (FALSE)
3. if size of stack is 5 can we Push 6 element in stack. (FALSE)
4. len() method used to find the size of stack. (TRUE)
5. Stack is a linear data structure. (TRUE)
Assertion Reason Questions
A. Both assertion and reason are true, and the reason is the correct explanation of the assertion.
B. Both assertion and reason are true, but the reason is not the correct explanation of the assertion.
C. Assertion is true, but the reason is false.
D. Assertion is false, but the reason is true.
1. ASSERTION (A): Using append(), many elements can be added at a time.
REASON(R): For adding more than one element, extend() method can be used. (D)
2. ASSERTION (A): LIFO is a technique to access data from queues.
REASON(R): LIFO stands for Last In First Out. (D)
3. ASSERTION (A): A Stack is a Linear Data Structure, that stores the elements in FIFO order.
REASON(R): New element is added at one end and element is removed from that end only. (D)
4. ASSERTION (A): An error occurs when one tries to delete an element from an empty stack.
REASON(R): This situation is called an Inspection. (C)
5. ASSERTION (A): A stack is a LIFO structure.
REASON (R): Any new element pushed into the stack always gets positioned at the index after the last
existing element in the stack. (B)
SENIOR JUNIOR
HOSTEL ADMIN
Answer 1:
(i)
(ii) Server can be placed in the ADMIN building as it has the maxium number of computer.
(iii) Repeater can be placed between ADMIN
and SENIOR building as the distance is more than 110 m.
(iv) Radiowaves can be used in hilly regions as they can travel through obstacles.
Question 2:
Good Marks Public School in Shimla is setting up the network between its different wings. There
are 4 wings named as SENIOR(S), JUNIOR(J), ADMIN(A) and HOSTEL(H).
Distance between various wings: Number of Computers in each Wing
(i)
(ii) Server should be in Wing S as it has the maxi-mum number of computers.
(iii) All Wings need hub/switch as it has more thanone computer.
(iv) Since the distance is more, wireless transmission would be better. Radiowaves are reliable
and can travel through obstacles.
Question 3:
Star Info Solution is a professional consultancy company. The company is planning to set up their
new offices in India with its hub at Jaipur. As a network adviser, you have to understand their
requirement and suggest them the best available solutions. Their queries are mentioned as (i) to
(iv) below.
Physical Locations of the blocked of Company
(i) What will be the most appropriate block, where company should plan to install their
server?
(ii) Draw a block to cable layout to connect all the buildings in the most appropriate manner for
efficient communication.
(iii) What will be the best possible connectivity out of the following, you will suggest to connect
the new setup of offices in Bangalore with its London based office:
o Satellite Link
o Infrared
o Ethernet Cable
(iv) Which of the following device will be suggested by you to connect each computer in each of
the buildings:
o Switch
o Modem
o Gateway
Answer 3:
(ii)
(iii) Satellite link
(iv) Switch
Question 4:
Rehaana Medicos Center has set up its new center in Dubai. It has four buildings as shown in the
diagram given below:
Accounts Research Packaging Store
LAb Unit
As a network expert, provide the best possible answer for the following queries:
(i) Suggest a cable layout of connections between the buildings.
(ii) Suggest the most suitable place (i.e. building) to house the server of this organization.
(iii) Suggest the placement of the following device with justification:
(iv) Repeater (b) Hub/Switch
(v) Suggest a system (hardware/software) to prevent unauthorized access to or from the
network.
Answer 4:
(i) Layout 1
(ii) The most suitable place / building to house the server of this organization would be building
Research Lab, as this building contains the maximum number of computers.
(iii) Since the cabling distance between Accounts to Store is quite large, so a repeater would
ideally be needed along their path to avoid loss of signals during the course of data flow in
this route.
(iv) Firewall.
Question 5:
1. Expert Professional Global (EPG) is an online, corporate training provider company for IT
related courses. The company is setting up their new campus in Mumbai. You as a network
expert have to study the physical locations of various buildings and the number of
computers to be installed. In the planning phase, provide the best possible answer for the
(i) Suggest the most appropriate building, where EPG should plan to install the server.
(ii) Suggest the most appropriate building to building cable layout to connect all three buildings
for efficient communication.
(iii) Which type of network out of the following is formed by connecting the computers of these
three buildings?
o LAN
o MAN
o WAN
(iv) Which wireless channel out of the following should be opted by EPG to connect to students
of all over the world?
o Infrared
o Microwave
o Satellite
nswer 5:
(i) Faculty Studio Building
(ii) Bus Topology
(iii) LAN
(iv) Satellite
Question 6:
“Learn India” is a skill development community which has an aim to promote the standard of skills
in the society. It is planning to set up its training centres in multiple towns and villages Pan India
with its head offices in the nearest cities. They have created a model of their network with a city
ABC Nagar, a town (UVW town) and 3 villages.
As a network consultant, you have to suggest the best network related solutions for their issues/
problems raised in (i) to (iv), keeping in mind the distances between various locations and other
given parameters.
Note:
– In Villagers, there are community centers, in which one room has been given as training entrer
to this organization to install computers.
– The organization has got financial support from the government and top Multinational Organi-
zations.
(i) Suggest the most appropriate location of the SERVER in the Cluster (out of the 4 locations),
to get the best and effective connectivity. Justify your answer.
(ii) Suggest the best wired medium and draw the cable layout (location to location) to efficiently
connect various locations within the Cluster.
(iii) Which hardware device will you suggest to connect all the computers within each location of
(iv) Which service/protocol will be most helpful to conduct live interactions of Expersts from
Head Office and peole at all locations of Cluster?
Answer 6:
(i) Best location for the server is UVW-TOWN, because it is approximately equidistant from
the village P, Q and R.
(ii) For connectivity between UVW-TOWN to head office is optic Fiber and to connect the
villages, P, Q and R with server at UVW- TOWN is co-axial cable.
(iii) The villages R Q and R can be connected with server at UVW-TOWN by a Hub and the head
office is connected by a Bus topology.
(iv) Between head office and UVWTOWN
we recommend for Bus topology, so HTTP protocol and other terminal can be connected by
UDP or FTP protocols.
Question 7:
Raj IT Solutions located in the hilly area of Nanital. The companies are located in four different,
blocks whose layout is shown in the following figure. Answer the questions (i) to (iv) with the
relevant justifi-cations.
Block A to Block C 50 m
Wing Number of
Block A to Block D 100 m
Computers
Block B to Block C 40 m
Block A 25
Block B to Block D 70 m
Block B 50
Block C to Block D 125 m
Block C 20
Block A to Block B 75 m
-
Block D 120
(i) Suggest a suitable network topology between the blocks.
(ii) Which is the most suitable block to house the server of this organization?
(iii) Suggest the placement of the following devices with justification
o Repeater
o Switch
(iv) The organization is planning to link the whole blocks to its marketing Office in Delhi. Since
cable connection is not possible from Shimla, suggest a way to connect it with high speed.
Answer 7:
(i) Suitable topology is bus topology.
(ii) The most suitable block for hosting server is BLOCK-D because this block has maximumnumber
of computers.
(iii) Switch is a device used to segment network into different sub-networks so switch will existin all the
blocks. Since distance between BLOCK-D and BLOCK-C is large so repeater will beinstall between
BLOCK-D and BLOCK-C.
(iv) The most economic way to connect it with a reasonable high speed would be the use radiowave
transmission, as they are easy to install, can travel long distance and penetrate buildings easily, so
they are used for communication, both indoors and outdoors. Radiowaves also have the
advantage of being omni-directional. They can travel in all the directions from the source, so that
the transmitter and receiver do not have to be carefullyaligned physically.
Question 8:
Zigma Institute is planning to set up its center in Bikaner with four specialized blocks for Medicine,
Management, Law courses along with an Admission block in separate buildings. The physical
distances between these blocks and the number of computers to be installed in these blocks are
given below. You as a network expert have to answer the queries raised by their board of directors
as given in (i) to (iv).
(i). Suggest the most suitable location to install the main server of this institution to get efficient
connectivity.
(ii). Suggest by drawing the best cable layout for effective network connectivity of the blocks
having server with all the other blocks.
(iii). Suggest the devices to be installed in each of these buildings for connecting computers
installed within the building out of the following:
• Modem
• Switch
• Gateway
• Router
(iv) Suggest the most suitable wired medium for efficiently connecting each computer installed in
every building out of the following network cables:
• Coaxial Cable
• Ethernet Cable
• Single Pair
• Telephone Cable.
Answer 8:
i) Admin Block
(ii)
(iii) Modem or Switch or Router
(iv)Ethernet Cable
Question 9:
Knowledge Supplement Organisation has set up its new centre at Mangalore for its office and web
based activities. It has 4 blocks of buildings as shown in the diagram below:
Block
C
Block Block
A
D
Block
(ii) The most suitable place / block to house the server of this organisation would be Block C, as
this block contains the maximum number of computers, thus decreasing the cabling cost for most
of the computers as well as increasing the efficiency of the maximum computers in the network.
(iii) (a) For Layout 1, since the cabling distance between Blocks A and C, and that between B and
C are quite large, so a repeater each, would ideally be needed along their path to avoid loss of signals
during the course of data flow in these routes.
(b) A hub/switch each would be needed in all the blocks, to interconnect the group of cables from
the different computers in each block.
(iv)The most economical way to connect it with a reasonable high speed would be to use radio wave
transmission, as they are easy to install, can travel long distances, and penetrate buildings easily, so
they are widely used for communication, both indoors and outdoors. Radio waves also have the
advantage of being omni directional, which is they can travel in all the directions from the source,
so that the transmitter and receiver do not have to be carefully aligned physically.
Question 10:
Gyan Vidya Bharti in Srinagar is setting up the network between its different wings. There are 4
wings named as SENIOR(S), MIDDLE(M), JUNIOR(J) and OFFICE(O).
Distance between the various wings are given below: Number of Computers
Ans10:
• Star or Bus or any other valid topology.
• Wing S, because maximum number of computers are located at Wing S.
• Hub/ Switch in all the wings.
• Coaxial cable/Modem/LAN/TCP-IP/Dialup/DSL/Leased Lines or any other
validtechnology.
Unit-3: Database concepts and the Structured Query Language
Database: A database is a collection of DATA/INFORMATION that is organized so that it can be easily accessed,
managed and updated. In Database, Data is organized into rows, columns and tables.
Relational Database: A relational database is a collective set of multiple data sets organized by tables, records and
columns. A Relational database use Structured Query Language (SQL), which is a standard user application that
provides an easy programming interface for database interaction.
Relation (Table) - A Relation or Table is Matrix like structure arranged in Rows and Columns.
Domain - It is collection of values from which the value is derived for a column.
Tuple / Entity / Record - Rows of a table is called Tuple or Record.
Cardinality - Number of rows (Records) in a table.
Attribute/ Field - Column of a table is called Attribute or Field.
Degree - Number of columns (attributes) in a table.
KEYS IN A DATABASE: Key plays an important role in relational database; it is used for identifying unique rows from
table & establishes relationship among tables on need.
SQL - is an acronym of Structured Query Language. It is a standard language developed and used for accessing and
modifying relational databases.
SQL is being used by many database management systems. Some of them are:
➢MySQL ➢PostgreSQL ➢Oracle ➢SQLite ➢Microsoft SQL Server
MySQL is currently the most popular open-source database software. It is a multi-user, multithreaded database
management system.
Constraints: Constraints are certain types of restrictions on the data values that an attribute can have.
Types of Constraints:
• NOT NULL - Ensures that a column cannot have NULL values where NULL means missing / unknown / not
applicable value.
• UNIQUE - Ensures that all the values in a column are distinct /unique.
• PRIMARY KEY - The column which can uniquely identify each row or record in a table.
MULTIPLE CHOICE QUESTIONS
1. What is a database?
(A) A collection of organized data (B) A software program used to manage data
(C) A hardware device used to store data (D) All of the above
6. In a multiplex, movies are screened in different auditoriums. One movie can be shown in more than
one auditorium. In order to maintain the record of movies, the multiplex maintains a relational
database consisting of two relations viz. MOVIE and AUDI respectively as shown below:
Movie(Movie_ID, MovieName, ReleaseDate)
Audi(AudiNo, Movie_ID, Seats, ScreenType,TicketPrice)
a) Is it correct to assign Movie_ID as the primary key in the MOVIE relation? If no, then suggest an
appropriate primary key.
b) Is it correct to assign AudiNo as the primary key in the AUDI relation? If no, then suggest
appropriate primary key.
c) Is there any foreign key in any of these relations?
Answer:
a) Yes, because every movie will have it's unique id.
b) Yes, because every auditorium will be assigned a unique id. No two auditoriums will have same id.
c) Yes, Movie_ID in Audi table is the foreign because it references the Movie_ID in the Movie table.
7. An organisation wants to create a database EMPDEPENDENT to maintain following details about its
employees and their dependent.
EMPLOYEE(AadharNumber, Name, Address,Department,EmployeeID)
DEPENDENT(EmployeeID, DependentName, Relationship)
a) Name the attributes of EMPLOYEE, which can be used as candidate keys.
b) The company wants to retrieve details of dependent of a particular employee. Name the tables and
the key which are required to retrieve this detail
c) What is the degree of EMPLOYEE and DEPENDENT relation?
Answer:
a) AadharNumber and EmployeeID can be used for candidate keys because they are unique to every
employee.
b) Employee and Dependent tables are required. EmployeeID is the key to retrieve the required data.
c) Degree of Employee relation = 5 and degree of Dependent relation = 3 The number of attributes in a
relation is called the Degree of the relation
8. 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:
SQL Operators
1. Mathematical Operators: SQL supports common mathematical operators such as + (addition), - (subtraction), *
(multiplication), and / (division). These operators are used for performing calculations on numeric data within the
database.
2. Relational Operators: - Relational operators like = (equal), <> (not equal), > (greater than), < (less than), >=
(greater than or equal to), and <= (less than or equal to) are used for comparing data values in SQL. They are crucial
for constructing conditional statements.
3.Logical Operators: - Logical operators such as AND, OR, and NOT are used to combine conditions in SQL queries.
They help in building complex query criteria and filtering data based on multiple conditions.
4. Aliasing and the DISTINCT Clause: - Aliasing allows you to provide temporary names for columns or tables in your
query results. It makes the output more readable and can be used to rename columns and tables.
- The DISTINCT clause is used to eliminate duplicate rows from the query result, ensuring that only unique rows are
displayed.
5. WHERE clause:- is essential for filtering and selecting specific rows that meet certain conditions. It supports
various operators to construct conditions, including:
- IN: Matches any of a list of values.
- BETWEEN: Selects values within a specific range.
- LIKE: Performs pattern matching with wildcard characters.
- IS NULL: Identifies rows with NULL values.
- IS NOT NULL: Identifies rows with non-NULL values.
6. ORDER BY: - The ORDER BY clause is used to sort the query result in ascending (ASC) or descending (DESC) order
based on one or more columns.
- It helps in organizing data for a more meaningful presentation.
7. Aggregate Functions: In the realm of databases, aggregate functions are essential tools for data summarization
and analysis.
MAX : Computes the maximum value within a given column.
MIN: Calculates the minimum value within a specified column.
AVG: Computes the average of values in a column.
SUM: Adds up all the values in a column.
COUNT: Counts the number of rows in a column or the number of non-null values.
Distinct
MysQl DISTINCT is used to remove duplicate records from the table and fetch only the unique records.
The DISTINCT is only used with the SELECT statement.
Syntax: Select DISTINCT expression FROM tables WHERE condition;
Select * from Empdata where Doj >= “2001-07-10” and Doj <= “2003-12-10”;
Select * from Empdata where empid NOT BETWEEN 101 and 107;
Select * from Empdata where Doj NOT BETWEEN “2001-07-10” and “2003-12-10”;
4. Assertion (A): HAVING clause is often used with the GROUP BY statement.
Reason (R): HAVING clause is used to check specified condition. (A)
5. Assertion (A):- Order by clause sorts fields in a table in ascending or descending order.
Reasoning (R): - The WHERE clause is placed before the ORDER BY clause. (b)
Help him in writing SQL queries to the perform the following task:
i. Insert a new record in the table having following values: [6,'Khushi','CS',85]
ii. To change the value “IP” to “Informatics Practices” in subject column.
iii. To remove the records of those students whose marks are less than 30.
iv. To add a new column Grade of suitable datatype.
v. To display records of “Informatics Practices” subject.
Answer:
i. INSERT INTO EXAM VALUES(6,'Khushi','CS',85);
ii. UPDATE EXAM SET subject= "Informatics Practices" where subject = "IP";
iii. DELETE FROM EXAM WHERE marks < 30;
iv. ALTER TABLE EXAM ADD COLUMN grade varchar (2);
v. Select * from exam where subject="Informatics Practices";
12. Consider the following table 'Furniture'. Write SQL commands for the statements (i)to (iii) and write
output for SQL queries (iv) and (v).
(i) To display FCODE and NAME of each Furniture Item in descending order of FCODE.
(ii) To display the average PRICE of all the Furniture Items, which are made of Wood with
WCODE as W02.
(iii) To display WCODE wise, WCODE and the highest price of Furniture Items.
(iv) SELECT SUM (PRICE) FROM Furniture WHERE WCODE = ‘W03’;
(v) SELECT COUNT (DISTINCT PRICE) FROM Furniture;
Answer:
(i) SELECT FCODE, NAME FROM FurnitureORDER BY FCODE DESC;
(ii) SELECT AVG (PRICE) FROM Furniture WHERE WCODE = ‘W02’;
(iii) SELECT WCODE, MAX(PRICE) FROM Furniture GROUP BY WCODE;
13. Consider the following table Activity. Write SQL Commands for the statements (i) to (ii) and output for
SQLqueries (iii) to (v).
(i) To display names of Participants and pointsin descending order of points.
(ii) To display House wise total points scored along with House name. (i.e. display the HOUSE
and total pointsscored by each HOUSE.)
(iii) SELECT AVERAGE (POINTS) FROM Activity WHERE HOUSE = 'Gandhi' orHOUSE = 'Bose':
(iv) SELECT COUNT (DISTINCT POINTS) FROM ACTIVITY;
(v) SELECT SUM(POINTS) FROM ACTIVITY;
Answer:
i. SELECT PARTICIPANTPOINTS FROM Activity ORDER BY POINTS DESC;
ii. SELECT HOUSE, SUM(POINTS) FROM Activity GROUP BY HOUSE;
iii. 250
iv. 4
1500
14. Naveen, a database administrator has designed a database for a Computer Stock.
Help her by writing answers of the following questions based on the given table:
TABLE: Stock
CODE FOR SELECTING AND PRINTING DATA FROM A MYSQL TABLE THROUGH PYTHON
import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="mohana",password="mohana", database="mydatabase")
mycursor = mydb.cursor()
mycursor.execute("SELECT * FROM customers")
myresult = mycursor.fetchall()
for x in myresult:
print(x)
CODE FOR DELETING A RECORD FROM MYSQL TABLE USING PYTHON
import mysql.connector
mydb = mysql.connector.connect(host="localhost",user="mohana",password="mohana", database="mydatabase")
mycursor = mydb.cursor()
sql = "DELETE FROM customers WHERE name = 'XYZ'"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, "record(s) deleted")
MCQs
1. Looking at the code below, what would this line do?
INSERT INTO Cats (name, breed) VALUES ('Petunia', 'American Shorthair')
A. Add a table to the Cats database with the name "Petunia" and breed "American Shorthair".
B. Add a row to the Cats table with the name "Petunia" and the breed "American Shorthair".
C. Create the table Cats.
D. Add a row to the Cats table with the name "American Shorthair" and the breed "Petunia".
2. Looking at the code below, what would this line do to the table Cats?
cur.execute('DROP TABLE IF EXISTS Cats ')
A. It will remove the row "Cats". B. It will move "Cats" to the end of the database.
C. It will remove the column "Cats". D. It will remove the table "Cats".
3. True or False? A cursor is used to create a database. A. True B. False
4. CONNECT() function in SQL is used for:
A. To connect to database. B. To open database
C. To create database D. All of the above
5. which method is used to retrieve N number of records
A. fetchone() B. fetchall() C. fetchmany() D. fetchN()
2. ABC Infotech Pvt. Ltd. needs to store, retrieve and delete the records of its employees. Develop an interface
that provides front-end interaction through Python, and stores and updates records using MySQL.
The operations on MySQL table "emp" involve reading, searching, updating and deleting the records of
employees.
Program to read and fetch all the records from EMP table having salary more than 70000.
Answer :-
import mysql.connector db1 = mysql.connector.connect (host = "localhost", user = "root", password =
"pathwalla", database = "company")
cursor = db1.cursor()
sql = "SELECT FROM EMP WHERE SALARY> 70000;"
try:
cursor.execute(sql)
resultset = cursor.fetchall ()
for row in resultset:
empno = row [0]
ename = row [1]
salary = row [2]
print (("empno-3d, ename=%s, salary-8f") % (empno, ename, salary))
except:
print ("Error: unable to fetch data")
db1.close()
3. import ______ mysql.connector______________ # line 1
mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword",
database="mydatabase" )
mycursor = mydb.cursor()
sql = "INSERT INTO customers (name, address) VALUES (%s, %s)"
val = ("John", "Highway 21")
mycursor.execute(sql, val)
______ mydb.commit()___________ # line 2
4. The given program is used to connect python with MySQL and show all the data present in the table
“stmaster” from the database “oraclenk”. You are required to complete the statements so that the code can
be executed properly.
import _____.connector __ pymysql #STATEMENT1
dbcon=pymysql._____________(host=”localhost”,user=”root”,________=”sia@1928”) #STATEMENT2
if dbcon.isconnected()==False
print(“Error in establishing connection:”)
cur=dbcon.______________() #STATEMENT3
query=”select * from stmaster”
cur.execute(_________)#STATEMENT4
resultset=cur.fetchmany(3)
for row in resultset:
print(row)
dbcon.______() #STATEMENT5
Answer:
1 mysql, as 2 connect, passwd 3 cursor 4 query 5 close