Professional Documents
Culture Documents
Xii Cbse Informatics Practices Sample Paper Solution Set4 PDF
Xii Cbse Informatics Practices Sample Paper Solution Set4 PDF
CBSE CS N IP Page 1 of 8
Communication Link
Ans: Loop1 will execute once and Loop2 will execute 0 times.
Loop1 is exit control loop and Loop2 is entry control loop.
(f) Write code in Java that takes two numbers from two text fields and displays their sum in a message dialog. 2
Ans: int i,j,sum;
i = Integer.parseInt(jTextField1.getText());
j = Integer.parseInt(jTextField2.getText());
sum = i+j;
JOptionPane.showMessageDialog(this, sum);
(g) How are tags used in XML different from tags in HTML? Write 2 points. 2
Ans: XML tags HTML tags
The tags used in XML are The tags used in HTML
user defined tags. are predefined tags.
XML tags cannot be HTML tags can be empty
empty tags. tags.
3(a) If a database "Employee" exists, which My Sql command helps you to start working in that database? 1
CBSE CS N IP Page 2 of 8
Ans: USE Employee
(b) Sahil created a table with some columns in My Sql. Later on he realized that there should have been another 1
column in the table. Which command should he use to add another column to the table?
Ans: ALTER TABLE
(c) Pooja, a student of class XI, created a table "Book". Price is a column of this table. To find the details of books 1
whose prices have not been entered in the table she wrote the following query: Select * from Book where
Price = NULL;
Help Pooja to run the query by removing the errors from the query and rewriting it.
Ans: Select * from Book where Price IS NULL;
(d) Rama is not able to change the value in a column of a table to NULL. What are the possible constraints that she 2
might have specified for that column?
Ans: She might have specified ‘NOT NULL’ or ‘PRIMARY key ‘constraints for that column while creating the table.
(e) Distinguish between Primary key and Candidate key with the help of a suitable example. 2
Ans: Candidate key of a table is a column or a group of columns that is capable of becoming the primary key) A
table can have multiple candidate keys but it can have only one primary key. Example:
Suppose a table STUDENT contains the columns AdmNo. RollNo. Name, Address. PhoneNo of the students of a
section of a class. In this table both AdmNo and RollNo are unique for every row in the table. Therefore, each
of these columns is capable of becoming the primary key of the table. Hence this table has two candidate keys
-AdmNo and RollNo. Out of these any one can be chosen as the primary key of the table.
(f) The LastName column of a table “Student” is given below: 2
LastName
Batra
Sehgal
Bhatia
Sharma
Mehta
Based on this information, find the output of the following queries:
a) SELECT lastname FROM Student WHERE lastname like “_a%”;
b) SELECT lastname FROM Student WHERE lastname not like “%a”;
Ans: a) Last Name
Batra
b) Last Name
Sehgal
(g) A table “Stock” in a database has 5 columns and 17 rows. What are the degree and cardinality of this table? 1
Ans: Degree = 5,Cardinality = 17
4(a) Define a class with reference to object oriented programming, 1
Ans: A class is an abstract user-defined data type that is used as a blueprint to define the objects of that class.
(b) What will be the content of jTextField1 after executing the following code: 1
int Num = 6;
Num = Num + 1;
if ( Num > 5)
jTextField1.setText(Integer.toString(Num));
else
jTextField1.setText(Integer.toString(Num+5));
Ans: 7
CBSE CS N IP Page 3 of 8
(c) What will be the contents of F1 and F2 after the following code is executed? 1
String F1 = "Hello" ,F2= "Friend";
F1 =F1.concat:(F2);
Ans: F1: HelloFriend
F2: Friend
(d) Rewrite the following program code using switch statement: 2
if (d == 1)
day = “Monday ";
else if (d = = 2)
day = "Tuesday “;
else if (d = = 3)
day = “Wednesday ";
else
day = "-";
Ans: switch(d)
{
case 1: day = “Monday”;
break;
case 2: day = "Tuesday";
break;
case 3: day = "Wednesday ";
break;
default: day = "-";
}
(e) The following code has some error(s). Rewrite the correct code underlining all the corrections made: 2
int i=2; j= 5;
while j>i
{
jTextField1.getText(“j is greater");
j--
++i;
}
JOptionPane.showMessageDialog( “ Hello" );
Ans: int i=2, i=5;
while (j>i)
{
jTextField1.setText("j is greater");
j--;
++i;
}
jOptionPane.showMessageDialog(this, "Hello" );
(f) What will be the contents of jTextField1 and jTextField2 after executing the following code: String s = “Value 2
for Time";
jTextField1.setText(s.length()+ “ “ );
jTextField2.setText(s.toLowerCase());
Ans: jTextField1: 14
jTextField2: value for time
(g) Glamour Garments has developed a GUI application for their company as shown below : 6
CBSE CS N IP Page 4 of 8
The company accepts payments in 3 modes- cheque, cash, and credit cards. The discount is given as per mode
of payment as follows:
Mode of Payment Discount
Cash 8%
Cheque 7%
Credit Card Nil
If the Bill Amount is more than 15000 then the customer gets an additional discount of 10% on Bill Amount.
(i) Write the code to make the textfields for Discount and Net Amount (named txtDisc and txtNetAmt
respectively) uneditable. 2
(ii) Write code to do the following:
a. When “Calculate Discount" button is clicked the discount should be calculated as per the given
criteria and it should be displayed in the discount textfield. “Calculate Net Amount" button (named
btnCalcNetAmt) should also be enabled. 3
b .When "Calculate Net Amount" button is clicked the net amount should be calculated and it
should be displayed in the net amount textfield. 1
(Net Amount = Bill Amount - Discount)
CBSE CS N IP Page 5 of 8
(b) float BillAmt, NetAmt. Disc;
BillAmt = Float.parseF1oat(txtBillAmt.getText());
Disc = Float.parseFloat(txtDisc.getText());
NetAmt = BillAmt- Disc;
txtNetAmt.setText(NetAmt+ " " );
5(a) Explain the purpose of DDL and DML commands used in SQL. Also give one example of each. 2
Ans: DDL: Data Definition Language. DDL commands are used to create, destroy and to restructure the database
objects.
Example: CREATE
DML: Data Manipulation Language. DML commands are used to insert, delete and change data in tables.
Example: DELETE
(b) Write the output of the following SQL queries: 2
(a) SELECT ROUND(6.5675, 2);
(b) SELECT TRUNCATE(5.3456, 1);
(c) SELECT DAYOFMONTH(‘2009-08-25‘);
(d) SELECT MID(‘Class 12’, 2,3);
Ans: (a) 6.57
(b) 5.3
(c) 25
(d) las
(c) Consider the table TEACHER given below. Write commands in SQL for (i) to (iv) and output for (v) to (viii) 6
ID Name Department Hiredate Category Gender salary
1 Tanya Nanda SocialStudies 1994-03-17 TGT F 25000
2 Saurabh Sharma Art 1990-02-12 PRT M 20000
3 Nadita Arora English 1980-05-16 PGT F 30000
4 James Jacob English 1989-10-16 TGT M 25000
5 Jaspreet Kaur Hindi 1990-08-01 PRT F 22000
6 Disha Sehgal Math 1980-03-17 PRT F 21000
7 Siddharth Kapoor Science 1994-09-02 TGT M 27000
8 Sonali Mukherjee Math 1980-11-17 TGT F 24500
i. To display all information about teachers of PGT category. 1
ii. To list the names of female teachers of Hindi department. 1
iii. To list names, departments, and hiring dates of all the teachers in ascending order of hiring dates.
1
iv. To count the number of teachers in English department. 1
v. SELECT MAX(Hiredate) FROM Teacher;
vi. SELECT DISTINCT(category) FROM Teacher;
vii. SELECT COUNT (*) FROM Teacher WHERE Category = ‘PGT’;
viii. SELECT AVG(Salary) FROM Teacher GROUP BY Gender;
Ans: i. SELECT * FROM Teacher WHERE Category = ‘PGT’;
ii. SELECT name FROM teacher WHERE Gender = ‘F’ AND Department = ‘Hindi’;
iii. SELECT name, department, hiredate FROM teacher ORDER BY hiredate;
iv. SELECT count(*)FROM teacher WHERE department = ‘English’;
v. 1994-09-02
vi. TGT
PRT
PGT
vii. 1
viii. 24500
24000
CBSE CS N IP Page 6 of 8
6(a) Write an SQL query to create the table ‘Item’ with the following structure: 2
Bill
BillNo CustID Bill_Amt
1 2 12000
2 1 15000
3 2 13000
4 3 13000
5 2 14000
(i) How many rows and how many columns will be there in the Cartesian product of these two tables?
(ii) Which column in the “Bill” table is the foreign key?
Customer
CustNo SetNo CustAddress
1 N2 Delhi
2 B1 Mumbai
3 N2 Mumbai
4 N1 Kolkata
5 B1 delhi
CBSE CS N IP Page 7 of 8
With reference to these tables, Write commands in SQL for (i) and (ii) and output for (iii) below:
(i) Display the CustNo, CustAddress and corresponding SetName for each customer.
(ii) Display the Customer Details for each customer who uses a Talk handset.
(iii) SELECT SetNo. SetName
FROM Handset, customer
WHERE SetNo = SetCode
AND CustAddress = ‘Delhi’;
Ans: (i) SELECT CustNo, CustAddress, SetName FROM Customer, Handset Where SetNo = SetCode;
(ii) SELECT Customer. * FROM Customer, Handset WHERE SetNo = SetCode and SetName like “Talk%”;
(iii) SetNo SetName
N2 Talk 3G
B1 Samwaad
7(a) What is the advantage of using IT applications over the manual operations? 1
Ans: Using IT applications we can save time.
(b) Give one example each of input values, where Radio Button and Check Box should be used for efficiency in an 2
IT application.
Ans: (1) Radio Button –
a. To input gender: Male or Female
(2) Check Box –
a. To input hobbies from a number of options available.
(c) Vijayan works for the Customs Department. He wishes to create controls on a form for the following functions. 2
Choose appropriate controls from Text box. Label, Option button, Check box, List box, Combo box, Command
button and write in the third column.
SNo Control Used to Control
1 Enter Last Name
2 Enter gender
3 Choose City from a list of cities
4 Submit Form
Ans:
SNo Control Used to Control
1 Enter Last Name Text Field
2 Enter gender Option Button
3 Choose City from a list of cities List Box or Combo Box
4 Submit Form Button (Command)
CBSE CS N IP Page 8 of 8