You are on page 1of 267

r

Best Seller k i
WN

m
_
OSWAAL BOOKS ®

tuaBnra IMUR
etraptii
*
ISC
¥ ¥
5] r#j

{ U

s®6
Kj

QUESTION
BANK
Chapterwise & Topicwise

O
4 SOLVED
PAPERS
CLASS 12
xJJL *
COMPUTER
SCIENCE
/

X
i m
Latest Board
•••• • Mind Maps
Paper
••••••••
•<

y S ta ®
Examiners ’ Concept Videos
| Comments & for blended
jg) i Answering Tips | Learning
r
Best Seller FOR
2023 EXAM

•i OSWAAL BOOKS
. taaisiacaiB caw c-rcwcn

ISC
QUESTION
Chapterwise
BANK
& Topicwise

SOLVED
PAPERS
CLASS 12
. j ~ COMPUTER SCIENCE
Strictly as per the Revised Syllabus Released on
20th May 2022 Issued by CISCE

' TTT '


X
k
So
•• Latest Board
Paper
Mina Maps

••
••••••

••••
•••
•••
•••
••
•••• ••• •
•••••••••••
is
Examiners ’ Concept Videos
Comments & for blended
Learning
IS 7th EDITION YEAR 2022- 23
pill ISBN (0) (8) (

SYLLABUS t
"978-93-5595-137- 3"

ISC-INDIAN SCHOOL
^ )

CERTIFICATE EXAMINATION
COVERED r

©
PUBLISHED BY
«OSWAAL BOOKS &
LEARNING PVT. LTD.
COPYRIGHT
RESERVED 1 / 11, Sahitya Kunj, M.G. Road,
Agra - 282002, (UP) India
BY THE PUBLISHERS
All rights reserved . No part of
this book may be reproduced, 1 / 1 , Cambourne Business Centre
stored in a retrieval system, Cambridge, Cambridgeshire
or transmitted, in any form or CB 236DR United kingdom
by any means , without written
permission from the publishers.
The author and publisher will
gladly receive information 0562 - 2857671
enabling them to rectify any
error or omission in subsequent
editions.
contact@oswaalbooks.com

www. OswaalBooks. com

DISCLAIMER
•Oswaal Books, hasanyexercised due care and caution in collecting all the data before publishing this book.
In spite of this if , inaccuracy
omission or printing error occurs with regard to the data contained in this
book, Oswaal Books will not be held responsible or liable.
• All the names, characters and incidents depicted in this book by the author are fictitious. The sole
purpose is to explain the given concept to the students. They have no relation with any event, person,
religion, caste or political establishments.
• The opinions, discussions, views and recommendations are solely those of the authors and not of
Oswaal Books.

Google Play Edition


TABLE OF CONTENTS
• Latest CISCE Circular released on 20th May 2022 for the Academic Year 2022 -23 6 - 6
• Latest ISC Syllabus issued by CISCE for Academic Year 2022-2023 7 - 11
• Topics Found Difficult by the Candidates 12 - 13
• Concepts in which candidates got confused 14 - 14
• Suggestions for students 15 - 16
• ISC Solved Paper 2021- 22 Semester - 2 Examination 19 - 23

SECTION A Topic 3. Arrays

1. Boolean Algebra 1 - 34 Topic 4. Strings


Topic 1. Propositional Logic • Self Assessment Paper- 3 171- 171
Topic 2. Theorems and Postulates of SECTION C
Boolean Algebra
4. Inheritance, Interfaces,
Topic 3. Forms of Representing
Boolean Expressions Polymorphism, Data Structures 172 - 198
Topic 4. Karnaugh Map (K - map) Topic 1. Inheritance
Topic 2. Interfaces
• Self Assessment Paper- 1 35 - 35
2. Computer Hardware 36 - 86 • Self Assessment Paper- 4 199 - 200
Topic 1. Logic Gates 5. Data Structures 201 - 223
Topic 2. Designing Simple Logic Circuits Topic 1. Queues and Stacks
Topic 3. Combinational Circuits Topic 2. Trees and Link List
• Self Assessment Paper- 2 87 - 87
• Self Assessment Paper- 5 224 - 225
SECTION B
• Practice Paper- 1 226 - 229
3. Programming in Java 88 - 170
Topic 1. Fundamentals of Java
• Practice Paper- 2 230 - 234

Topic 2. Methods, Recursion • Practice Paper- 3 235 - 239

(3)
Get Unlimited Access to
Free Resources
at: oswaalbooks.com / free-resources /

Step 1 : Visit oswaalbooks.com /


tree-resources / and choose
your board and class.

/T •? 22£LKS£
S
«
'
£

Step 2: Not Registered?


Register here quickly for the
ocean of knowledge inside.
(If registered already, simply
login and move ahead)

I I (4)
Step 3: You are here!
Enjoy this unlimited treat of
FREE resources.
LET THE ADVENTURE BEGIN!

m
India is currently one of the youngest economies in the
world. Hence, it's imperative for our education system to
churn out more learners than ever before. Considering the
Banking on current learning mindset of students CISCE has introduced
Better Systems the curriculum for classes XI & XII containing academic
"Improvise, Adapt, overcome" has content, syllabus for examinations with learning outcomes,
been the mantra of education pedagogical practices and assessment guidelines. The Board
boards and schools everywhere. will conduct the annual scheme of assessment at the end of
Conducting lectures as well as the Academic session 2022- 23 as per the given curriculum.
assessments online was still pretty
uncommon in our country. But To score well in Exams students need to start by acquiring the
now teachers and students have latest and most relevant study material. The focus should be
got familiar with the new ways. on conceptual clarity rather than mugging up facts. Students
The intention of shifting from rote should find out their preparation level by conducting
learning to competency-based regular self-assessments and practicing questions from this
development will prove beneficial question bank. Breaking down the syllabus in a systematic
to the coming generations; and in way right from the beginning will help students learn better
turn, to the country. and secure a high score.

Benefits of studying from Oswaal Question Banks for ISC exams include

1. Strictly as per the revised syllabus for Exams 2023


2. Includes fully solved ISC Board Specimen Question Paper released on 12th July 2022

3. With all Typologies as per ISC pattern


4. Chapter wise and Topic wise Introduction for in-depth study
5. Modified & Empowered Mind Maps for quick learning
6. Concept videos for Blended Learning
7. Examiner Comments & Answering Tips to aid in exam preparation.

Our Heartfelt Gratitude


Finally, we would like to thank our authors, editors, and reviewers. We promise to
always strive towards 'Making Learning Simple' for all of you.
Wish you all Happy Learning and a Successful 2022 -23!!

(5)
CISCE CIRCULAR 2022-23

Council For The Indian School Certificate Examinations


Pragati House, 3rd Floor, 47-48, Nehru Place, New Delhi -110019
Telephones: 29564831, 29564833, 26411706, 26413820
E-Mail: council@cisce.org Fax: 91-11-29564735

Chief Executive & Secretary


GERRY ARATHOON
M.A.,B.Ed.
PV /CIR/ 2022
20th May 2022
To: All Heads of Schools presenting candidates for the ICSE & ISC Year 2023 Examinations
Dear Principal,
Subject: Conduct of the ICSE and ISC Year 2023 Examination and Revised Syllabus
for the year of Examination
It has been decided by the CISCE to conduct only ONE EXAMINATION at the end of the
Academic Year 2023 at both ICSE & ISC levels. The CISCE proposes to hold the said examinations
tentatively in the months of February/ March 2023.
Please note the Syllabus for the ICSE & ISC Year 2023 Examination has been revised in select
subjects. The revised syllabus is available on the CISCE website, under the Publication Section.
You are requested to plan the academic calendar in your respective schools accordingly, so as to
prepare the students adequately for the examinations.
It may further be noted that the specimen papers for all subjects will be made available on the
website of the CISCE i.e., www.cisce.org in the month of July 2022.
You are further requested to disseminate this important information to all your students, teachers,
parents, and guardians.
With warm regards
Yours sincerely,

Gerry Arathoon
Chief Executive & Secretary

(6)
SYLLABUS

COMPUTER SCIENCE (868)


CLASS 12
Latest Syllabus issued by CISCE For the Academic Year 2022- 2023
There will be two papers in the subject :
Paper I : Theory (3 hours ) 70 marks
Paper II: Practical - 3 hours ... 30 marks
PAPER I (THEORY) - 70 Marks
SECTION A majority circuit etc., SOP and POS representation;
1. Boolean Algebra Maxterms & Minterms, Canonical and Cardinal
(a) Propositional logic, well formed formulae, truth representation, reduction using Karnaugh maps and
values and interpretation of well formed formulae Boolean algebra.
(wff ), truth tables, satisfiable, unsatisfiable and 2. Computer Hardware
valid formulae. Equivalence laws and their use in (a ) Elementary logic gates (NOT, AND, OR, NAND,
simplifying wffs. NOR, XOR, XNOR) and their use in circuits.
Propositional variables; the common logical connectives ( ) Applications of Boolean algebra and logic gates
b
( ~ ( not )( negation ), A (and )( conjunction), v (or ) to half adders, full adders, encoders, decoders,
(disjunction ), => ( implication ), <=> ( biconditional ); multiplexers, NAND, NOR as universal gates.
definition of a well-formed formula ( wff ); ' representation Show the correspondence between Boolean methods and
of simple word problems as wff (this can be used for the corresponding switching circuits or gates . Show that
motivation ); the values true and false; interpretation NAND and NOR gates are universal by converting
of a wff ; truth tables; satisfiable, unsatisfiable and valid some circuits to purely NAND or NOR gates.
formulae. SECTION B
Equivalence laws: commutativity of A, V; associativity The programming element in the syllabus (Sections B
of A, v; distributivity; De Morgan' s laws; law of and C) is aimed at algorithmic problem solving and not
implication ( p => q = ~ p v q ); law of biconditional (( p merely rote learning of Java syntax. The Java version used
<=> q ) = ( p => q ) A (q => p )); identity ( p s= p ); law of should be 5.0 or later. For programming, the students can
negation ( ~ ( ~ p ) - p ); law of excluded middle ( p v ~ p use any text editor and the javac and java programs or
= true ); law of contradiction ( pA~ p = false ); tautology any other development environment: for example, BlueJ,
and contingency simplification rules for A, V. Converse, Eclipse, NetBeans etc. BlueJ is strongly recommended for
inverse and contra positive. its simplicity, ease of use and because it is very well suited
(b) Binary valued quantities; basic postulates of for an 'objects first approach.
7

Boolean algebra; operations AND, OR and NOT; 3. Implementation of algorithms to solve problems
truth tables. The students are required to do lab assignments in
(c) Basic theorems of Boolean algebra (e.g. duality, the computer lab concurrently with the lectures.
idempotence, commutativity, associativity, Programming assignments should be done such that
distributivity, operations with 0 and 1, complements, each major topic is covered in at least one assignment.
absorption, involution); De Morgan's theorem and Assignment problems should be designed so that
its applications; reducing Boolean expressions they are sufficiently challenging. Students must
to sum of products and product of sums forms; do algorithm design, address correctness issues,
Karnaugh maps (up to four variables). implement and execute the algorithm in Java and
Verify the laws of Boolean algebra using truth tables. debug where necessary.
Inputs, outputs for circuits like half and full adders, Self explanatory.

(7)
SYLLABUS
.
4 Programming in Java (Review of Class XI Sections B searching, finding maximum/minimum, sorting
and C) techniques, solving systems of linear equations,
Note that items 4 to 13 should be introduced almost substring, concatenation, length, access to char in
simultaneously along with classes and their definitions . string, etc.).
While reviewing, ensure that new higher order problems Storing many data elements of the same type requires
are solved using these constructs. structured data types - like arrays. Access in arrays is
.
5 Objects constant time and does not depend on the number of
(a ) Objects as data (attributes) + behaviour (methods); elements. Address calculation ( row major and column major ),
object as an instance of a class. Constructors. Sorting techniques ( bubble, selection, insertion ). Structured
data types can be defined by classes - String. Introduce
(b) Analysis of some real-world programming
the Java library String class and the basic operations on
examples in terms of objects and classes.
strings (accessing individual characters, various substring
(c) Basic input/output using Scanner from JDK; input/
operations, concatenation, replacement, index of operations ).
output exceptions. Tokens in an input stream,
11 . Recursion
concept of whitespace, extracting tokens from an
input stream (String Tokenizer class). Concept of recursion, simple recursive methods
(e.g. factorial, GCD, binary search, conversion of
.
6 Primitive values, Wrapper classes, Types and casting
representations of numbers between different bases).
Primitive values and types: byte, int, short, long, float,
Many problems can be solved very elegantly by observing
double, boolean, char. Corresponding wrapper classes
that the solution can be composed of solutions to ' smaller'
for each primitive type. Class as type of the object.
versions of the same problem with the base version having a
Class as mechanism for user defined types. Changing
known simple solution. Recursion can be initially motivated
types through user defined casting and automatic type
by using recursive equations to define certain methods. These
coercion for some primitive types.
definitions are fairly obvious and are easy to understand. The
.
7 Variables, Expressions
definitions can be directly converted to a program. Emphasize
Variables as names for values; named constants that any recursion must have a base case. Otherwise, the
(final), expressions (arithmetic and logical) and their computation can go into an infinite loop.
evaluation (operators, associativity, precedence).
The tower of Hanoi is a very good example of how recursion
Assignment operation; difference between left hand
gives a very simple and elegant solution where as non-
side and right hand side of assignment.
recursive solutions are quite complex.
.
8 Statements, Scope
SECTION C
Statements; conditional (if, if else, if else if, switch
Inheritance, Interface, Polymorphism, Data structures.
case, ternary operator), looping (for, while, do while,
12. Inheritance, Interfaces and Polymorphism
continue, break); grouping statements in blocks, scope
and visibility of variables. (a ) Inheritance; super and derived classes; member
access in derived classes; redefinition of variables
.
9 Methods
and methods in subclasses; abstract classes; class
Methods (as abstractions for complex user defined
Object; protected visibility. Subclass polymorphism
operations on objects), formal arguments and actual
and dynamic binding.
arguments in methods; different behaviour of primitive
Emphasize inheritance as a mechanism to reuse a class
and object arguments. Static method and variables. The
by extending it . Inheritance should not normally be
this Operator. Examples of algorithmic problem solving
used just to reuse some methods defined in a class but
using methods (number problems, finding roots of
only when there is a genuine specialization (or subclass )
algebraic equations etc.).
relationship between objects of the super class and that of
.
10 Arrays, Strings
the derived class.
Structured data types - arrays (single and multi-
b
( ) Interfaces in Java (conceptual)
dimensional), address calculations, strings. Example
Emphasize the difference between the Java language
algorithms that use structured data types (e.g.

(8)
SYLLABUS
construct interface and the word interface often used to Examiner. A printout of the program listing including
describe the set of method prototypes of a class. output results should be attached to the answer
13. Data structures script containing the algorithm and handwritten
(a) Basic data structures (stack, queue, dequeue); program. This should be returned to the examiner. The
implementation directly through classes; definition program should be sufficiently documented so that the
through an interface and multiple implementations algorithm, representation and development process
by implementing the interface. Conversion of Infix is clear from reading the program. Large differences
to Prefix and Postfix notations. between the planned program and the printout will
Basic algorithms and programs using the above data result in loss of marks.
structures. Teachers should maintain a record of all the assignments
(b) Single linked list (Algorithm and programming), done as part of the practical work through the year and
binary trees, tree traversals (Conceptual). give it due credit at the time of cumulative evaluation
at the end of the year. Students are expected to do a
The following should be covered for each data structure:
Linked List ( single ): insertion, deletion, reversal, -
minimum of twenty five assignments for the year.

extracting an element or a sublist, checking emptiness. EVALUATION:


Binary trees: apart from the definition the following Marks (out of a total of 30) should be distributed as
concepts should be covered: root, internal nodes, external given below:
nodes ( leaves ), height ( tree, node), depth ( tree, node ), Continuous Evaluation
level , size, degree, siblings, sub tree, completeness, Candidates will be required to submit a work file
balancing, traversals ( pre, post and in-order ). containing the practical work related to programming
PAPER II: PRACTICAL - 30 MARKS assignments done during the year.
This paper of three hours' duration will be evaluated by Programming assignments done 10 marks
the Visiting Examiner appointed locally and approved throughout the year (Internal
by the Council. Evaluation)
The paper shall consist of three programming problems Programming assignments done 5 marks
throughout the year (Visiting Examiner)
from which a candidate has to attempt any one. The
Terminal Evaluation
practical consists of the two parts:
1. Planning Session Solution to programming problem on 15 marks
the computer
2. Examination Session
Marks should be given for choice of algorithm and
The total time to be spent on the Planning session and
implementation strategy, documentation, correct output
the Examination session is three hours. A maximum of
on known inputs mentioned in the question paper, correct
90 minutes is permitted for the Planning session and 90
output for unknown inputs available only to the examiner.
minutes for the Examination session.
NOTE:
Candidates are to be permitted to proceed to the
Examination Session only after the 90 minutes of the Algorithm should be expressed clearly using any standard
scheme such as a pseudo code.
Planning Session are over.
EQUIPMENT
Planning Session
There should be enough computers to provide for a
The candidates will be required to prepare an algorithm
and a hand written Java program to solve the problem. teaching schedule where at least three-fourths of the time
available is used for programming.
Examination Session
Schools should have equipment/platforms such that all
The program handed in at the end of the Planning
the software required for practical work runs properly, i.e.
session shall be returned to the candidates. The
it should run at acceptable speeds.
candidates will be required to key-in and execute the
Since hardware and software evolve and change very
Java program on seen and unseen inputs individually
on the Computer and show execution to the Visiting rapidly, the schools may have to upgrade them as required.

(9)
SYLLABUS
Following are the recommended specifications as of now: is that it should run the operating system and Java
The Facilities: programming system 0ava compiler, Java runtime
• A lecture cum demonstration room with a environment, Java development environment ) at
MULTIMEDIA PROJECTOR/ an LCD and O.H.E acceptable speeds.
attached to the computer. • Good Quality printers.
• A white board with white board markers should be Software:
available. • Any suitable Operating System can be used.
• A fully equipped Computer Laboratory that allows one • JDK 6 or later.
computer per student. • Documentation for the JDK version being used.
• Internet connection for accessing the World Wide Web • A suitable text editor. A development environment with
and email facility. a debugger is preferred (e.g. BlueJ, Eclipse, NetBeans).
• The computers should have a minimum of 1 GB RAM BlueJ is recommended for its ease of use and simplicity.
and a P IV or higher processor. The basic requirement

( 10 )
Assessment of Practical File Assessment of the Practical Examination
(To be evaluated by the Visiting Examiner only) TOTAL MARKS (Total
Marks are to be added and
Visiting Ex- entered by the Visiting Ex-
Unique Identification
Internal Algorithm Java Program Hard Copy Output
Evaluation aminer with internal aminer )
S. No. Number (Unique ID ) of ( printout)
10 Marks 5 Marks Documenta-
the candidate
tion

3 Marks 7 Marks 2 Marks 3 Marks 30 Marks

1.

2.

3.

4.
M
M

5.

6.

7.

8.

9.

10 .

Name of the Visiting Examiner


Signature:
Date:
Topics Found Difficult by Candidates

i
Examination Paper 2020
• Passing objects to functions
• Interfaces
Circular queue operations for push() and pop() operations
• Degree of and its implementation using inheritance
• Properties aofnode in a binary tree
• Dual and Compliment of a Boolean expression
zero
• Infix to prefix notation
• Output using recursion
• Circular queue
• Concept of inheritance with interface and super class
• Degree of a node in a Binary tree
• Properties of zero in Boolean algebra

Examination Paper 2019

• Interface
Propositional statements for Converse and Contrapositive.
• Complexitydefinition .
• Output using recursive function
and comparing 2
0(n ) and 0(2“).
• K MAPS (grouping, redundant .groups, map rolling, place value).
• Recursive technique.
- -

»
• Passing objects to functions.
• Queue operations for push() and pop() operations.
• Size of a binary tree.

Examination Paper 2018

• Extracting
Wrapper classes
• Recursive technique
digits from a number without using the % operator.
• methods. : >Passing objects to functions. > Stack operations for push() and pop(

Examination Paper 2017


,
• Interfaces
The symbols ' =>' , and V from propositional logic (Inverse and Converse)
AI

• Complexityand Classes
• Returning value of the base case in recursive output
• Complement properties
• Recursive technique
• Passing objects to functions
• Queue operations for adding and removing elements
•Examination Paper 2016
• The symbols 'L' and 'V' from propositional logic
• 'fall through' condition in switch case ()
( 12 )
Topics Found Difficult by Candidates

• Keywords 'extends' and 'implements' with respect to inheritance


• Recursive
Returning value of the base case in recursive output
• Passing objects
technique
• Stack operationstoforfunctions
•Examination Paper 2015adding and removing stings
• Computational
The symbols 'L' and 'V' from propositional logic
• Size of double data
complexity definition.
• Keywords ‘this’ andtype for the width of an array cell.
• Extracting digits without
‘super’ with respect to overriding
• Deriving POS expressionusing the % sign.
• Recursive technique from a truth table
• Pre defined size of an array and re declaring the size in the constructor.
• Complexity and Big ‘O’ Notation
- -
• Stack operations for adding and removing characters.
•Examination Paper 2014
• Tmth table of conjunction and disjunction in a proposition.
• Difference
Advantages of using the concept of inheritance.
• Output of abetween int nextlnt() and boolean has Nextlnt() functions
• K-MAPS (Labeling , Grouping
character array without mentioning subscript.
• Passing objects to functions. , map-rolling , place value)
• Recursive technique and invoking function within another function (Nesting of functions).
• Pushing marks from array to stack.

I ( 13 )
Concepts in which Candidates got Confused

Examination Paper 2020


•• Best Conversion from infix notation to prefix notation
case and worst case for bubble sort
•• K MAPSusing
Output recursive function

i
- (grouping, redundant groups, map-rolling, place value)
• Recursive Drawing XOR gate using NOR gate
•Examination Paper technique
2019
•• Use of single instance variable
Propositional statements .
for multiple operations in various functions.
•• Size and Siblings of a tree
Link list and Queue .

Examination Paper 2018


•• Complexity The symbols ( '=>', and 'v' ) in a proposition.
'A'
and factors.
•• Output withouthandling
Exceptional and finally block in a try .. catch statement.
using the % operator.
•• Passing objects to functions.
Splitting words from a sentence.
•• Passing of objects.
Use of single instance variable for multiple operations in various functions.
•• Link list and Stacks.
Height of tree.
Examination Paper 2017
•• The symbols in a proposition.
The terms 'complexity' and 'interface'.
•• Passing
Output using recursive technique.
objects to functions.
•• Passing of objects
Sorting and swapping character in a word.
.
•• Link list and Queues. variable for multiple operations in various functions.
Use of Single instance

Examination Paper 2016


•• The The symbols in a proposition.
terms 'extends' and 'implements'.
•• Passing objects
Symbol of decrement operator (postfix).
to functions.
•• Cyclic shift in matrix
Concatenation of two strings.
.
•Examination Paper 2015 variable for multiple operations in various functions.
Use of Single instance

•• The symbols in a proposition.


Difference between ‘this’ and ‘super’.
•• Deriving POS expression from Truth table.
Deriving expression from a given circuit and reducing it.
•• Concatenation of two numbers.
Left and right sub tree for a binary tree.

( 14 )
Suggestions for Students
> => Apart from Textbook learning, surfing the net (Wikipedia, School net, etc.) and other reliable
resources would be helpful to gather knowledge on the latest concepts and enhancements
in programming. Proper definitions, output programs, algorithms, etc. can be downloaded
directly from the internet.
|
=> Prepare a summary for each chapter or use high lighters to highlight the important terms and
definitions.
> => Revise of the entire syllabus thoroughly.
Relate everything taught in class with Real Life Environment examples which helps in
remembering / recall of the concepts learnt.
> => Practical work on the computer is necessary on regular basis to understand the syntax and
to correct errors.
=> Answers and definitions should be short and precise and according to the marks allocated.
Solve ISC previous years’ question papers.
>=> Underline/ Highlight Important words and terms.
>=> Show working at the side of each question, wherever required.
|
=> Mention laws while reducing a Boolean Expression. Practice one form of K-Map with proper
place value for both SOP and POS.
> => In programming documentation is compulsory and should be mentioned with each program.
>=> Declare the class with data members and member functions.
>=> Expand or define each function according to the instructions given by the side of each
function.
|
=> Do not memorise the program, try to understand the logic.
> => Practice constructors with every program. Treat each function of a class as a separate program.
=>
> Do your preparations section-wise following the scope of the syllabus.
=> Revise and integrate the concepts studied in Class XI with the Class XII syllabus.
=> Avoid selective study.
=> Give equal importance to all the topics mentioned in the syllabus.
=>
|
Practise each topic/sub-topic with as many examples as possible.
Gather knowledge of the subject comprehensively with latest concepts and improved
techniques in programming using reliable resources like text books, Wikipedia etc.
=> Download directly proper definitions, output programs, algorithms etc. from the net.
=> Prepare summary for each chapter or use high lighters to recognize the important terms and
definitions.
=> Understand all key terms/important words, definitions etc. comprehensively and learn.

( 15 )
Suggestions for Students

=> Practise on the system on a regular basis to understand the syntax and to correct the errors.
=> Always write laws while reducing a Boolean expression.
=> Practise one form of K-Map with proper place value for both SOP and POS.
=> Mention documentation with each program.
=> Declare the class with data members and member functions.
=> Expand or define each function according to the instructions given by the side of each function,
t# Practise constructors with every program.
=> Understand the logic of a program instead of memorising it.
=> Solve previous years’ ISC question papers.
=> Always show workings, wherever required, on the side of each question.
=> Always answer to any question as per the requirement of the question.

( 16 )
HEAR IT FROM OUR HAPPY READERS!

This book has a lot of ques.


For preparation and nr
Just Fabulous loved the
product I recommended
proper practice.. One can j
everyone to buy this
solve this after completing the A
book it will help you
syllabus . U can definatly go M
for this one.
a lot during exams .
Bhoomi Kajuria

Suresh Kalanki

Aashito

I have bought this book for my


sister ' s daughter. It's very easy to
study . Best collection of question on
pysical enviroment studies. Questions
A must buy book for school students. and solutions given manner are easy
Beginner friendly book ith quality
answers.
Srija
Shruti Abinaya

Best Framed answers with clear


understanding . Content is to the
> point and it covers all the topics.

Mayank Singh

If you want to get good result in


ISC then u will need this book.
Pranoy Das
Everything is very lucidly described The way of solution given in this
in question and answer form. Slightly book is very simple and understandable.
elaborative but language is easy . The book is very good for revision of your
Its a very good reference book and syllabus as it covers all the points. Make
got it cheap and delivered in time. your preparation easier.
Overall a very good buy.
Moksh
Misha Agarwal

( 17 )
Exclusive School Books Suppliers
OUR DISTRIBUTORS
M/s Pragnya, 8847888616, 9437943777,
ANDHRA PRADESH BHUBANESHWAR
Padmalaya, 9437026922

HYDERABAD Sri Balaji Book Depot, (040) 27613300, 9866355473 PUNJAB

BIHAR PATIALA Adarsh Enterprises, 9814347613

Bokaro Student Friends, (0612) 2300600, 2618400, Gyan Ganga Ltd.,


PATNA
9304826651
LUDHIANA Amit Book Depot., 9815807871

Nova Publisher 8L Distributors, (0612) 2666404, Cheap Book Store, 9872223458, 9878258592, Subhash Book
JALANDHAR Depot, 9876453625,
City Book Shop, 9417440753
Shri Durga Pustak Mandir, 9334477386, Sharda Pustak Bhandar,
RAJASTHAN
9334259293

DELHI BHILWARA Nakoda Book Depot, (01482) 243653, 9214983594

Mittal Books, (011) 23288887, 9899037390,


DELHI R.D. Chawla & Sons, (011) 23282360 -61 TAMIL NADU
Bokaro Student Friends Pvt Ltd., 9308451948

GUJARAT CHENNAI Vijaya Stores, 9381037417

AHMEDABAD Patel Book, 9898184248, 9824386112 TRIPURA

JHARKHAND AGARTALA Books Corner, 9856358594

BOKARO Bokaro Student Friends, (0654) 2233094, 7360021503 UTTAR PRADESH

Sparsh Book Agency, 9412257817, Om Pustak Mandir, (0562)


Crown Book Distributor 8i Publishers, (0651) 2213735,
RANCHI AGRA 2464014, 9319117771, Panchsheel Books, 9412257961,
Bokaro Students Friends, 9234628152
9412257962,

DUMKA Vidyarthi Pustak Bhandar, 9431310228 ALLAHABAD Mehrotra Book Agency, (0532) 2266865, 9415636890

KARNATAKA AZAMGARH Sasta Sahitya Sadan, 9450029674

HUBLI Renuka Book Distributors, 0836- 2244124, 9513355124 GORAKHPUR Atul Pustak Bhandar, 9935210622, Central Book, 9935454590

Rama Book Depot (Retail), (0522) 4080133, 9956922433, Vyapar


KERALA LUCKNOW
Sadan, 7607102462, Azad Book Depot Pvt. Ltd., 7317000250

ERNAKULAM Academic Book House, (0484) 2376613 MEERUT Ideal Book Depot, (0121) 4059252, 9837066307

JOMER SRINILAYAM H & C Store, (0484) 2351233 NOIDA Prozo Distribution Pvt Ltd., 9318395520/8882170255

KOTTAYAM H & C Store, (0481) 2304351, Book Centre, (0481) 2566992 VARANASI Bokaro Student Friends, (0542) 2401250, 8299344607

TRIVANDRUM Academic Book House, (0471) 2333349, 9447063349, Gupta Books, 9918155500, 8707225564

H & C Store, (0471) 2572010, 9446411996 UTTARAKHAND

CALICUT Aman Book Stall, (0495) 2721282, DEHRADUN Brothers Pustak Bhandar, 9897833882, Mittal Book, 9837223825

MAHARASHTRA WEST BENGAL

Oriental Publishers & Distributor (033) 40628367,


Katha 'O' Kahini, (033) 22196313, 22419071,
Vijay Book Depot, 9860122094, (0712) 2520496, 2534217,
NAGPUR KOLKATA Saha Book House, (033) 22193671, 9333416484,
Karmveer Book, 9923966466
Bijay Pustak Bhandar, 8961260603,
United Book House, 9231692641, (033) 22418105

Shivam Books & Stationery, (022) 28230897, 9892935799,


MUMBAI Vidyarthi Sales Agencies, 9819776110, COOCH BEHAR S.B. Book Distributor, 9002670771
New Student Agencies, 7045065799

PUNE Natraj Book Depot, (020) 24485054, 9890054092, SILIGURI Agarwal Book House, (0353) 2535274, 9832038727

ODISHA
£-
o
CUTTACK A. K. Mishra Agencies, 9437025991, 9437081319

( 18 )
ISC SEMESTER-2 EXAMINATION
Computer Science
Solved Paper - 2021-22
Class-12th
Maximum Marks: 35
Time allowed: One and a half hours
Candidates are allowed an additional 10 minutes for only reading the paper.
They must NOT start writing during this time.
Answer all questions in Section A, Section B and Section C.
While answering questions in Section A and B, working and reasoning may he
indicated briefly, wherever required.
The intended marks for questions or parts of questions are given in brackets [ ].
All working, including rough work, should be done on the same sheet as the rest of the answer.

Section-A
Question 1
(i) The concept in Java to perform method overloading and method overriding is called: [1]
(a) inheritance (b) Polymorphism
(c) data abstraction (d ) encapsulation
(ii) The interface in Java is a mechanism to achieve: [1]
(a) encapsulation (b) overriding
(c) polymorphism (d ) abstraction
(iii) System.out.println ("Computer Science" last Index Of ('E'));
,

The output of the statement given above will be: [1]


(a) 8 (b ) 7
(c) -1 (d ) 15
(iv) Write a statement in Java to extract the last four characters from the word "SIMPLICITY" , [1]
(v) Name a data structure that follows LIFO principle and one that follows FIFO principle. [1]
(vi) What is the output of the program code given below, when the value of x = 294? [1]
inf simple (inf x )
{ return (x < = 0)? 0: x + simple(x/10);}
(vii) State any one drawback of using recursive technique in a Java program. [1]
Section-B
Question 2.
Differentiate between finite recursion and infinite recursion. [2]
Question 3 .
Convert the following infix notation to prefix notation; [2]
P * ( Q - R) + S
Question 4 .
Answer the following questions from the diagram of a Binary Tree given below: [2]

(i) State the siblings of the nodes C and E. Also, state the predecessor node( s ) and successor node( s ) of node B. [2]
(ii) Write the in-order traversal of the left sub tree and the pre-order traversal of the right sub tree. [2]
20 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE Class-XII

Section-C
. I
Each program should be written in such a way that it clearly depicts the logic of the problem
This can be achieved by using mnemonic names and comments in the program.
( Flowcharts and Algorithms are not required.)
The programs must be written in Java.
Question 5.
(i) Design a class Unique, which checks whether a word begins and ends with a vowel. [6]
Example: APPLE, ARORA etc.
The details of the members of the class are given below:
Class name : Unique
Data members/instance variables:
word stores a word
len to store the length of the word
Method/Member functions:
Unique( ) default constructor
void acceptword ( ) to accept the word in UPPER CASE
boolean checkUnique( ) checks and returns 'true' if the word starts and ends with a
vowel otherwise returns 'false'
void display( ) displays the word along with an appropriate message
Specify the class Unique, giving details of the constructor, void acceptword( ), boolean check Unique( ) and
void display( ). Define the main( ) function to create an object and call the functions accordingly to enable the
task.
OR
(ii) Design a class NoRepeat which checks whether a word has no repeated alphabets in it.
Example: COMPUTER has no repeated alphabets but SCIENCE has repeated alphabets.
The details of the class are given below:
Class name : NoRepeat
Data members/instance variables:
word to store a word
len to store the length of the word
Method/Member functions:
NoRepeat(String wd) parameterized constructor to initialize word = wd
boolean check( ) checks whether a word has no repeated alphabets and returns
true else returns false
void pm( ) displays the word along with an appropriate message
Specify the class NoRepeat, giving details of the constructor(String), boolean check( ), and void pm ( ). Define
the main( ) function to create an object and call the functions accordingly to enable the task.
Question 6.
(i) A class CalSeries has been defined to calculate the sum of the series: [6]
2
sum = 1 + x + x + x 3
+ xn
Some of the members of the class are given below:
Class name : CalSeries
Data members/instance variables:
x integer to store the value of x
n integer to store the value of n
sum integer to store the sum of the series
Member functions/methods:
CalSeries( ) default constructor
void input( ) to accept the values of x and n
int power(int p, int q) return the power of p raised to q ( p1!) using recursive
technique
void cal( ) calculates the sum of the series by invoking the method
powerQ and displays the result with an appropriate message
I SOLVED PAPER - 2021-22 21
Specify the class CalSeries, giving details of the constructor, void input( ), int power(int,int) and void cal( ).
Define the main( ) function to create an object and call the member function accordingly to enable the task,
(ii) Design a class Revno which reverse an integer number.
Example: 94765 becomes 56749 on reversing the digits of the number.
Some of the members of the class are given below:
Class name : Revno
Data member/instance variable:
num to store the integer number
Member functions/methods:
Revno() default constructor
void inputnum() to accept the number
int reverse (int nn) returns the reverse of a number by using recursive technique
void display() displays the original number along with its reverse by
invoking the method reverseQ
Specify the class Revno, giving details of the constructor, void inputnum ( ), int reverse(int ) and void display().
Define the main () function to create an object and call the functions accordingly to enable the task.
Question 7.
A super class Item has been defined to store the details of an item sold by a wholesaler to a retailer. Define a
subsclass Taxable to compute the total amount paid by the retailer along with service tax.
Some of the members of both the classes are given below:
Class name : NoRepeat
Data members/instance variables:
name to store the name of the item
code integer to store the item code
amount stores the total sale amount of the item (in decimals)
Member functions/methods:
Item (...) parameterized constructor to assign value ot the data members
void show( ) to display the item details
Class name Taxable
Data members/instance variables:
tax to store the service tax (in decimals)
totamt to store the total amount (in decimals)
Member functions/methods
Taxable(...) parameterized constructor to assign values to the data
members of both classes
_
void cal tax( ) calculates the service tax @ 10.2% of the total sale amount
calculates the total amount paid by the retailer as (total sale
amount + service tax)
void show( ) to display the item details along with the total amount
Assume that the super class Item has been defined . Using the concept of inheritance, specify the class Taxable,
giving details of the constructor, void cal_tax( ) and void show ( ).
The super class, main function and algorithm need NOT be written.
22 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE Class-XII . I
ANSWERS
Section-A char cl = word.charAt(0);
char c2 = word.charAt(len-l);
1. ( i) Option (b) is correct. if (vowel.indexOf (cl ) > = 0 &&vowel.indexOf (c2)
(ii) Option (b) is correct. > = 0)
(iii) Option (c) is correct return true;
(iv) String str ="SIMPLICITY".substring(6); else
(v) LIFO used in Stack and FIFO used in Queue. return false;
(vi) Output will be : 325 }
(vii) In recursive function, time complexity is much public void display(){
higher than non-recursive function. System.out.println("Word =" + word);
boolean flag = checkUnique();
Section-B if (flag)
Question 2. System.out.println("Word is unique");
else
Finite recursion Infinite recursion
System.out.println("Word is not
In thiskind of In this type of unique");
recursion the process recursion, it does not }
terminates after a terminate after a finite public static void main (String [ ] arg){
finite number of number of recursive Unique obj = new Unique();
recursive calls. calls. obj.acceptword ();
Question 3. obj.display();
P * (Q - R) + S }
}
= P * (- QR) + S (ii) import java.util.Scanner;
= (* P (- QR)) + S public class NoRepeat
= + * P - QRS {
Question 4.
String word;
(i) Sibling of node C is B, and sibling of node E is D. int len;
Predecessor node of B is (D) and successor node public NoRepeat(String wd ){
of B is G. word = wd;
(ii) Inorder traversal of left sub tree is : D B G E len = word.lengthQ;
Pre-order traversal of right sub tree is: C F HI }
private boolean check(){
Section-C for(int i = 0;i < len;i + + ){
Question 5. int c = 0;
(i) import java.util.Scanner; for(int j = 0;j < len;j + + ){
public class Unique if (word.charAt(i) = = word.charAt( j))
C+ +;
{
}
String word;
if (ol)
int len;
return false;
public Unique(){ }
word = ""; return true;
len = 0; }
} public void prn(){
public void acceptword(){ System.out.println("Word =" + word);
Scanner sc = new Scanner(System.in); boolean flag = check();
System.out.println("Enter a word"); if (flag)
word = sc.nextLine(); System.out.println("No repeated character
word = word.toUpperCase(); found");
len = word.lengthQ; else
} System.out.println("Repeated character
found");
private boolean checkUnique(){ }
String vowel ="AEIOU";
void main(String [ ] arg){
I Scanner sc = new Scanner(System.in);
SOLVED PAPER - 2021 -22

static int ans = 0;


23

System.out.println("Enter a word "); public RevnoQ {


String wd = sc.nextLine().toUpperCase(); num = 0;
NoRepeat obj = new NoRepeat(wd); }
obj.prn (); public void inputnum(){
} Scanner sc = new Scanner(System.in);
} System.out.println("Enter a number");
num = sc.nextlntQ;
Question 6.
}
(i) import java.util.Scanner;
public int reverse(int nn){
public class CalSeries
{ if (nn = = 0)
return ans;
intx;
else{
intn;
ans = ans*10 + nn %10;
int sum;
return reverse(nn/10);
public CalSeries(){
}
x = 0;
}
n = 0;
sum = 0; public void display(){
} System.out.println ("Number = " + num);
int rev = reverse(num);
public void input(){
Scanner sc = new Scanner(System.in); System.out.println("Reverse = " + rev);
}
System.out.println("Enter the value of x and
n"); public void main(String [ ] arg){
x = sc.nextlnt(); Revno obj = new Revno();
n = sc.nextlnt(); obj.inputnum();
} obj.display();
public int power(int p, int q){ }
if (q = = 0) }
return 1; Question 7.
else public class Taxable extends Item
return p* power( p,q-l ); {
} double tax;
public static void cal(){ double totamt;
for (int i = 0;i< = n;i + + ){ public Taxable (String nm, int cd, double amt){
super(nm,cd,amt);
sum = sum + power(x,i); tax = 0.0;
} totamt = 0.0;
System.out.println ("Sum of series = " + sum); }
}
public static void main(String [ ] arg){ _
public void cal tax(){
CalSeries obj = new CalSeriesQ; tax = amount * 10.2/100.0;
obj.input(); totamt = amount + tax;
obj.calQ; }
} public void show(){
} super.show();
System.out.println("Service tax " + tax);
(ii) import java.util.Scanner; System.out.println("Total amount = " + totamt);
public class Revno }
{ }
int num;
To get access to ISC Board Specimen Paper 2022 23 - -
Fully Solved , Scan the code below

u
WRITING YOUR NOTES

Just in case you have forgotten today, takedown your notes!


But why is it so important?
Tools for the hands are tools for the brain writes Hetty Roessingh.
Handwritten notes are a powerful tool for encrypting embodied cognition and in turn supporting the
.
brain's capacity for recuperation of information If that sounds so scientific then in simple words:
Writing notes by hand help you in:
Increasing your comprehension Strengthening your memory Igniting your creativity
Engaging your mind Increasing your attention span
Are these reasons enough to get you started?

1.
2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16 .

17.

18.

19.

20.
Section A

CHAPTER

1 BOOLEAN
ALGEBRA
B (a) Propositional logic, well formed formulae, truth values and
interpretation of well formed formulae (WFF ), truth tables, satisfiable,
unsatisfiable and valid formulae. Equivalence laws and their use in
'simplifying WFFs. ( b ) Binary valued quantities; basic postulates of Boolean algebra; operations AND, OR
'and NOT; truth tables, ( c ) Basic theorems of Boolean algebra (e.g. Duality, idempotence, commutativity,
'associativity, distributively, operations with 0 and 1, complements, absorption, involution ); De Morgan' s
[theorem and its applications; reducing Boolean expressions to sum of products and product of sums forms;
!Karnaugh maps (up to four variables ).
[
-
*Note These Concepts are only for your reference. Questions from these parts will not be asked in the Final Examination.

Im
Propositional Logic Topic - 1
Concepts covered: Propositional Logic;
Topic -1 NegationConjunctionJDisgunctionConditional;
Propositional Logic
.
Page No 01
bi-conditional;truthtable;equivalencelawsof
propositions. Topic-2
Theorems and Postulates of
Boolean Algebra
.
Page No 12

Revision Notes Topic - 3


Forms of Representing
> A proposition is a declarative sentence that is either 'True' or 'False' but Boolean Expressions
not both. Propositions are also called statements. .
Page No 22
For example, Topic-4
.
1 The Sun sets in the East direction.
Karnaugh Map ( K-map)
(It is a proposition with false value)
.
Page No 28
> Logical Connective (Operators): For combining two or more statements
we use special symbols, called logical connectives. There are several logical connective as follows:
• Negation (NOT): If S is a statement or proposition, then NOT (S) or (S) is negation of proposition S.
For example,
S: Ram eats the mango.
Not (S): Ram doesn't eat the mango.
• Conjunction (AND): If R and S are two propositions, then R and S are connected by 'AND' or V symbol.
For Example,
R: He is a player.
S: He plays football very well.
R A S: He is a player AND he plays football very well.
JO
I
liable I (a variable or literal that can have 9
I a value either 0 or 1). I
°L
n
O
fD
Boolean Expression (Sequence of Boolean variables / VI

I values connected using logical operators) §


U3
Multiplicative, 0.p =0 j eg. P = Q + R QJ

A"
Additive, 0 + p = p
Identity (Idempotent La n
r w) g
Boolean laws P +P= P
£aivo/ Cn {p . p=p I
£
Multiplicative, l.p- p fi?
Additive, l + p = l o '
P + P -l .
*I
{.= p p' 0 p
a&
a 82
p + q=q+ p
1
p.q = q.p (p+ ql -p' q
- 7J
{ (p q)' = p’+ q'
- n
m
Z
n
p + (q + r ) = ( p + q ) + r
p.(q.r ) = (p.q).r ST

p.(q + r) = ( p.q) + (p.r) { (P’) = P U


p + (q.r ) = ( p + q).(p + r)
Converting AND(.) to OR ( + ) p+ (p.q) = p
Converting OR( + ) to AND(.) { p.(p + q) = p
Converting 0 to 1 First Level Second Level Third Level

Converting 1 to 0
}
(Sum terms are called maxterms) (Product terms are called minterm )
eg. (P + Q + R ), (P’ + Q + R') eg. (PQ.R), (F.Q.R )-

0
tSuins) Jo'imt of {Boolean
Ixp'ienion

(Disjunction of minterms)
(Conjunction of maxterms) , ,
, eg. S1= EQ.R + F.Q .R + PQ'.R’
eg. P1= (A + B + C).(A + B' + C').(A' + B + C).(A' + B + C)
S2= Z(l,3,6,7)
/
P2= 71(2,3 5,7)

co
O
O
(A way of representing each term as a maxterm or (only the term numbers are used) G
>
a minterm not contains all the variables) eg. 1 Cardinal form of A'.B' + A'B + AB is Z(0,l,3) Z
eg. 1 A' B’ + A'B + A.B >
eg. 2 Cardinal form of (A + B + C'XA + B' + C'MA' + B' + C) 5
eg. 2 (A + B + C).(A + B' + C).(A' + B' + C) m
is 71(1,3,7) co
£
Trace the Mind Map (f
First Level Second Level
^
Third Level
CO
4 .
Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE Class- XII
I
I

v
£

£ o

I!
iffi
£ S »5 M D

l l III
I1 I ? S

I
V%
2 pair
An arrangement of variables of
CD' C'D CD CD' an exp such that simplication can
A'B' :1 1 l i| be done by minimising the terms.
eg - A'B 0 0 0 0
'
AB :T r 0 0
AB' :l 1 0 0
Developed by
8& JCaxnaugA’a Map Mr. Maurice Karnaugh
CD ' ' C'D CD CD' O
ME %
A'B' I 1 l i; 31- Map
e - g. A'B 1 1 1 l:
#
AB 0 0 0 0 Variables A B B [0] B [11
AB' 0 0 0 0 B [0] B' [1] A' [0] A'B' A' B 1
A B 0
K-Map of sum of A[l ] AB'
A [0] A + B A + B' 2
AB 3
0 1 Product Form (SOP)
A [1] A + B A + B'
2
K-Map of Product B'C' B'C BC BC '
B +C B +C B + C' B' + C' B' + C of Sum Form (POS) [0 0] [01] [Oil [101
A [001 [01] [11] [10] A'B'C' A'B'C A'BC A'BC '
A + B + C A + B + C' A + B' + C ' A + B' + C A' [0]
A [0] 0 1 3 2
0 1 3 2 AB'C' AB'C ABC ABC '
A [1]
A' + B + C A' + B + C' A' + B' + C ' A' + B' + C 4 5 7 6
A' [l]
4 5 7 6

C'D' C'D CD CD'


C+D C+ D C + D' C' + D' C' + D
[0 0] [0 1] [11] [1 0]
A+ B [0 0] [0 1] [1 1] [1 0]
A+B A + B + C + D A + B + C + D' A + B + C' + D' A + B + C' + D A'B' A'B'C'D' A'B'C'D A'B'C D A'B'C D'
[0 0] [0 0] 0 1 3 2
0 1 3 2
A + B' A + B' + C + D A + B' + C + D' A + B' + C' + D' A + B' + C' + D
A'BC'D A'B CD A'BC D' CO
[0 1]
A'B [0 1] A'BC'D'
4 5 7 6 O
4 5 7 6 O
A' + B' A' + B' + C + D A' + B' + C + D' A' + B' + C' + D' A + B' + C' + D AB ABC'D' ABC'D ABCD ABC D' m
[1 1] [11] 13 >
12 13 15 14 12 15 14 Z
A' + B A' + B + C + D A' + B + C + D' A' + B + C' + D' A' + B + C' + D AB' AB'C'D' AB'C'D AB'CD AB'C D' >
[ 1 0] 8 9 11 10 [1 0] 8 9 11 10 o
m
J co
£
Trace the Mind Map
First Level Second Level Third Level
^
Note : For minimising the terms, First we make all possible octets, them all possible quads and the last all possoble pairs .
01
6 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

• asDisjunction (OR): It is represented by 'OR' or V symbol. Let R and S be two propositions. Then R v S is read
I
R or S.
For Example,
R: She is a player.
S: She is a dancer.
R v S: She is a player OR dancer.
• Conditional (=> ): A —> B is called a conditional statement. It is also read as 'A implies B'.
For Example,
A: You will do hard work.
B: You will get success.
A —> B: If you will do hard work, then you will get success.
• Biconditional (<=>): A o B is known as biconditional statement or proposition. ' o ' or '<=>' shows equivalence
relation between two propositions.
For example:
A: She is smart.
B: She is beautiful.
A —> B: She is smart as well as beautiful.
• Truth Table: A table used to determine all possible truth values regarding a proportional value. A single
proposition contains two possible values as 'True' for correct and 'False' for incorrect value. True value (denoted
by 1) or false value (denoted by 0) are called 'truth values'.
We can determine the truth values of the various connections as follows:

P q ~P ~P PM pvq p => q p«q


0 0 1 1 0 0 1 1
0 1 1 0 0 1 1 0
1 0 0 1 0 1 0 0
1 1 0 0 1 1 1 1
Table: Truth Table for connectives
• Other important Terminology:
Well formed formula (WFF): It refers a simple proposition and compound proposition. A WFF can be
determined with the help of following properties:
If p is a propositional variable, then it is a WFF.
- If p is WFF, then Ap is a WFF.
- If p and q are WFF, then ( p A q), (p v q), p => q, p <=> q are WFF.
Tautology: A compound proposition that is always 'True'.
Contradiction: Negation of tautology is termed as contradiction.
Contingency: A compound proposition that is neither tautology nor contradiction.
For Example:
p v p, is a tautology, p A p, is a contradiction and p v p, or p A p, is a contingency.
Argument: Sequence of statements (premises). An argument is valid if it is a tautology, otherwise it is
fallacy, (non-valid ).
Syllogism: A Logical process of drawing conclusions from given premises.
Converse: The converse of p —> q is q —> p.
Inverse: The inverse of p —> q is p —> q,
Contra positive: The contra positive of p —> q is q —> p.
• Some basic Equivalence Laws of Propositions:
Commutative Law:
pvqoqvp and p A q <=> q A p
Distributive Law:
p A (q v r) o (p A q) v (p A r) and p v (q A r) <=> ( p v q) A (p v r)
De Morgan's Law:
~ (p A q) o ~ p v ~q and (p v q) o ~ p A ~q
I Involution Law: ~ ( ~ p) <=> p
BOOLEAN ALGEBRA 7

Absorption Law: p v ( p A q) <=> p and p A (p v q) <=> p


p => q = ~ p A q
-
p A T = p a n d p V F = p ; p T = T a n d p A F = F.
P » P = (P -> q) A (q -> p)

|Key Terms
> Logic means some rules which can be applied over an expression to find its optimal solution.
> Mathematical logic is used in designing the circuits in the computer system.
> Propositional logic is a declarative statement with two possible values either 'True (01)' or 'False (0)' but not both.
> AND (A), OR (V), Not ( ~ ), conditional ( —>) and biconditional (<->) are logical connectives. With the help of these
connective, compound statements are created.
> If there are n-variables in the expressions, then it contains 2n possible combination of their values.
> Tautology: A compound statement having all its possible values become True.
> Contradiction: A compound statement that is always False.
> Contingency: A compound statement that is neither True nor False.
> Argument: An argument is valid if it is a tautology.
> Syllogism: Logical process of drawing conclusion from given propositions.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


.
Q. 1 The Boolean equation which holds true for the consequent of the original conditional statement
Involution Law is: - -
[ISC Sem 1 Paper 2021 22] and consequent as negative antecedent of the
(A) A' + l = l (B ) ((A + B)')'= A + B original conditional statement.
(C) (A + B)' = A'.B' ( D ) A.(B + C) = (A + B).C Q. 5. The proposition (P = > ~ Q) v( ~ P = > Q) is a:
.
Ans Option ( B) is correct. -
[ISC Sem 1 Paper 2021 22]-
Explanation:ln Involution law (a')' = a. Here in (A) Contradiction (B ) Tautology
option B ((A + B)')' = A + B (C) Implication (D) Contingency
Q. 2. The propositional operator ~
represents: Ans. Option (B ) is correct.
- -
[ISC Sem 1 Paper 2021 22] Explanation: In truth table value of P —» Q' is 1, 1,
(A) Negation (B) Implication
— —
1, 0 and the value of P' » Q is 0, 1, 1, 1. P » Q' v
(C) Conjunction
Ans. Option (C) is correct.
( D) Disjunction —
'P' » Q will be 1, 1, 1, 1 which is tautology.
Q. 6. Conjunction (AND ) is denoted by which symbol?
~
Explanation:This symbol ( ) will represent AND (A) A (B ) v
in Boolean algebra which is known as Conjunction.
(C) => (D ) «
..
Q 3 Given the proposition A = > ~ B, find the inverse Ans. Option (A) is correct.
of the proposition: - -
[ISC Sem 1 Paper 2021 22]
(A ) ~ A = > B
(C) ~ A = > ~ B
(B ) B = > A
(D) ~ B = > A
— Explanation: If p and q are two propositions, then
conjunction of p and q is denoted by ( p A q) or
(p A q) and is read as p and q. The compound
Ans. Option (A ) is correct.
statement p A q is true when both p and q are true,
Explanation: The inverse of a given conditional otherwise it will result false.
statement is a new condition whose antecedent
and consequent are the negation of the original Q. 7. Which of the following are used to determine all
conditional statement. the possible truth values regarding a proportional

positive of the proposition:



Q. 4. Given the proposition A = > B, find the contra-
variable?
(A) Tautology (B ) Contradiction
[ISC Sem-1 Paper 2021-22] (C) Truth table (D) Contingency
(A ) ~ A = > B (B ) B = > ~ A Ans. Option (C) is correct.
(C) ~ B = > A (D ) ~ A = > ~ B Explanation: Truth table are used to determine all
Ans. Option (B ) is correct. the possible truth values regarding a proportional
Explanation: A new conditional statement variable. Every simple or compound proportion
obtained whose antecedent is the negation of the may take either true or false value. These true
value or false value are called truth values.
8 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 8. If equation P -> Q implies to ~ Q - > ~ P then
I
produces another logical value. A logical operation
which implication suits it? that is done on a single logical value can deal with
(A) Converse (B ) Inverse only two circumstances, i.e. true or false.
(C) Contra positive (D) None of these Q. 12. Which of the following represents the disjunction?
Ans. Option (C) is correct. (A) PAQ (B ) PvQ
Explanation: Contra position refers to the (C) P Q (D ) P • Q
inference of going from a conditional statement Ans. Option (B ) is correct.
into its logically equivalent contrapositive and Explanation: If P and Q are two propositions then
an associated proof method known as proof of disjunction of P and Q is denoted by (P v Q) or
contraposition. The contrapositive of a statement (P + Q) and is read as 'P OR Q'. The statement
has its antecedent and consequent inverted P v Q is always true if at least one of P and Q
and flipped. The contrapositive of P —> Q is the propositions is true.
implication -• Q —> ~ P
Q. 13. Proportions are also called
Q. 9. The operator, negative is denoted by
(A ) ~ p
(C) p
(B ) - p
(D) All of these
(A) Sentences (B ) Statements
(C) Both (A) and (B) (D) None of these
Ans. Option (C) is correct.
Ans. Option (D) is correct.
Explanation: The propositional logic represents
Explanation: If p is any proposition, the negation logic through prepositions and logical connectives.
of p, denoted by ~ p or -> p or p' or p and read as A proposition is a declarative sentence that is
not p. This proposition is false when p is true and either true or false but not both. Propositions are
proposition is true when p is false. also called sentences or statements.
Q. 10. If A and B are two inputs and F = A + B is an Q. 14. Which of the following is an expression that
output of its operation. Which operator is using in results in a Boolean value, i.e. either true or false?
this output? (A) Duality (B ) Maxterm
(A) AND (B ) OR (C) Minterm (D) Boolean expression
(C) NOT (D) XOR
Ans. Option (D) is correct.
Ans. Option (B ) is correct.
Explanation: A Boolean expression is an expression
Explanation: An OR operator, can have two or that results in a Boolean value, i.e. either true
more inputs and one output, it performs an or false. It is a logical expression that is used
operation known as logical addition. to compare Boolean variables. It is also called
Expression for OR operator is F = A + B, where comparing expression, conditional expression and
A and B are two inputs and F is an output of its relational expression.
operation. Q. 15. When a compound proportion is a contradiction
Q. 11. Which of the following is an operation, which then, it is called
takes one or more logical values and produces (A) Satisfiable (B ) Contingency
another logical value? (C) Unsatisfiable (D) Tautology
(A) Truth table Ans. Option (C) is correct.
(B ) Boolean variable
(C) Logical operation Explanation: When the compound proportion
(D) Logical statements is false for all assignments of truth values, the
compound proposition is known as unsatisfiable.
Ans. Option (C) is correct. When a compound proposition is a contradiction
Explanation: A logical operation is an operation, then, it is called unsatisfiable.
which takes one or more logical values and

yf SUBJECTIVE TYPE QUESTIONS


Q. 2. Show that X v - (Y A X) is a tautology. [ISC 2016]
Short Answer Type Ans. X v ~ (Y A X)
<©> Questions I -(2 8 3 marks)
Q. 1. If (P => Q ) then write its [ISC 2017]
X
0
Y
0
YAX
0
-
(YAX) X V ~f f A I
1 1
(i) Inverse (ii) Converse 0 1 0 1 1
Ans. (i) Inverse —— P => ~ Q
(ii) Converse Q => ~ P
1
1 1
0 0
1
Hence, it is a Tautology.
1
0 1
1

[ISC Marking Scheme, 2016]


BOOLEAN ALGEBRA 9
Ans.
Examiner's Comment A B Conjunction A B Disjunction
0 0 0 0 0 0
w Most of the candidates answered this part
0 1 0 0 1 1
correctly. Some candidates were confused with
symbols V and V and interchanged them in 1 0 0 1 0 1
the truth table. Some proved it with the help of 1 1 1 1 1 1
Boolean laws. [ISC Marking Scheme, 2014]

Answering Tip
Answering Tip
w Students should learn all the propositional logic
; !r - Learn Proposition logic using all the terms that
are required, especially the terms conjunction,
with appropriate symbols and truth tables. i j disjunction, negation, implications and
' ! biconditional.
Q. 3. Draw the truth table to prove the proportional
logic expression.
(X => Y) A (Y => X ) = X <=> Y
Q. 7. Using a truth table verify: [ISC 2013] #
p = (p A ~ q) v (p A q)
( ~ P => q) A

0
[ISC Specimen Question Paper 2016]
Q. 8. If (X => Y) then write its
Q. 4. Verify the following proposition with the help of
a truth table. (i ) Converse (ii) Contrapositive [ISC 2012]
P - ( ~ P A Q) = P - Q [ISC 2015] Ans. (i ) Converse Y » X —
Ans. Proof of P v ( ~ P A Q) = P v Q (ii) Contrapositive Y X
L.H.S. R.H.S. Q. 9 . Using truth table, verify whether the following is
true or false: [ISC 2011]
P Q ~P ~P A Q P V ~P A Q PVQ
L.H.S. R .H.S.
0 0 1 0 0 0
(p ^ q) = (q => p)
0 1 1 1 1 1 Ans.
1 0 0 0 1 1
p q p => q q p q => p
I I o o I I
0 0 1 1 1 1
Q. 5. Differentiate between a proposition and WFF. 0 1 1 0 1 1
[ISC 2014]
1 0 0 1 0 0
Ans. Proposition: A statement that can have only two
possible answers (True or False). 1 1 1 0 0 1
WFF: It is a proposition which is satisfiable or L.H.S. R .H.S.
valid . [ISC Marking Scheme, 2014]
Q. 10. Using a truth table, verify if the following
proposition is valid or invalid [ISC 2013]
( =* ) ( => ) = ( => )
a b A b c a c
Examiner's Comment
Ans.
w A number of candidates gave the full form of WFF. —
a b c a > b b -> c (a » b) A (b -»c) (a > c) —
Some candidates wrote the same definition for —
both. 0 0 0 1 1 1 1
0 0 1 1 1 1 1
0 1 0 1 0 0 1
Answering Tip
o l l l l l l
w More practice should be given in the chapter of l 0 0 0 1 0 0
propositional logic and the various terms used 1 0 1 0 1 0 1
must be learnt with examples.
1 1 0 1 0 0 0
Q. 6. Write the truth table for a 2-input conjunction and 1 1 1 1 1 1 1
disjunction in a proposition. [ISC 2014] Hence , the given proposition is invalid.

These questions are for practice and their solutions are available at the end of the chapter
10 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 11. Verify if, p • ( ~ p + q') = (p => q) ' using truth (ii) The truth table for p <=> q, i.e., bi-directional
I
table. [ISC 2010] between p and q.
Ans. Here, we have two input variables, i.e., p and q. To q p«q
P
satisfy this expression, take L.H.S. = p • ( ~ p + q ')
and R.H.S. = ( p => q) ' 0 o I
Now, formed the truth table, o I o
p q ~p q' ( ~ p + q ) p ( ~ p + q ) p => q (p ^ q) '

I o o
o0 1 1 1 0 1 0
1 1 1
01 1 0 1 0 1 0
Q. 13. Using the truth table verify p • q + p • q ' = p.
10 0 1 1 1 0 1
Ans. Given expression is p • q + p • q' = p
11 0 0 0 0 1 0 Here, we have two input variables, i.e., p and q.
L.H.S. R.H.S. To satisfy the given expression, we take
From the above truth table, we can see that both L.H.S. = p • q + p • q "
L.H.S. and R.H.S. possess same truth values. So, and R.H.S. = p
expression is verified. Now let us form the truth table.
Q. 12. Draw the truth tables of the propositional logic
expression p => q and p <=> q. [ISC 2008] p q p q q' p q' -
p q + p q' -
Ans. Here, we have two input variables, i.e., p and q. 0 0 0 1 0 0
(i) The truth table for p => q, i.e., implication
between p and q. 0 1 0 0 0 0
p q p => q 1 0 0 1 1 1
0 0 1 1 1 1 0 0 1
0 1 1
1 0 0 R.H.S. L.H.S.
1 1 1 So, p • q + p • q ' = p Hence Proved.
Q. 14. Using the truth table, prove that ( A + B ) ' + ( A + B ') ' = A '. [ISC 2006]
Ans. Given expression, (A + B) ' + (A + B ') ' = A '
Here, we have two input variables, i.e., A and B.
To satisfy this expression, we take L.H.S. = (A + B) ' + (A + B ') ' and R.H.S. = A'
Now, let us form the truth table,
A B A+B (A + B ) ' B' A + B' (A + B ') ' ( A + B) ' + (A + B ') ' A'
0 0 0 1 1 1 0 1 1
0 1 1 0 0 0 1 1 1
1 0 1 0 1 1 0 0 0
1 1 1 0 0 1 0 0 0
L.H.S. R.H.S.
From the above table, we can see that both L.H.S. and R.H.S. possess same truth values. Hence, it is proved.
Q. 15. Prove that [(p' + q) • (q' + r)]' + (p' + r) = 1 [ISC 2006]
Ans. Here, we have three input, i.e., p, q and r. Now, let us form the truth table.
p q r P q ' p + q q ' + r ( p ' + q) ( q ' + r ) l ( p ' + q ) - ( q + nr p ' + r [(p ' + q) (q ' + r)]' + ( p ' + r)
0 0 0 1 1 1 1 1 0 1 1
0 0 1 1 1 1 1 1 0 1 1
0 1 0 1 0 1 0 0 1 1 1
0 1 1 1 0 1 1 1 0 1 1
1 0 0 0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0 1 1 1
1 1 0 0 0 1 0 0 1 0 1
1 1 1 0 0 1 1 1 0 1 1
I BOOLEAN ALGEBRA 11

<©> Short Answer Type


Questions-II (4 marks each)
Q. 1. State whether the following expression is a Tautology, Contradiction or a Contingency, with the help of a
truth table:
(X => Z ) v ~[(X => Y) A (Y => Z )] [ISC 2016]
Ans. Expression: (X => Z) v ~[(X => Y) A (Y => Z)]
A B C D
X Y Z D' A + D'
X^Z X => Y Y => Z (X => Y) A (Y => Z)
0 0 0 1 1 1 1 0 1
0 0 1 1 1 1 1 0 1
0 1 0 1 1 0 0 1 1
0 1 1 1 1 1 1 0 1
1 0 0 0 0 1 0 1 1
1 0 1 1 0 1 0 1 1
1 1 0 0 1 0 0 1 1
1 1 1 1 1 1 1 0 1
Hence, it is a Tautology. [ISC Marking Scheme 2016]
Ans. Here, we have three input variables, i.e., a, b, and c.
Examiner's Comment =
To satisfy this expression, take L.H.S. = (a > b) A (b
> c) and R.H.S. = (a => c)
=
w Most of the candidates answered this part well. Now, formed the truth table,
Some did not mention whether it was a Tautology,
a b c a => b b => c (a => b) A (b > c) a => c
Contradiction or a Contingency. Some were not =
clear with the symbols V and 'A'. 0 0 0 1 1 1 1
0 0 1 1 1 1 1
..
Q 2 Define proposition. How does tautology differ
from contradiction ? 0 1 0 1 0 0 1
[ISC, Specimen Question Paper 2016] 0 1 1 1 1 1 1
Ans. Proposition Boolean algebra is based on
1 0 0 0 1 0 0
propositions, which are non-ambiguous sentences
that can be either True or False. One can combine 1 0 1 0 1 0 1
these propositions in a variety of ways by using 1 1 0 1 0 0 0
the connectives AND and OR, or one can negate
them by preceding them with not. The results of 1 1 1 1 1 1 1
these operations on propositions are dictated by L.H.S. R.H.S.
the rules of Boolean algebra. From the above truth table, we can see that (a => b)
Difference between tautology and contradiction: A (b => c) and (a => c) do not possess same truth set

Tautology Contradiction value. So, it is proved that is a invalid proposition.


A propositional expres - A propositional expres- Q. 4. Define the terms Contingency, Contradiction and
sion is a tautology
if and only if for all
sion is a contradiction
if and only if for all
Tautology. 0 [ISC 2012]
Q. 5. Verify if the following proposition is valid.
possible assignments possible assignments
of truth values to its of truth values of its (a => b) A (a => c) = a => (b A C) [ISC 2011]
variables is T. variables is F. Ans. From the given expression, we have three input
Q. 3. Using a truth table, verify if the following variables, i.e., a, b and c. To satisfy this expression,
proposition if valid or invalid [ISC 2013] take L.H.S. = (a => b) A (a => c) and R.H.S. = a =>
(b AC).
(a => b) A (b => c ) = (a => c )
Now, formed the truth table
These questions are for practice and their solutions are available at the end of the chapter
12 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

(a=>b) a => 1 0 1 0 1 0 0 0
I
a b c a=>b a => c (b.c )
.(a=>c) (b Ac) 1 1 0 1 0 0 0 0
0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1
0 0 1 1 1 1 0 1 L.H.S. R.H.S.
0 1 0 1 1 1 0 1 From the above table, we can see that both L.H.S.
0 1 1 1 1 1 1 1 and R.H.S. possess same truth values. So, it is a
1 0 0 0 0 0 0 0 valid proposition.
Q. 6. State whether the following expression is a tautology or contradiction with the help of truth table.
[ISC 2010]
(X » Z ) • [(X => Y) • (Y => Z)1
Ans. For the above equation, we have three inputs for truth table, i.e., X, Y and Z.
Truth table for given expression is
X Y Z X => Y Y => Z (X => Y) • (Y => Z) X«Z (X <=> Z) • [(X => Y) • (Y => Z) ]
0 0 0 1 1 1 1 1
0 0 1 1 1 1 0 0
0 1 0 1 0 0 1 0
0 1 1 1 1 1 0 0
1 0 0 0 1 0 0 0
1 0 1 0 1 0 1 0
1 1 0 1 0 0 0 0
1 1 1 1 1 1 1 1
From the above truth table, we can clearly see that all the values of last column are neither all l 's nor 0's. Hence,
the given expression is neither tautology nor contradiction.

I Topic - 2 Theorems and Postulates of Boolean Algebra


Concepts covered: Boolean Algebra; Laws of Boolean algebra.

Revision Notes
> Boolean Algebra is an algebra given by George Boolean which uses 0 and 1 as binary variables, and three basic
operations OR, AND and NOT.
> Laws of Boolean Algebra
S. No. Theorem /Laws Expression Dual
1. Identity law A+0 =A A 1=A

2. Complementary law A + A' =1 AA ' =0


3. Commutative law A+B=B+A AB = B • A
4. Associative law A + (B + C) = (A + B) + C A • (B • C) = (A • B) • C
5. Distributive law A + (B • C) = (A + B) • (A + C) A • ( B + C) = (A • B) + (A • C)
6. Idempotence law A+A=A A •A = A
7. Absorption law A + (A • B) = A A • (A + B) = A
8. DeMorgan's law (A + B) ' = A ' • B ' (A • B) ' = A ' + B '
9. Third distributive law A + (A ' B) = A + B

> Principle of Duality: It states that a Boolean relation can be obtained by changing OR by AND and Vice-versa.
For example,
(i) Dual of X + Y • Z is X • (Y + Z).
-
(ii) Dual of O is always 1 and Vice versa.
I BOOLEAN ALGEBRA 13

|Key Terms
> Basic Postulates:
A+0=0+A=A 0 + l = l;a + 0 = 0
A.l = 1 A A = A 0 A1 = 0 ;1 + 1 = 1
A + A = A; A.A = A
A + A- = 1; A.A = 0
(A) = A
> De Morgan's Theorem: The complement of the sum of variables is equal to the product of the complement of the
variables.
> (A + B) = A . B or (A . B) = A + B

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. The dual of the Boolean equation Ans. Option ( C) is correct.
(X + Y)' + ( X'.Y') + 1 = 1 is: Explanation:After compliment using De'Morgans
[ISC Sem-1 Paper 2021-22] law which is change AND into OR and vice versa
(A) (X.Y)'.(X' + Y').0 = 0 it produce option C.
( B) (X + Y).(X'.Y') +1=1 (P + ((Q + R).(Q' + S')))'
(C) (X.Y).(X + Y).0 = 0 = P'.(Q + R ) ' + ( Q' + S' ) '
( D) (X.Y)'.(X' + Y').1=1 [De'Morgans law ]
Ans. Option ( A ) is correct. = P'.(Q'R' + QS)
Explanation: In duality, change AND into OR and Q. 5. Given the Boolean expression F = P + ((Q + R).
vice versa. Similarly 0 into 1 and 1 into 0. For this (Q' + S')). De Morgan's law states that the
given equation dual of the expression will be (XY)'. complement of a sum is equal to:
(X' + Y').0 = 0 i.e., option (a). [ISC Sem-1 Paper 2021-22]
Q. 2. The simplified expression for the Boolean (A) the complement of their product
expression PQ.(PQ + QR ) is: (B) the product of their individual complements
[ISC Sem-1 Paper 2021-22] (C) the sum of their individual complements
(A) P ( B) 1 (D ) the complement of their sum
(C) PQ (D) QR Ans. Option ( B ) is correct.
Ans. Option (C) is correct. Explanation: De Morgan's law states that the
Explanation: Using Distributive law it will produce complement of a sum is equal to the product of
PQ as output. their individual complements, e.g. (A + B)' = A'.B'.
Q. 3. The reduced expression of the Boolean function Q. 6. Reduce the given Boolean function F(A,B,C,D)
F = A ( B + C( AB + AC)') is: = S(6,7,10,11,12,14,15) by using 4-variable Karnaugh
[ISC Sem-1 Paper 2021-22] map. What is the reduced expression of the Boolean
function given below? [ISC Sem-1 Paper 2021-22]
(A ) 1 (B) AB
( A) ABD' + ACD' + BCD' + AC'D'
(C) 0 ( D) A'C + AB'C
(B ) (B + C).(A + C).(A + B + D')
Ans. Option (B ) is correct. (C) AC + ABD' + BCD'
Explanation: (D) BC + AC + ABD'
A(B + C(AB + AC)') = AB + AC(A(B + C))' Ans. Option (D) is correct.
= AB + AC(A' + (B + C)') Explanation: Reduced expression will be BC + AC
= AB + ACA' + ACB'C' + ABD' (Which is nearer to Option (D) is correct.)
(Using De'Morgans law) Q. 7. Reduce the given Boolean function F(A,B,C,D)
= AB + 0 + 0 = p(3,4,5,6,7,10,12,13,14,15) by using 4-variable
= AB Karnaugh. What is the reduced expression of the
Boolean function given above?
Q. 4. Given the Boolean expression F = P + ((Q + R).
[ISC Sem-1 Paper 2021-22]
(Q' + S')). Identify the complement of the
expression: [ISC Sem-1 Paper 2021-22] (A) (A' + C').(C' + D).(A' + C' + D).(A + C + D')
(A) P' + (Q'R' + QS) (B ) P'. (QR + Q'S') (B ) B'.(A' + C' + D).(A + C' + D')
(C) P'. (Q'R' + QS) (D) P'QR + P'QS (C) B'.(A' + C').(C' + D')
(D) (A' + C' + D).(A + C + D').(A + B' + C).(B' + C + D')
14
.
Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class- XII
Ans Option (B) is correct . . .
Q 11 Which of the following is the simplify form of
I
Explanation: From Octet output will be B' and F = A • B (A • B + B • C)?
from 1st pair output will be (A + C' + D') and from (A) F = A • B (B) F = B • C
2nd pair output will be (A' + C' + D). (C) F = A • C (D) All of these
..
Q 8 Choose the name of correct law which states .
Ans Option (A) is correct .
following A + (B + C) = (A + B) + C Explanation:
(A) Commutative law(B) Involution law F = A • B(A • B + B • C)
(C) Associative law (D) Distributive law
.
Ans Option (C) is correct . = (A • B) (A • B) + (A • B) (B • C)
[By distributive law]
Explanation: Associative law of addition states that
OR ing more than two variables i.e. mathematical = (A B) + (A B) (B C) [By idempotent law]
• • •

addition operation performed on variables will = (A • B) + (A • B C) [idempotent law]


return the same value irrespective of the grouping = (A B).(l + C)
• [By distributive law]
of variables in an equation. It involves in swapping
of variables in groups. = (A • B).l [prop, of 1]
F = (A • B) [By absorption law]
..
Q 9 Find the dual of A + (A • B ) = A
(A) A • (A • B) = A (B) A + (A + B) = A . .
Q 12 Which of the following is the simply form of
(C) A • (A + B) = A (D) A • (A + B) = 0 xy + xz + xyz?
.
Ans Option (C) is correct . (A) xy (B) xz
(C) xyz (D) x(y + z)
Explanation: The principle of duality states that a
Boolean relation can be derived by .
Ans Option (D) is correct .
(A) Changing every OR ( + ) by AND (•) Explanation:
(B) Changing every AND (•) by OR ( + ) F = xy + xz + xyz
(C) Changing every 0 by 1 and by 0 = xy + xyz + xz
The duality of A + (A • B) = A is A • (A + B) = A = xy (1 + z) + xz
. .
Q 10 Which of the following is an example of first De = xy (1) + xz
Morgan's Theorem? = xy + xz
(A) (A + B) = A • B (B) A • B = A + B F = x(y + z)
(C) X = X (D) (A + B) = A • B Q. 13. Which law is stated the A + B = B + A?
.
Ans Option (D) is correct . (A) Absorption law (B) Commutative law
Explanation: The complement of sum of variables (C) Distributive law (D) Involution law
is equal to the product of the complements of
individual; variables, i.e. the complement of two
.
Ans Option (B) is correct .
or more OR variables is equivalent to the AND of Explanation: Commutative law states that the
the complements of the individual variables, i.e. interchanging of the order of operands in a
(A + B + C + .... + F)' = A • B' • C' F' Boolean equation does not change its result.
eg - A+B =A B -
De Morgan's law I • A+B=B+A
A • B = A + B De Morgan's law II • A*B = B*A

yf SUBJECTIVE TYPE QUESTIONS


[ISC 2020]
Short Answer Type
Questions I -
(2 8 3 marks)
Ans. F(P,Q,R) = P + (Q ' • R)
= (P + (Q ' - R)) '
..
Q 1 State the properties of zero in Boolean algebra . | P ' ;{<T - R) '
[ISC 2020] = P ' • (Q + R ' )
.
Ans Properties of zero: [ISC Marking Scheme 2020]
A+0 =A ..
Q 3 Find the dual of: (A ' + 0) • ( B + 1) =A '

and A O = 0 [ISC Marking Scheme 2020]


%
> [ISC 2020]
..
Q 2 Find the complement of the following Boolean ..
Q 4 Simplify the following expression using Boolean
expression using De Morgan's law: laws:
F(P,Q,R) = P + (Q • R) F = [(X ' + Y) • (Y ' + Z ) ]' + (X ' + Z)
[ISC 2020]
These questions are for practice and their solutions are available at the end of the chapter
I BOOLEAN ALGEBRA 15

Ans. Simplify :
[(X ' + Y) -(Y ' + Z)]' + (X ' + Z)
= (X ' + Y) ' + (Y' + Z) ' + ( X' + Z)
= XY' + YZ' + X ' + Z
w
I Answering Tip
Students should learn to find out the principle of
duality in the order of their precedence.
= X ' + XY' + Z + YZ'
= (X ' + X)- (X ' + Y') + (Y + Z)-(Z + Z') Q. 9. State Associative law and prove it with the help of
= X' + Y' + Z + Y a truth table.[ISC, Specimen Question Paper 2016]
= 1 as ( Y + Y' = 1) Ans. Associative law states that
[ISC Marking Scheme 2020] i.e., X + (Y + Z) = (X + Y) + Z
Q. 5. State the principle of Duality. [ISC 2017] Truth table for X + (Y + Z) = (X + Y) + Z
Ans. Principle of duality states: X Y Z Y + Z X + Y X + ( Y + Z ) ( X + Y) + Z
(1) Change all 0's to l's and l's to 0's. 0 0 0 0 0 0 0
0 0 1 1 0 1 1
(2) Change all to ' + ' and ' +' to
0 1 0 1 1 1 1
Q. 6. Find the complement of the following Boolean 0 1 1 1 1 1 1
expression using De Morgan's law. [ISC 2017] 1 0 0 0 1 1 1
F(a, b, c ) = (b + c) + a
' 1 0 1 1 1 1 1
Ans. ((b' + c) + a)' = (b' + c)' • a' 1 1 0 1 1 1 1
1 1 1 1 1 1 1
= b • d a'
Both the columns X + (Y + Z) and (X + Y) + Z are
Q. 7. State involution law and prove it with the help of
identical.
a truth table. [ISC 2016]
Ans. Involution Law states that the double complement of Q. 10. Find the dual for the Boolean equation:
a variable returns the same variable, i.e., AB ' + BC' + 1 = 1
(A') ' = A [ISC, Specimen Question Paper 2016]
Truth Table Q. 11. Minimise F = XY + (XZ ) ' + XY 'Z using Boolean
A A '
(A )' ' laws. [ISC, Specimen Question Paper 2016]
0 1 0 Ans. F = XY + (XZ) ' + XY 'Z
1 0 1 = XY(Z + Z ') + (XZ) ' + XY 'Z
[ISC Marking Scheme, 2016] = XYZ + XYZ ' + (XZ) ' + XY 'Z
= XYZ + XY 'Z + XYZ ' + (XZ) '
Examiner's Comment = XZ(Y + Y ') + XYZ ' + (XZ) '
= XZ + (XZ) ' + XYZ '
w This part was well answered by most of the [ •• (Y + Y ') = 1]
candidates. Some candidates mentioned laws = 1 + XYZ ' [ v (XZ + XZ ) = 1]
involving complementation. Others proved by F =1 [ •.• 1 + XYZ ' = 1]
laws instead of truth table. Some drew truth table Q. 12. Simplify ( A + C)(A + A - D) + A - C + C
of 2 variables. [ISC 2015]
Q. 8. Find the dual o f Y - X + X ' + l = l [ISC 2016] Ans. (A + C) (A + AD) + AC + C
Ans. (Y + X) • X ' •
0=0 (A + C)A + AC + C
[ISC Marking Scheme, 2016] A + AC + AC + C
A+C [ISC Marking Scheme, 2015]

Examiner's Comment
Examiner's Comment
w This was well attempted by most candidates. A
few candidates did not put brackets in the dual w Most of the candidates answered well. Some
equation Some changed the complement also, reduced the expression in one step without
showing the working. In a few cases, the laws
which was not required. O's and l's were not
were used incorrectly. Some candidates were
interchanged in some cases. unable to open the brackets in the expression.

These questions are for practice and their solutions are available at the end of the chapter
16 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Distributive law:
I
Answering Tip A + B • C = (A + B) • (A + C)

w Students should show the working and mention


= X • [(Y + Y ') • (Y + Z)]
the laws, if necessary in such type of questions. Complementary law:
Knowledge of the laws and practice in their Y + Y' = 1
application is important.
= X • (Y + Z) = R.H.S.
[ISC Marking Scheme, 2015]
Q. 13. State De Morgan's law and verify it using a truth
table . [ISC 2015]
Ans. De Morgan's law states that the complement of Examiner's Comment
sum of the variables is same as product of the
individual complements of the variables and w While most candidates answered this part
vice-versa. correctly, some did not mention the laws. A few
-
(A B) ' = A ' + B ' candidates wrote the answer directly in one step.
(A + B) ' = A ' B ' -
A B A B- (A - B ) ' A' + B '
Answering Tip
o o 0 1 1
0 1 0 1 1 w Students must know that the laws must be
mentioned while reducing, minimizing or proving
1 0 0 1 1 an expression.
1 1 1 0 0
[ISC Marking Scheme, 2015] Q. 15. Find the complement of XY Z + XY + YZ '.
[ISC 2014] 0

w
Examiner's Comment
A number of candidates proved both the laws of
De Morgan.
A few candidates mentioned some other law.
n w
Examiner's Comment
Some candidates were not clear with the
POS form of expression and wrote the SOP
expression. Actual meaning and features of
Some wrote 'Break the line and change the sign'
canonical expression were not clear to many
which is not the law, but a way to remember the
candidates.
law.
Q. 16. State the principle of duality. Write the dual of

Answering Tip - -
(P + Q ') R 1 = P R + Q ' R - [ISC 2013]
Ans. Principle of duality states that starting with a
w All the laws of Boolean algebra must be practiced Boolean relation another Boolean relation can be
and proved with the help of truth table. derived by
(1) Change all 0’s to l’s and l’s to 0’s.
Q. 14. Verify the following expression using Boolean (2) Change all to ' + ' and ' + ' to
laws. Also, mention the law used at each step of Dual of (P + R • 1 = P • R + Q' R
Q) ' • -
simplification. [ISC 2015]
=> (P • Q') + R + 0 = (P + R) • (Q ' + R)
-
- - - -
X Y Z + X Y' Z + X Y Z ' = X - (Y + Z ) Q. 17. Minimize the expression using Boolean laws.
Ans. X - Y - Z + X - Y - Z + X - Y - Z
' '
F = (A + B ) • (B + CD) ' [ISC 2013]
= X • (Y + Z)
L.H.S. = X - Y - Z + X Y' - Z + X - Y - Z '
Ans. F = (A + B )- (B + CD)
' '

= X • Y - (Z + Z ') + X • Y ' Z = (A + B) - (B + CD)


Complementary law: = (A + B) - (B-CD) (De Morgan's law)
Z + Z' = 1 = (A + B) -[B-(C + D)]
= X • Y + X • Y' • Z = (A + B) -[B-C + B-D)]
= X • (Y + Y ' • Z) (Distributive law)
These questions are for practice and their solutions are available at the end of the chapter
I = ABC + ABD + BBC + BBD
BOOLEAN ALGEBRA
Now, put the values of A, A ', B, B ', C and C ' in
17

the expression as like,


= ABC + ABD + BC + BD
X = A 'BC + ABC + ABC + A 'BC '
= BC(A + 1) + BD(A + 1)
= BC + BD - - -
= 0 0 -1 + 11-1 + 1 0-1 + 0 0- 0 -
= B(C + D) =0+l+0+0
X =1
Q . 18. If A = 1 and B = 0, then find:
Q . 23. Show that the dual of P'QR ' + PQ 'R + P 'Q ' R
(i) (A ' + 1) • B (ii) (A + B y
is equal to the complement of PQ 'R + Q •
Ans. (i) ((1) ' + l ) - 0 = (0 + l ) 0 = l - 0 = 0
(ii) (1 + (0) ') ' = (1 + 1 )' = (1) ' = 0
(P 'R + P R ). ( [ISC 2010] fl
Q . 24. Simplify the following expression by using the
Q.19 . Using a truth table, verify the following
Boolean laws. Show the working of each steps
expression
and also mention the laws used. [ISC 2009]
X + (Y + Z ) = (X + Y) + Z [ISC 2012]
x' y' z' + x' y' z + x' yz + x' yz' 4- xy' z 4- xy' z
Also state the law.
Ans. Given that
Ans.
F = x' y' z ' 4- x' y' z + x' yz 4- x' yz'
X Y Z X + Y (X + Y ) + Z Y + Z X + (Y + Z ) + xy' z + xy' z
0 0 0 0 0 0 0 = x' y' z' + x' y' z 4- x' yz + x' yz' 4- xy' z
0 0 1 0 1 1 1 (by idempotent law)

0 1 0 1 1 1 1
= x ' y ' (z '
+ z ) + x '
y (z + z' ) 4- xy' z
= x y (l ) 4- x y( l ) 4- xy z
' ' ' '

0 1 1 1 1 1 1
(by complement law)
1 0 0 1 1 0 1
= x y + x y 4- xy z
' ' ' '

1 0 1 1 1 1 1 = x '(y ' 4- y) + xy' z


1 1 0 1 1 1 1 = x '(l ) + xy 'z (by complement law)
1 1 1 1 1 1 1 = x (l + y z ) + xy z (by basic postulates)
' ' '

It is associative law. = x ' + x' y' z + xy' z


Q . 20. Find the complement of the following expression: = x ' + y 'z (x ' + x)
X ' + XY ' [ISC 2012]
= x ' + y 'z (1) (by complement law)
F =x +y z
' '
Ans. (X ' + XY ') ' = (X ") • (XY ') '
= X • (X ' + Y)
Q .25 . Obtain the truth table to verify the following
expression x* ( y + z) = x- y + x- z . Also, name the
= XX ' + XY
law stated above. [ISC 2009]
= XY
Ans. To verify expression using truth table,
Q . 21. State the two absorption laws . Verify any one of
them using truth table . [ISC 2011] x y z y + z x -y x-z x - (y + z ) x- y + x- z
Ans. x + xy = x 0 0 0 0 0 0 0 0
x • (x + y) = x 0 0 1 1 0 0 0 0
x y xy x + y x + xy x • (x + y) 0 1 0 1 0 0 0 0

0 0 0 0 0 0 0 1 1 1 0 0 0 0
1 0 0 0 0 0 0 0
0 1 0 1 0 0
1 0 1 1 0 1 1 1
1 0 0 1 1 1
1 1 0 1 1 0 1 1
1 1 1 1 1 1
1 1 1 1 1 1 1 1
Q . 22. If X = A BC + AB C + ABC 4- A BC', then find
the value of X, when A = 1, B = 0 and C = 1. L.H.S. R.H.S.
[ISC 2010] From the above table, L.H.S. = R.H.S.
Ans. A = 1 => A = 1 = 0
' ' - -
x (y + z ) = x y + x - z
B = 0 => B ' = 0 ' = 1 The law stated in the given expression is called
C = 1 => C ' = 1' = 0 distributive law.

These questions are for practice and their solutions are available at the end of the chapter
18 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 26. Given F = A + (B + C)-(D' + E) = x ' + (y " + z ") - (y ' + z ')
I
Find F ' and show the relevant working in steps. (by demorgan law)
[ISC 2009] F = -
x ' + (y + z) (y ' + z ')
Ans. Given function is, (by involution law)
F = A + (B + C) (D ' + E) - Q. 30. Simplify the following Boolean expression using
We need to find the complement of F, i.e., F '. laws of Boolean algebra. At each step, state clearly
First of all, we will simplify F the law used for simplification. |§|[ISC 2007]
F = A + (B + C) (D ' + E) - F = x-y(x-y + yz)
F = (A + B + C) (A + D ' + E) - Q. 31. State the DeMorgan's laws. Verify any one of
(by distributive law) them using the truth table. [ISC 2007]
Now, complement of F, Ans. DeMorgan's laws state that,
(F ') = [(A + B + C) (A + D ' + E)] ' - (i) Law 1: The complement of sum of literals is
= (A + B + C) ' + (A + D ' + E) ' equal to the product of individual complement
(by demorgan’s law) of literals, i.e., (x + y) ' = x ' y ' -
= A 'B 'C '
+ 'D "E '
A (ii) Law 2: The complement of product of literals
(by demorgan’s law) is equal to the sum of individual complement
= A 'B 'C '
+ A 'DE ' -
of literals, i.e., (x y) ' = x ' + y '
(by involution law) Now, we will verify the law 1 using the truth table
F = A B C + A DE '
' ' ' ' ' as:
Q . 27. Simplify the following Boolean expression and
(x + y) ' = x' y' -
state clearly the laws used for the simplification x y x + y (* + yr
.
x' yl x ' y ' -
at each step. o 0 0 1 1 1 1
xy + xz + xyz [ISC 2008] 0 1 1 0 1 0 0
Ans. Given Boolean expression is, 1 0 1 0 0 1 0
F = xy + xz + xyz = xy + xyz + xz 1 1 1 0 0 0 0
= xy(l + z) + xz (by absorption law) L.H.S. R.H.S.
= xy(l) + xz (by basic postulates) From the above table, it is verified that,
= xy + xz L.H.S. = R.H.S.
F = x(y + z) (by distributive law) Q. 32. Find the complement of
Q. 28. State the two complement properties of Boolean -
F(a, b, c, d) = [a + { (b + c) (b ' + d ' ) }] [ISC 2007]
algebra. Verify any one of them using the truth Ans. Given function is,
table. [ISC 2008]
Ans. According to the complement properties of
F(a, b, c, d) = [a + {(b + c) (b ' + d ')}] -
On applying demorgan's theorem,
Boolean algebra, (i) x + x ' = 1 (ii) x x ' = 0 - -
F ' = a ' {(b + c) (b ' + d ')}' -
Now, will verify the complement law using truth
table as:
-
= a ' {(b + c) ' + (b ' + d ') '}
(by demorgan's law)
X x' x + x' - -
= a (b c + b " d ")
' ' '
-
0 1 1 (by demorgan's law)

1 0 1 = a' ( b' c' + b d) - -


(by involution law)
So, it is verified that x + x' = 1. F ' = a 'b 'c ' + a 'bd
- -
Q. 29. Find the complement of x (y ' z' + yz) [ISC 2008] (by distributive law)
Ans. Given Boolean function is, Q. 33. Find the complement of
- -
F = x (y ' z ' + y z) - --
F(m, n, o) = m' n o ' + m ' n ' o [ISC 2006] - -
- -
F = [ x ( y' z' + yz)] ' Ans. Given,
-
= x ' + (y ' z ' + y z) ' - F(m, n, o) = m ' n o ' + m ' n ' o -- - -
(by demorgan's law) On applying deMorgan's theorem,
= x + (y z ) (y z) '
' ' ' '
- - - --
F ' = (m ' n o ' + m ' n ' o) ' - -
(by demorgan law) --
= (m ' n o ') ' (m ' n ' o) ' - - -
These questions are for practice and their solutions are available at the end of the chapter
I = (m " + n ' + o ")-(m " + n " + o ') x y
BOOLEAN ALGEBRA

z y + z x (y + z) xy x-z (x-y) + (x- z)


19

(by demorgan's law)


0 0 0 0 0 0 0 0
F' = (m + n ' + o) (m + n + o ') -
(by involution law) 0 0 1 1 0 0 0 0

- -
Q. 34. Simplify a b + a ' c + b c using the laws of - 0 1 0 1 0 0 0 0
Boolean algebra. At each step, state clearly the 0 1 1 1 0 0 0 0
law used for simplification. [ISC 2006]
1 0 0 0 0 0 0 0
Ans. Given expression is,
1 0 1 1 1 0 1 1
F = a b + a' c + b c - - -
F = b(a + c) + a ' c (by distributive law) - 1 1 0 1 1 1 0 1
--
= a' b a + a' b c + b c a + b c c -- -- -- 1 1 1 1 1 1 1 1
(by distributive law) L.H.S. R.H.S.
--
= a' a b + a' b c + a b c + b c -- -- - So, it is verified from the truth table that
,
(by idempotence law) - -
x (y + z) = x y + x z. -
-
= 0 b + a' b c + a b c + b c -- -- - Q.36. What is the application of Boolean Algebra in
(by zero property) computer science? [ISC 2005] #
= 0 + a' b c + a b c + b c -- -- - Q.37. Reduce the following expression to its simplest
(by zero property) form using laws of Boolean Algebra. At each step
--
= a b c + b c(a + 1) = a ' b c + b c 1
'
- -- -- clearly state the law used for simplification .
(by basic postulates) AB + ABC + AC + BC
= a' b c + b c -- - [ISC 2005]
= b c(a ' + 1) -(by basic postulates)
Ans. Given expression is,
= b c1 --
F = bc - ( . b c 1 = b c) -- - - - F = AB + ABC + AC + BC
. .
Q 35 State the distributive law. Verify it using the truth Now, we will simplify the given expression by
table. [ISC 2005] using Boolean laws as below:
Ans. The distribution law states that, F = AB + ABC + AC + BC
(i) x + yz = (x + y) (x + z) - = AB + ABC + A + C + BC
-
(ii) x (y + z) = x y + x z - - (by demorgan's law)
Now, we will verify the first law using truth table = AB + A + ABC + C + BC
as follows:
(by commutative law)
x + yz = (x + y) (x + z) - = AB + A(1 + BC) + C + BC
X y z yz x + yz x + y X + z ( x + y) ( x + z ) - (by distributive law)
0 0 0 0 0 0 0 0 = AB + A-l + C + BC
0 0 1 0 0 0 1 0 (by basic postulate)
0 1 0 0 0 1 0 0 = AB + A + C + BC (by identity law)
0 1 1 1 1 1 1 1 -
= [(A + A) (B + A)] + [(C + C) (C + B)] -
1 0 0 0 1 1 1 1 (by distributive law)
1 0 1 0 1 1 1 1 -
= 1 (B + A) + 1 ( + B)
C -
1 1 0 0 1 1 1 1 (by complement law)

1 1 1 1 1 1 1 1 = (B + A) + (C + B) (by identity law)


L.H.S. R.H.S.
=B+B+A+C (by commutative law)

So, it is verified from the truth table that,


=1+ A + C (by basic postulates)

x + yz = (x + y) (x + z) - =1+ C (by basic postulates)

Now, we will verify the another law by truth table F =1


as follows: Q. 38. Verify that (z + x)(z + x + y ) = (z + x??)(z + y).
-
x (y + z) = (x y) + (x z) - - [ISC 2005]

These questions are for practice and their solutions are available at the end of the chapter
20 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class- XII
Ans. Given expression, = x' + z + 1
I
(z + x)(z + x + y) = (z + x)(z + y) = X ' + l (z + 1 = 1 )
Take L.H.S. = (z + x)(z + x + y) =1
= (z + x)(z + x) + (z + x)y (x ' + 1 = 1) = R.H.S.
(by distributive law) Q. 2. State the complement properties. Find the
= zz + zx + xz + xx + zy + xy complement of the following expression using
(by distributive law) DeMorgan's law: 0 [ISC 2006]
= z + zx + xz + xx + zy + xy AB + A + BC
'

(by idempotent law)


Q. 3. Reduce the following expression using Boolean
= z + zx + xz + 0 + zy + xy laws: [ISC 2014]
(by complement law)
F( A, B, C, D) = ( A + C)*(A ' + C') ( A ' + B + CD)
= z + zx + xz + zy + xy
(by identity law)
Ans. (A ' + C) (A ' - + C ') -(A' + B + C 'D)
= z(l + x) + xz + zy + xy = A '(l + C)(l + C ') (A + B ' + C 'D)
= z + xz + zy + xy = A '( A ' + B + C 'D)
(by absorption law) = A 'A ' + A 'B + A 'C 'D
= z + zy + xy (by absorption law) = A ' + A ' B + A 'C ' D '
= z + xy (by absorption law) = A '(l + B + C 'D ') (v 1 + A = 1)
= (z + x)(z + y) = A' 1 -
(by distributive law) = A' [ISC Marking Scheme, 2014]
So, L.H.S. = R.H.S. Hence verified.
Q. 39. State the law represented by the following Examiner's Comment
proposition and prove it with the help of a truth
table. w Most of the candidates attempted this part
correctly barring a few who gave vague reduction.
PvP =P [ISC 2017]
Ans. Idempotent law.
p PvP Answering Tip
0 0
1 1 w All related laws of Boolean Algebra should be
practiced for reducing expression.
P P- =P
Answer Type
<©> Short
Questions-II (4 marks each)
Q. 4. Verify algebraically if,
x' y' z' + x' y' z + x' yz + x' yz' + xy' z' + xy' z
Q. 1. Prove the Boolean expression using Boolean laws. = x ' + y' [ISC 2012]
Also, mention the law used at each step. Ans. Given expression is,
[ISC 2017] x 'y 'z ' + x 'y 'z + x ' yz + x 'yz ' + xy 'z ' + xy 'z
F = (x ' + z) + [(y' + z) • (x' + y)]' = 1 = x ' + y'
Ans. F = (x ' + z) + [(y ' + z) (x ' + y)] '
• L.H.S. = x 'y 'z ' + x ' y 'z + x 'yz + x 'yz ' + xy 'z '
= x ' + z + (y ' + z) ' + (x ' + y) ' + xy 'z
= x ' + z + (y ') '-z ' + (x ') '-(y) ' = x y (z + z) + x y(z + z ) + xy (z ' + z)
' ' ' ' ' '

- [De' Morgans Law] = x 'y '(l ) + x 'y(l) + xy '(l)


= x + z + yz + xy '
' ' (by complement law)
- [Double Negation] = x y + x y + xy
' ' ' '

= + + + ' - [a + a 'b = a + b]
x ' xy ' z yz = x '(y ' + y) + xy '
= x ' + y' + z + y = x '(l) + xy ' (by complement law)
= x ' + z + y' + y = x '
+ xy '
= (x '
+ x) • (x ' + y ')

[Complement Law: a + a ' = 1] (by distributive law)

These questions are for practice and their solutions are available at the end of the chapter
I = l -(x ' + y ') (by complement law)
BOOLEAN ALGEBRA
= A-[AB + AC + BBC + BCC]
21

= (x + y )
' '
(by distributive law)
L.H.S. = R.H.S. = A-[AB + AC] (by complement law)
Q. 5. (a) State the principle o£ duality. [ISC 2011] = AAB + AAC (by complement law)
Ans. Principle of duality states
=0
(1) Change all 0 's to l 's and l 's to 0 's.
Q. 8. State the dual form of the following expression
(2) Change all '-' to ' +' and ' +' to
Dual of (P + Q) ' • R • 1 = P - R + Q ' • R xy(xyz + x + xz) <§) [ISC 2005]
=> (P - Q ') + R + 0 = (P + R) (Q ' + R) - Long Answer Type
(b) Give the dual of the following: <©> Questions -I (5 marks each)
- -
(A ' B) + (C l) = (A ' + C) (B + C) -
Ans. (A + B) • (C + 0) = (A ' C) + (B C)
'
- - Q. 1. Reduce the Boolean expression to the simplest
Q. 6. Minimise the following expression. At each step forms.
state clearly the law used. (i) { (C- D)' + A} + A + (CD) + ( A- B )
Y = (A + B ) - ( B + CD) '
[ISC 2009]
'
(ii) A-{ B + C( A - B + A -C)'} [ISC 2011]
Ans. Given expression is, Ans. (i ) Given expression
Y = (A + B) (B + CD) ' - F = (C-D) ' + A + A + -
(C D) + (A- B)
= (A + B) B (C + D) -- (demorgan's law)
F = 1 + A + A + A -B
= (A + B)(BC + BD) (distributive law)
(by complementary law)
= ABC + ABD + B BC + B.BD -
= ABC + ABD + BC + BD (P P = P) - F = 1 + A + A- B (by unit property)
= ABC + BC + ABD + BD F = 1 + A- (l + B)
= BC(A +1) + BD(A +1) (P +1 = 1) F =1+ A (by absorption law)
= BC + BD F =1
= B(C + D) (ii) Given expression,
Q. 7. Reduce the following Boolean expression to the F = A-{B + C(A- B + A-C)'}
simplest form. => F = A-{B + C(A-B)'.(A-C)'}
A -[( B + C) - ( AB + AC)] [ISC 2008] (by demorgan's law)
Ans. Given Boolean expression, F = A-{B + C(A' + B')- (A' + C')}
F = A -[(B + C)- (AB + AC)] (by demogran's law)
= A -[(B + C)-(AB-AC)] F = A-{B + C(A'-A' + A'-C' + B'-A' + B'C')}
(by demogran's law) (by distributive law)
= A -[(B + C)- ((A + B)(A + C))] F = A-{B + C(A' + A'-C' + A'- B' + B'C')}
(by demogran's law) (by idempotent law)
= A -[(B + C)- (A-A + A-B + A- C + B- C)] F - - -
= A {B + A'C + A'C'C + A' B' C + B'-C'-C)}
(by distributive law) (by distributive law)
= A-[(B + C)- (A + AB + AC + BC)] F = A-{ B + A'-C + 0 + A' - B'-C + 0}
(by idempotent law) (by complementary law)
= - C) ( -
A [(B + (A 1+ B) + AC + BC)] F = A- B + A-A'-C + A'-A- B'-C
(by distributive law) (by distributive law)
= A-[(B + C)- (A + AC + BC)] F = A- B + 0 + 0 (by complementary law)
(by absorption law) F = A-B (by identity law)
= A-[(B + C)- (A + BC)] Q. 2. Verify if,
(by absorption law)
- - -
x y z+x y z+x y z+x y z - - -
= A-[(B + AC + BCC)]
= x-y + y-z + z-x
(by distributive law)

These questions are for practice and their solutions are available at the end of the chapter
22 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
At each step state the law used for simplification = (x - z + x)y + x - y - z
I
clearly. [ISC 2007] (by distributive law)
Ans. L.H.S. =x y z+x y z+x y z+x y z = (x + z)y + x y z ( v A + AB = A + B)
• •

= x - y - z + x - y - z + x - y(z + z) = x-y + y-z + x-y-z


(by distributive law) (by distributive law)
= x - y - z + x - y - z + xy(l ) = x - y + (y + x - y) xz
(by complement law) (by distributive law)
= x-y -z + x - y -z + x - y = x - y + (y + x) - z ( vA + AB = A + B)
(by identity law) = xy + yz + zx (by distributive law)
= x-y -z + x - y + x-y -z .-. L.H.S. = R.H.S.
(by communicative law)

I Topic- 3

Revision Notes
Forms of Representing Boolean Expressions
Conceptscovered: Minterms; Maxterms; SOPform; POSform;Canonicalforms

>

>
A Boolean expression results either true or false i.e., a Boolean value. It is also called as comparing expression,
conditional expression, and relational expression. In Boolean expression two important terms are Minterms and
Max terms.
A Boolean expression is an expression that results in either true or false. In Boolean expression, a single variable

or its complement is called literal.
> Minterms two or more literals joined by AND operator are known as minterms. For example, xy, x'y, x'y' and xy'
are minterms for two literals and x and y.
> Maxterm two or more literals jointed by or operator are known as maxterms. For examples, x + y, x' + y', x' + y
and x + y' are maxterms for two variables x and y.

Maxterm () Minterm
x y z
Term Symbol Term Symbol
x+y+z mo x'y'z' Mo
0
0
0
0
1
0 0
1
0
x + y + z'
x + y'+ z
m
m?
. x'y'z
x'yz'
Mi
ML
0 1 1 x + y' + z' mq x'yz ML
1 0 0 x' + y + z m4 xy'z' ML
1 0 1 x' + y + z' HU xy'z M
1 1 0 x'+ y' + z ms xyz' ML
1 1 1 x' + y' + z' m7 xyz M7
> Canonical Expression: A Boolean expression composed entirely of either minterms or maxterms.
> Sum-Of-Products (SOP) form: A Boolean expression represented purely as sum of minterms is said to be in SOP
form.
> Product Of Sum (POS) form: A Boolean expression represented purely as product of maxterms is said to be in
canonical POS form.
> Canonical SOP and POS Forms: When each term of a logic expression contains all variables, It is said to be in the
canonical form.
> Conversion from SOP Expression to Canonical SOP Expression:
The following procedure is used to convert SOP expression into canonical SOP expression
.
1 Check the missing variable in each term.

.
2 Perform AND operation with (e.g. with X + X if x is missing) terms, which have missing variables.
.
3 Expand all terms and remove the duplicate terms such that X + X = X o r X + X + X = X.
.
4 The produced SOP expression is the canonical SOP expression.
I> Conversion from POS Expression to Canonical POS Expression:
BOOLEAN ALGEBRA 23

The following procedure is used to convert POS expression into canonical POS expression
.
1 Check the missing variables in each term.

.
2 Perform Or operation with (e.g. with X X if x is missing) missing variables.
.
3 Expand all terms and remove the duplicate terms such that X X = X or X X X = X.
.
4 The produced POS expression is the canonical POS expression.
> Conversion from SOP Expression to Canonical POS Expression:
The following procedure is used to convert the SOP expression into canonical POS expression
. —
1 Check the given SOP expression is canonical SOP expression or not, if not then convert it into canonical SOP
expression. If it is already in canonical SOP expression then continue to step 2.
.
2 Use the duality theorem to convert SOP into canonical POS such that:
(i) Change every OR sign ( + ) to AND sign (•).
(ii) Change every AND sign (•) to OR sign ( + ).
(iii) Change normal variable (A) into complement variable (A) and vice versa.
.
3 The produced expression is the canonical POS expression.
> Conversion from POS Expression into Canonical SOP Expression:
The following procedure is used to convert POS expression into canonical SOP expression:
.
1 Check the given POS expression is canonical POS expression or not, if not then convert it into canonical POS
expression. If it is already in canonical POS expression then continue step 2.
.
2 Use the duality theorem to convert POS expression into canonical SOP expression such that:
(i) Change every OR sign ( + ) to AND sign (•).
(ii) Change every AND sign (•) to OR sign ( + ).
(iii) Change normal variable (A) into complement variable (A) and vice versa.
.
3 The produced expression is the canonical SOP expression.

|Key Terms
> -
Sum of Products (SOP): Sum of minterms is known as Sum Of Products (SOP) form. Example, xy' + x'y is a SOP
form.
> - -
Product of Sum (POS): Product of maxterms is known as Product Of Sums (POS) from. Example, (x + y) (x' + y)
is a POS form.
> Miniterm is a product of all literals and maxterm is a sum of literals.
> Canonical from: If an expression is represented in its maxterms or minterms.
> Cardinal form: If an expression is represented in its decimal equivalent of its terms.

OBJECTIVE TYPE QUESTIONS (1 mark each)


.
Q. 1 The representation of the Boolean function , ,
Q. 3. AND terms x’ y’ x' y xy’ and xy are known as
F(A,B) = p (l,3) in canonical form is: (A) Maxterms (B) Minterms
- -
[ISC Sem 1 Paper 2021 22] (C) Both (A) and (B) (D) None of these
(A) (A' + B).(A + B) ( B ) S(0,2) Ans. Option (B ) is correct.
(C) A'B + AB (D) (A + B').(A' + B') Explanation: And terms x'y', x'y, xy' and xy are
Ans. Option (D) is correct. known as minterms. A minterm is a Boolean
Explanation: In product of sum, 1 will be expression resulting in 1 for the output of a single
cell and Os for all other cell in a Karnaugh map
represented by (A + B') and 3 will be represented by
or truth table. If a minterm has a single 1 and the
(A' + B'). So canonical form will be (A + B').(A' + B')
remaining cells as Os, it would appear to cover a
Q. 2. If P = l, Q = l, R = 0 and S = l, then the minterm minimum area of Is.
will be: [ISC Sem-1 Paper 2021-22] -
Q. 4. Name the form of given example (A + B ) (A + B ).
(A) P + + R + S
Q ' (B ) P'Q'RS' (A) SOP (B ) POS
(C) PQR'S (D) P' + Q' + R + S' -
(C) K map (D) De Morgan's law
Ans. Option (C) is correct. Ans. Option (B ) is correct.
Explanation: Minterm is product of Boolean Explanation: POS (Product of Sum) is a Boolean
variables either in normal form or complemented expression in which sum of terms (OR terms) are
form. connected by the AND operators. Each OR terms
24 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
contains one or more variables in complemented F(A, B, C, D) = BD + ABC + ACD
I
or normal form.
Q. 9. Identify the complement of the reduced
(A + B)-(A + B) expression of given expression.
Q. 5. If A = 1, B = 0, C = 1 and D = 1, find its maxterm
from given options. F( A, B, C) = 2(0, 1, 2, 3, 4, 5, 6, 7)
(A) ABCD (B ) A + B + C- D (A ) 1 (B ) 0
(C) A + B + C + D (D ) A + B + C + D (C) A + B (D) AB
Ans. Option (C) is correct. Ans. Option (B ) is correct.
Explanation: The variables are also combined to Explanation:
form a standard sum when we take OR operation F(A, B, C) = 2(0, 1, 2, 3, 4, 5, 6, 7)
between the variables. These OR terms are known
BC
as maxterms.
_ _
If A = 1, B = 0, C = 1 and D = ltiien the maxterm
A \ BC BC BC BC
for these variables is A + B + C + D.
Q. 6. What is the reduce form of
A
A
1
JL1
1
1- - 1 - - 1
T
1j
TIL
4 5 T ( i
F( A, B,_C) = 2(0,4, 5, 7)
(A) BC + AB + AC (B ) BC + AB + AC -
In a three variables K map octet means given
(C) BC + AB + AC (D) BC + AB + AC function will produce output 1, i.e. tautology.
Ans. Option (D) is correct. i.e. F(A, B, C) = 1
Explanation: the complement of F, i.e. F' = 1' = 0.
F(A, B, C) = 2(0, 4, 5, 7) Q. 10. When a Boolean expression is represented as
BC product of Maxterms it is said to be:
A \ BC BC BC BC
(A) Simplified expression
2 (B ) Dual of the Boolean expression
(C) Canonical Product-of-sum
6
-
(D) Canonical Sum of-product
F = BC + AB + AC Ans. Option (C) is correct.
Q. 7. What is the canonical SOP form of A B + BC?
^ Direction: On the basis of given inference answer Q. 11.
(A) ABC + ABC + ABC and Q. 12.
(B ) ABC + ABC + ABC A Post Graduation College intends to offer courses
(C) ABC + ABC + ABC
in three categories of journalism which are, the
(D) ABC + ABC + ABC
print, the web and the broadcasting media. A
Ans. Option (A) is correct. student is eligible to apply if he/she satisfies any
Explanation: one of the criteria given below:
F = AB + BC • The student is a graduate in any discipline
-
F = A B-l + 1 BC with an aggregate percentage of 75 or above
= AB-(C + Q + (A + A) j3 C and with a record of literary skills.
= ABC + ABC + ABC + ABC Or
F = ABC + ABC + ABC • The student is a graduate in Mass
Q. 8. What is the reduce form of Communication with an aggregate percentage
of 75 or above and with a record of literary skills.
F( A, B C, D) = 2(0, 1, 2, 8, 10, 14)
(A) BD + ABC^ + ACD Or
(B ) BD + ABC + ACD
• The student is a graduate in Mass
Communication and with a record of
(C) BD + ABC + ACD
(D) BD + ABC + ACD literary skills but does not have an aggregate
percentage of 75 or above.
Ans. Option (A) is correct. The inputs are:
Explanation:
Inputs

\CD
_
F(A, B, C, D) = 2(0, 1, 2, 8, 10, 14)
__ G Graduate in any discipline
AB\ CD CD CD CD M Graduate in Mass Communication
AB. m o
T; •i
1 3 S
P Aggregate percentage of 75 and above
Record of Literary Skills
AB 4 5 7 6 (In all the above cases 1 indicates yes and 0
indicates no).
AB 12 13 15 ljl4
Output: X [1 indicates eligible and 0 indicates not
AB; 1 J: 8 9 11
J "
eligible for all cases].
10
I Draw the truth table for the inputs and outputs
BOOLEAN ALGEBRA 25
and other position produced 0. So SOP expression
given above and answer the following questions: will be the Option (A) is correct.
[ISC Sem-1 Paper 2021-22] Q. 12. What will be the complement of the above SOP
Q. 11. What will be the SOP expression for X(G,M,P,S)? expression?
(A) S(5,6,11,13,14,15) (A) 5(5,6,11/13,14,15)
(B ) P(5,6,11,13,14,15) (B ) P(5,6,11,13,14,15)
(C) S(0,1,2,3,4,7,8,9,10,12) (C) S(0,1,2,3,4,7,8,9,10,12)
(D) P(0,1,2,3,4,7,8,9,10,12) (D) P(0,1,2,3,4,7,8,9,10,12)
Ans. Option (A ) is correct. Ans. Option (D) is correct.
Explanation: After draw the truth table at the Explanation: After complementing the SOP
position of 5, 6, 11, 13, 14, 15 produced 1 as output expression it will produce POS expression for this
reason Option (d ) will be the correct option.

SUBJECTIVE TYPE QUESTIONS


P = o, Q = 1, R = 1 and S = 0
Short Answer Type
<©> Questions- I ( 2 & 3 marks)
Minterm = P'QRS'
Maxterm = ( P + Q' + R' + S)
Q. 1. Convert the following expression to its cardinal Q . 3. Convert the following Boolean Expression into its
SOP form: canonical POS form.
F( P,Q,R ) = P'Q'R + P'QR + PQR' + PQR' g
F( A, B, C) = ( B + C’) ( A' + B ) ( |[ISC 2017]
[ISC 2020] Q . 4. Differentiate between Canonical form and
Ans. F( P,Q,R) = P'Q'R + P'QR + PQ'R' + PQR' cardinal form of expression. [ISC 2016]
001 011 100 110 Ans . Canonical form: If an expression is represented
F(P,Q,R) = 2( 1,3,4,6 ) in its maxterms or minterms.
[ISC Marking Scheme 2020] Cardinal form: If an expression is represented in
Q. 2. Define maxterms and minterms. Find the maxterm its decimal equivalent of its terms.
and minterm when: [ISC 2017] [ISC Marking Scheme 2016]
p = 0, Q = 1, R = 1 and S = 0
Ans. A minterm is a product of all variables taken
either in their direct or complemented form. Any
Boolean function can be expressed as a sum of its
w
A Examiner's Comment
This part was well answered by most of the
-
1 minterms and the inverse of the function can be
candidates. Some represented the difference
expressed as a sum of its 0-minterms. Hence,
through examples.
F (list of variables)
= 2 (list of 1-minterm indices)
and Answering Tip
F' (list of variables)
= 2 (list of 0-minterm indices) w Students should have sufficient knowledge about
A maxterm is addition of all variables taken Canonical form and Cardinal form of expression
either in their direct or complemented form. Any and regular practice with several examples.
Boolean function can be expressed as a product
of its 0-maxterms and the inverse of the function
Q. 5. Write the maxterm and minterm, when the inputs
can be expressed as a product of its 1-maxterms.
are A = 0, B = 1, C = 1 and D = 0. [ISC 2016]
Hence,
F (list of variables) Ans.
= 7i (list of 0-maxterm indices) A B C D MAXTERMS MINTERMS
and 0 1 1 0 A + B +C + D A' BCD'
F' (list of variables) [ISC Marking Scheme, 2016]
= 7i (list of 1-maxterm indices)

These questions are for practice and their solutions are available at the end of the chapter
26 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class- XII
Q. 8. Convert the following cardinal form of expression
I
Examiner's Comment into its canonical form
F(P, Q, R) = P(l, 3) [ISC 2013]
w Almost all candidates answered this part correctly. Ans. Given expression is
Some candidates interchanged the maxterms with
the minterms. F(P Q, R) = P(l, 3)
It is clear that, the function F is in POS form and
contains two maxterm,
Answering Tip i.e., F(R Q, R) = MJ M3 -
To convert it into canonical form, we need to find
w Students should learn to device the maxterms the expression of the maxterm as:
and minterms from a given truth table. Their use P Q R Maxterm Expression
in expression must be explained to students.
0 0 0 Mo P+Q+R
0 0 1 Mj P + Q + R'
Q. 6. Convert the Boolean expression F(X, Y, Z ) = X'Y'Z
0 1 0 M2. P + Q' + R
+ X'YZ' + XYZ into its cardinal form.
0 1 1 M3. P + Q' + R'
ill
[ISC Specimen Question Paper 2016]
1 0 0 M4 P' + Q + R
Q. 7. Convert the following expression into its
1 0 1 M5 P' + Q + R'
canonical POS form.
1 1 0 Nk P' + Q' + R
F( A, B) = ( A + B ) A' [ISC 2014]
1 1 1 M7 P' + Q' + R'
Ans. (A + B ) A ' From the above table,
(A + B ) (A ' + B.B1) -
F = MJ M3
(A + B ) (A ' + B) (A1 + B') F = (P + Q + R')-(P + Q' + R')
[ISC Marking Scheme, 2014] -
Q. 9. Given F(x, y, z) = (x' + y') (y + z')
Detailed Answer: Write the function in canonical product of sum
Given expression is, form [ISC 2012]
F(A, B) = (A + B) A' Ans. Given function is,
As we know, in given expression there must be
two maxterms but in one term a variable is missing
-
F(x, y, z) = (x' + y') (y + z')
like, = (x' + y' + 0)-(0 + y + z')
F(A, B) = (A + B) A' -
= (x' + y' + zz ') (xx ' + y + z')
(by complement law)
Maxterm
F(A, B) = (A + B) (A' + (BB'))
, , ' '
-
F(x y z) = (x + y + z) (x' + y' + z' )
•(x + y + z ' )-(x' + y + z ')
(BB' = 0, complementary law) (by distributive law)
= + B) (A' + B) (A' + B')
(A
Q . 10. If A = 1 B =
, 0, C =1 and D = 1, find its
(distributive law)
The canonical POS form is, (i) Maxterm
F(A, B) = (A + B) (A' + B) (A' + B') (ii) Minterm [ISC 2011]
Ans. (i) The maxterm corresponding to the given
value of the variables will be:
Examiner's Comment = A+ B+C + D
(ii) The minterm corresponding to the given
w Some candidates were not familiar with the
values of the variables will be:
SOP expression. Actual meaning and features
of canonical expression were not clear to many = ABCD
candidates. Q. 11. Convert the following function into its canonical
sum of product form
F(x, y, z) = S (0, 1, 5, 7) [ISC 2010]
Answering Tip Ans. Given function is,
F(x, y, z) = (0, 1, 5, 7)
w Do more practice for solving SOP and POS type of So, the canonical form, of function F will be:
Boolean expression. Both canonical and cardinal F = m0 + m1+ m5+ m7
forms should be practical.
= 000 + 001 + 101 + 111
So, F(x, y, z) = x'y'z + x'y'z + xy'z + xyz
These questions are for practice and their solutions are available at the end of the chapter
I
Q. 12. For the given truth table where A, B, C are inputs 0 1 1 m3 ovw
BOOLEAN ALGEBRA

M3 o+v+w
27

and X is the output,


1 0 0 m4 ovw M4 o+v +w
A B C X 1 0 1 m5 ovw M5 o +v+ w
0 0 0 1 1 1 0 m6 ovw M6 o +v+ w
0 0 1 0 1 1 1 m7 ovw M7 o+v+w
0 1 0 0 From the above table ,
0 1 1 1 F = m0 + m1+ m3+ m5

1 0 0 1
= S (0, 1, 3, 5)
Now, it is known that the complement of a
1 0 1 0 minterm is equal to its corresponding maxterm
1 1 0 1 F = M2.M4.M6.M7
1 1 1 0 So, the canonical POS form of F is,

Write,
-
D = (o + v + w) - (o + v + w) - (o + v + w) (o + v + w)

(i) Canonical sum of Product expression (SOP)


.
Q. 16. Convert ( x' + y + z').(x + y' + z ).(x + y + z') (x + y + z)
into SOP form. [ISC 2006]
[ISC 2009]
Ans. Given (x + y + z ). (x + y + z). (x + y + z ).(x + y + z)
' ' ' '
(ii) Canonical Product of Sum expression (POS)
Now, we will find the form of F using truth table
.
Ans (i) Canonical Sum of Product expression is: as:
ABC + ABC + ABC + A - B C - x y z Maxterm Maxterm Minterm Minterm
(ii) Canonical Product of Sum expression is:
expression expression
-
(A + B + C) (A + B + C) - (A + B + C) - (A + B + C)
0 0 0 M0 x+y+z mo x'y'z'
. .
Q 13 Convert the following Product of Sum ( POS) form
0 0 1 Mj x + y + z' x'y'z
into its corresponding Sum of Product (SOP) mi
form. [ISC 2008]
0 1 0 M2 x + y' + z m2 x'yz'
F(x, y, z ) II ( 2, 4, 6, 7)
0 1 1 M3 x+ y +z
' ' m3 x'yz
=
1 0 0 M4 x' + y + z m4 xy'z'
Q. 14. Given: F ( x, y, z ) = S(l, 3, 7) [ISC 2008]
1 0 1 M5 x' + y + z' m5 xy'z
Prove F(x, y, z ) = P (0, 2, 4, 5, 6)
Ans. Given expression is,
1 1 0 M6 x' + y ' + z m6 xyz'
F (x, y, z) = S(l, 3, 7) 1 1 1 M7 x' + y ' + z' % xyz
F = Complement of S( l, 3, 7) From the above truth table,
F = M5- M2- Mj- M0 = S (0, 1, 2, 5)
_ = P (0, 2, 4, 5, 6)
F = Complement of P (0, 2, 4, 5, 6) F = n (0, 1, 2, 5)
The SOP form for above expression is,
= S(l, 3, 7)
It is proved that SOP form, i.e., S( l, 3, 7) and POS F' = S(3,4,6,7) = m3 + m4 + m6 + m7
form, i.e., P(0, 2, 4, 5, 6) are complement to each F = x'yz + xy 'z' + xyz' + xyz
other. Q.17. Write the Product of Sum ( POS) form for the
. .
Q 15 Convert the following SOP expression into its Boolean function F ( A, B, C) whose output is 0
corresponding POS form . only when, [ISC 2006]
F(o,v,w) = ovw + ovw + ovw + ovw A = 1, B = 0, C = 0
[ISC 2007] A = 0, B = l, C = 0
Ans. Given function is, A = 0, B = 0, C = 1
F(o,v,w) = ovw + ovw + ovw + ovw A = l, B = l, C = 1
To convert SOP expression into POS expression .
Ans From the given description, the truth table for
make a truth table as: three variable A, B and C is as follows:
o v w Minterm Minterm Maxterm Maxterm A B C F(A, B, C) Maxterm Maxterm
expression expression expression
0 0 0 1 Mo A+ B+C
0 0 0 m0 ovw M0 o+v+w
0 0 1 0 Mt A+ B+C
0 0 1 mj ovw Mj o+v+w
0 1 0 0 Mj A+ B+C
0 1 0 m2 ovw M2 o+v +w
0 1 1 1 Ms. A+ B+C
28

1
Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

00 0 M4 A + B+C = (L.U + M + P) -
( .. A. A'
I
= 0)
1 01 1 Ms. A + B+C = (0 + M + P) (by complement law)
1 1 0 1 Me A + B+C
F = (M + P) (by identity law)
This is the simplified form of F.
1 1 1 0 M7 A + B+C
To find the POS form for F, we need to find Q. 2. What are maxterms? Convert the following
maxterms for which the value of F is 0 and these function as a product of maxterms.
are Mj, M2, M4 and M7. F(P, Q, R) = (P + Q). (P' + R') 0 [ISC 2010]
So, F = Mj. M2. M4. M7 Q. 3. Simplify the following expression and convert it
F = (A + B + C).(A + B + C).(A + B + C).(A + B + C) to its canonical POS form.
Q.18. What is the canonical form of Boolean expression? ((x.y ) + z). (y + (z\ x) ) [ISC 2009]
State the two types of canonical forms. [ISC 2005] Ans. Given expression is,
Ans. A Boolean expression is in canonical form when it F = (x. y + z) (y + z'. x)
is composed entirely of Minterms and Maxterms.
F = (x + z). (y + z). (y + z'). (y + x)
There are two types of canonical forms: (by distributive law)
(i) Canonical SOP expression = (x + z). (y + z). (y + z'). (x + y)
(ii) Canonical POS expression (by communicative law)
Now, we will convert F into canonical form,
Answer Type
<&\ Short
Questions-II (4 marks each)
F = (x + 0 + z).(0 + y + z).(0 + y + z').(x + y + 0)
(z + yy' + z).(xx' + y + z)(xx' + y + z')(x + y + zz')
Q. 1. Convert the following cardinal expression into its (by distributive law)
canonical form and reduce it using Boolean laws. F = (x + y + z).(x + y' + z).(x + y + z)(x’ + y + z)
F (L, M, O, P) = P (0, 2, 8, 10) (x + y + z').(x' + y + z')(x + y + z)(x + y + z')
[ISC 2011] (by complement law)
Ans. Given function is, = (x + y + z).(x + y + z).(x + y + z).(x + y' + z).
F(L, M, O, P) = P (0, 2, 8, 10) (x' + y + z).(x' + y + z').(x + y + z').(x + y + z')
It is clear that the function F is in POS form and F = (x + y + z).(x + y' + z).(x' + y + z).(x' + y + z')
contain the maxterm 0, 2, 8 and 10. •(x + y + z')

i.e„ F = M0. M2. M8. M10 (by idempotent law)


Canonical POS form of F is, Q.4. Convert A.B + B.C to its canonical SOP form
F = (L + M + 0 + P).(L + M + 0' + P) using Boolean algebra. [ISC 2008]
. (L' + M + 0 + P).(L' + M + 0' + P) Ans. The given function is,
Now, we will simplify the above expression by F = A.B + B.C
using Boolean laws. F = A.B.l + l.B.C (by identity law)
F = (L + M + 0 + P).(L + M + 0’ + P). = A.B.(C + C) + (A + A).B.C
(L' + M + 0 + P).(L' + M + O' + P) (by component law)
= (L + M + 0 0' + P). (L' + M + OO' + P) = ABC + ABC + ABC + ABC
(by distributive law) F = ABC + ABC + ABC (by idempotent law)
= (L + M + 0 0 + P). (L' + M + 00' + P)
' Q. 5. Prove that
(by complement law) F( A, B, C) = TI(2, 3, 4, 7) = S(0, 1, 5, 6)
= (L + M + P). (L' + M + P) (by identity law) 0 [ISC 2005]

I TopiC-4

Revision Notes
Karnaugh Map (K-map)
Conceptscovered:KamaughmapiRedudngabooleanexpressionintoitscanomcal
form using K-map

> Karnaugh Map (K-map) Method: It is a most popular method for simplification of Boolean expressions of two
variables, 3-variables, 4-variables and so on. It is a graphical display of the fundamental products in a truth table.
It is a rectangle made up of certain number of squares, each square representing a maxterm or minterm.

These questions are for practice and their solutions are available at the end of the chapter
I Representation of K-maps:
BOOLEAN ALGEBRA 29

, vB B B BCBC BC BC BC
A \ Q 1 A \ 00 01 11 10
A A 0
° o 2 0 1 3 2
A 1 A 1
2 3 4 5 7 6
2-VariablesK-map 3-Variables -map
K
CD CD CD CD
AB \ op pi ii ip
AB 0
°
AB 01
0 l 3 2

4 5 7 6
AB 11
12 13 15 14
AB 10
8 9 11 10
4-Variables K-map
> -
Possible combinations 2n cells for n variables:
— -
2 variables K-map (4 cells): AB, AB, AB, AB.
— -
3 variables K-map (8 cells): ABC, ABC, ABC, ABC, ABC, BC, ABC, ABC

>
—- -
4 variables K-map (16 cells): Take combination as shown in the k-map
K map Simplification Rules: K-map uses the following rules for the simplification of expressions by grouping
expressions together in the form of Octet, Quad and Pair.
Some rules are as follows:
• Groups must contain 1, 2, 4, 8, or in general 2n cells.
• That is if n = 1, a group will contain two l's since 21 = 2.
A
B 1

0 •' 1 1 Group of 2

1 0 0

• Groups may not include any cell containing a zero It means we cannot make a pair of 0 and 1
. .
• Groups may be vertical or horizontal, but not diagonal
B B
.

A \ B B A \ B B
A o i/ n'
'
A m I

A 7T A o:M
Incorrect Pattern Correct Pattern
• Each groups should be as large as possible i.e., Octet
(8 adjacent l's), Quad (4 adjacent l's) and pair (2 adjacent l's)

or: ID or: ID or; no f ; "


i

OC r. 'D. J
Incorrect Pattern Correct Pattern
• Groups may overlap as shown above in the correct pattern.
• - -
In a K map, first find out all possible Octet group, then Quad group and at the end make pairs. Then you will
found the optimal solution or simplest form of given expression.
30


Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
Each group should be as large as possible.
. I
A
BN BO 01 11 10

0 1 1 1 1

1 1 1

OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. The group which eliminates the maximum Q. 4. Which of the following is a very popular
variables in a Karnaugh's map is: technique used for the simplification of Boolean
[ISC Sem-1 Paper 2021-22] expressions?
(A) Quad (B ) Octet -
(A) K map (B ) POS
(C) Pair (D) Redundant (C) SOP (D) None of these
Ans. Option (B ) is correct. Ans. Option (A ) is correct.
Explanation: In Karnaugh's map maximum variable -
Explanation: K map is very popular technique used
can be used in an octet. Because in octet 8 blocks for the simplification of Boolean expressions. It is
will group together. drawn in the form of a diagram divided by rows
and columns into squares and the number of square
Q. 2. Reduce the given Boolean function F(A,B,C,D) corresponds to a raw number in the truth table.
= S(6,7,10,11,12,14,15) by using 4-variable Karnaugh Q. 5. What is the expression represented by the given
map and answer the following question: K-map?
What will be the least number of groups and its
\BC
__ __
types formed for reduction K-Map\ [0, 0] BC [0] BC [11] BC [10] BC
[ISC Sem-1 Paper 2021-22] [OJA 0 1 1 3 1 2
(A) 4 pairs
(B ) 2 quads and 1 pair
[1] A 4 5 1 7 1 6 l
(A) B (B) AB
(C) 1 quad and 2 pairs (C) ABC (D) ABC + ABC
(D) 3 quads Ans. Option (A) is correct
Ans. Option (B ) is correct. Q. 6. The set of non-redundant groups in the given
Explanation: After plotting Karnaugh's map it K-map are:
will produce 2 quads (cell number (6,7,14,15) and CD
(10,11,14,15)) and one pair (cell number (12,14)). AB CD [0 0] CD[01] CD [ii ] CD[i 2]
Q. 3. Reduce the given Boolean function F(A,B,C,D) [00] AB 1 1
= p(3,4,5,6,7,10,12,13,14,15) by using 4-variable 0 1 3 2
Karnaugh map and answer the following [01] AB 1 1
question: 4 5 7 6
What will be the least number of groups and its [11] AB 1 1
types formed for reduction? 12 13 15 14
[ISC Sem-1 Paper 2021-22] [10] AB 1 1 1
(A) 1 octet and 2 pairs 8 9 11 10
(B ) 2 quads and 2 pairs (A) Quad 1 (0,4,8,12)
(C) 1 octet and 3 pairs Quad 2 (4,5,12,13)
(D) 4 pairs Quad 3 (8,9,12,13)
Ans. Option (A ) is correct. Pair 1 (2,10)
Explanation: After plotting Karnaugh's map it will (B ) Quad 1 (4,5,12,13)
Quad 2 (8,9,12,13)
produce 1 octet (cell number (4,5,6,7,12,13,14,15)
Pair 1 (0,4)
and two pairs cell number (3,7) and (10,14).
Pair 2 (4,12)
I (C) Quad (0,4,8,12) (A) 4
BOOLEAN ALGEBRA
(B ) 1
31

Pair 1 (2,10) (C) 3 (D ) 2


(D) Quad 1 (0,4,8,12) Ans. Option (D) is correct.
Quad 2 (4,5,12,13) Q. 9. Consider the K-map given below:
Quad 3 (8,9,12,13) DH
Ans. Option (A ) is correct. RP [0 0] D + H [01]D + H' [11]D' + H' [10]D' + H
Q. 7. The Canonical expression represented by the
given K-map is [00] R + P 0 0 0 0
BC 0 1 3 2
A BC [o 0] BC[01] BC [ii ] BC [10]
[01] R + P' 0
[0] A 1 1 1 1 4 5 7 6
0 1 3 2
[11] R' + F 0
[1] A 1 1 1 1 12 13 15 17
4 5 7 6
(A) 2(0,1,3) (B) 71(0,1,2,3,4,5,6,7) [10] R' + P 0 0
(C) £(0,1,2,3,4,5,6,7) (D) 0 8 9 11 10
.
Ans Option (C) is correct. The terms for Quads (M0M4M8M12) will be:
.. -
Q 8 Number of non reduntant group in the given (A) P + D ( B) P + D
-
K map is:
CD R+P D+H
AB CD [0 0] CD[Q l] CD [ii] CD[io] (C) R + P (D) D + H
[00] AB 0 0 0 0 D+H R+P
0 1 3 2 .
Ans Option (B) is correct.
[01] AB 1 1 1 0
4 5 7 6
[11] AB 1 1 1 0
12 13 14 15

[10] AB 0 0 0 0
8 9 11 10

SUBJECTIVE TYPE QUESTIONS


There are two octets and one quads:
Short Answer Type
<©> Questions- I ( 2 a 3 marks) Octetl (m0 + m1 + m2 + m3+ m8 + m j+ m10+ m11)
(

= B'
..
Q 1 Given the Boolean function:
,
Octet2 (m0 + m + m 4 + m 5 + m8 + m 9 + m12 + m13)
F(A, B, C, D)
= 2 (0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13,14). = C'
Reduce the above expression by using 4 variable - Quad (m8 + m10 + m12 + m14) = AD'
Karnaugh map, showing the various groups (i.e.
Hence, F (A, B, C, D) = B' + C' + AD'
octal, quads and pairs). [ISC 2020]
[ISC Marking Scheme, 2020]
Ans.
Q. 2. Given the Boolean function:
CD' C'D CD CD'
= 7t( 3, 4, 6, 9, 11, 12, 13, 14, 15 ).
F( A, B, C, D)
0 -t 3 2 Reduce the above expression by using 4-variable
A'B' 1 1 1 1 Karnaugh map, showing the various groups (i.e.

A'B
4
1
5
1
7
0
6
0
octal, quads and pairs). [ISC 2020] < ) ®
Q. 3. Minimise the following Boolean expression using
12L 13 15 14 the Karnaugh map.
AB 1 1 0 1
9 11 10
F( A,B,C) = ABC + ABC + ABC + ABC
8 [ISC 2014]
AB’ 1 1 1 1

These questions are for practice and their solutions are available at the end of the chapter
32 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII . I
Ans. \BC BC BC BC BC
B'C' B'C BC BC' As|
Quad-1
A'
0 1 T 2 A 1
0 0 1 1
0 1 3 2
4 5 7 6
A 0 0 1 1
A 1 1
[ISC Marking Scheme, 2014] 4 5 7 6
Quad. 1 = m2 + m3 + m6 + m7 = B
So, minimised Boolean expression is:
Examiner's Comment F(A, B, C) = B
Q. 4. Reduce the following expression,
w Almost all candidates answered this part correctly
F(A, B, C) = S (0, 1, 2, 3, 4, 5, 6, 7)
except for a few who did not use the K map for - Also, find the complement of the reduced
reducing but used the laws instead K map plotting - expression. [ISC 2011]
was not correct in some cases. Ans. Given expression is,
F(A, B, C) = S(0, 1, 2, 3, 4, 5, 6, 7)
-
Now, draw the K map according to the given
Answering Tip minterms
BC
A BC BC BC BC
w Do practice in minimizing Boolean expressions 0 1 3 2
- -
using k maps. 3 variable k maps should also be A I 1 1 1
1 Octet
practiced for short answers. 3
4 5 7 6
A 1 I
Detailed Answer: 1 1
7
Given expression is,
F(A,B,C) = ABC + ABC + ABC + ABC
In a three variables K map octet means given -
function will produce output 1, i.e., tautology,
Here, we have three inputs A, B and C. So, while i.e., F (A, B, C) = 1
-
draw the K map, we need 2" = 23= 8 squares. the complement of F, i.e.,
F = 1' = 0
..
Q 5 Reduce the following three input function into its
simplest form .
-
F(x, y, z) = S (0, 1, 3, 5) [ISC 2006] #

These questions are for practice and their solutions are available at the end of the chapter
I BOOLEAN ALGEBRA

Solutions for Practice Questions


TOPIC-1 23. According to the principle of duality, interchange
2 Marks Questions ( + ) with (•) and (•) with ( + ). So, the dual of
.
3 Given expression, expression P 'QR ' + PQ 'R + P 'Q R, say X is,
(X => Y) A (Y => X) = X <=> Y X = (P ' + Q + R ')-(P + Q ' + R)(P ' + Q ' + R)
L.H.S.(X => Y) A (Y => X) Now, let us assume the complement of
R.H.S. X « Y PQ 'R + Q • (P 'R ' + PR ') = Y.
Truth table So, Y = [PQ 'R + Q (P'R ' + PR ')] '
X Y X => Y Y => X (X => Y) A (Y => X) X <=> Y = (PQ 'R) ' [Q (P'R ' + PR ')] '
0 0 1 1 1 1 (by demorgan's law)
0 1 1 0 0 0 = ( P '
+ Q "
+ R ') [QP ' R '
-+ QPR ' ] '
1 0 0 1 0 0 (by demorgan's law)
1 1 1 1 1 1
= (P' + Q " + R 'HQP 'R ') ' (QPR ' ) '
L.H.S. R.H.S.
(by demorgan's law)
7.
p —>q
= (P +' Q " '
-
+ R ) (Q ' + P " + R " )
p iL pq yL -
P q pq + pq (p-> q ) p •(Q ' + P ' + R " )
0 0 0 1 0 0 1 0 0
0 1 0 0 0 0 1 1 0 (by demorgan's law)
1 0 0 1 1 1 0 1 1 = ( P '
Q
+ + R 'HQ '
+ P + R)
1 1 1 0 0 1 0 1 1 •(Q ' + P ' + R)

B A (by involution law)


A = B => Hence verified = ( P '
+ Q + R ') (P
-+ Q ' + R)
In the above table (.) means A, + means v, and '

(P' + Q ' + R)
(bar) means Now, we can see that X = Y, hence the dual of
4 Marks Questions expression P 'QR ' + PQ 'R + P 'Q 'R is equal to
.
4 Contingency: The propositions that have some the complement of PQ 'R + Q (P 'R ' + PR ').
combination of 0's and l's in their truth table .
30 Given boolean expression is
column are called contingency. - -
F = x y(x y + y z) -
Contradiction: The propositions having only 0's in - - - -
= (x y)(x y) + (x y)(y z)
their truth table column are called contradiction. (by distributive law)
Tautology: The propositions having only l's in
their truth table column are called tautologies.
- - -
= (x y) + (x y)(y z) (by idempotent
law)
TOPIC- 2 F = xy - (by absorption law)
36. Boolean algebra plays a vital role in computer
2 Marks Questions
science for designing logic circuits and simplifying
.
3 Find the dual of : circuits. In boolean algebra, the variable can take
(A ' + 0) • (B ' + 1) = A' only two variables, i.e., either true (1) or false (0)
and hence, it is compatible with binary arithmetic
Dual = A' * 1 + B' * 0 = A' used in simplifying the designing of computer
[ISC Marking Scheme, 2020] hardware.
.
10 Boolean equation 4 Marks Questions
L.H.S. = AB ' + BC ' + 1 .
2 Complement properties:
On applying the duality A + A ' = 1 and A A ' = 0 -
= (A + B') • (B + C ') 0 - Complement of AB ' + A ' + BC
= (A + B') 0 = 0 - = (AB ' + A ' + BC) '
On applying the duality -
= (AB ') ' (A ') ' (BC) ' -
R.H.S. = 0 = (A ' + B)-A (B ' + C ') -
L.H.S. = R.H.S.
.
8 Given that,
-
F = xy (xyz + x + xz)
15. (XY 'Z + XY + YZ ') Dual of F = (x + y) + (x + y + z)-(x)-(x + z)
(X ' + Y + Z ') • (X ' + Y ') • (Y ' + Z) = (x + y) + (x + y + z)-(xx + xz)
or (X ' + Y + Z ') • (Y ' + X 'Z) (by distributive law)
[ISC Marking Scheme, 2014] = (x + y) + (x + y + z)-(0 + xz)
(by complement law)
34 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

(x + y) + (x + y + z)-xz .
I
=
_ _ _Jby identity law) 5 Given that
F(A, B, C) = n(2, 3, 4, 7)
= (x + y) + (xxz + xyz + xzz) F = 71(0, 1, 5, 6)
_ _ (by distributive law) = M0 My M5, M6
/

= (x + y) + (xz + xyz + xzz) By involution law,


(b idempotent law)

_ ^_
F = (F')' = (Mo. M y M5. M6)'
= -
(x + y) + (xz + xyz + x 0)
F = Mo'. M' j. M'5. M'6
_ (by complement law)
It is known that the complement of a maxterm is
= (x + y) + (xz + xyz + 0)
equal to its corresponding minterm.
(by basic postulates)
F = m0 + mj + m5+ m6
= (x + y) + (xz + xyz)
F = 2(0, 1, 5, 6) Hence proved.
(by identity law)
F = x + y + xz (by absorption law)
TOPIC-4
TOPIC-3 2 Marks Questions
2 Marks Questions
.
3 Now A. A = 0, similarly, C.C' = 0 2.
so, (B + C') = (B + C' + A.A) C+D C + D1 C + D’ C+ D
= (B + C' + A) (B + C' + A1) 0 1
[Treating B + C' as a single variable] 3 2
A +B 1 1 0 1
and (A' + B) = (A' + B + C.C')
= (A' + B + C)(A' + B + C') + 5 7 6
[Treating A' + B as a single variable]
A + B' 0 1 1 0
F (A, B, C) = (B + C').(A' + B) 12 13 15 14
A' + B’ 0 0 0 0
= (B + C' + A)(B + C' + A')(A' + B + C)
(A' + B + C') 8 9 11 10
= (B + C' + A)(A' + B + C')(A' + B + C) A' + B 1 0 0 1
[(B + C' + A')(A' + B + C) = (A' + B + C')]
.
6 Given expression, There are two quads and one pair:
F(X, Y, Z) = X'Y'Z + X'YZ' + XYZ Quad 1: (M4M6M12M14) = B' + D
= 001 + 101 + 111 Quad 2: ( M9M11M13M15) = A' + D'
(putting 0 for complements and 1 for the terms)
Pair: (M3Mn) = B + C' + D'
= m| + m2 + m7
(converting each of these to decimal equivalents) Hence F(A, B, C, D) = (B' + D) • (A' + D')
F in cardinal form, • ( B + C' + D' )
F(X, Y, Z) = S(l, 2, 7) [ISC Marking Scheme, 2020]
.
13 Given function is, .
5 Given expression is,
F (x, y, z) = 11(2, 4, 6, 7) F (x, y, z) = S(0, 1, 3, 5)
As we knew, SOP and POS both are complement i.e., F = m0 + nri] + m3 + m5
to each other. As we know,
Hence, sum of product of F(x, y, z) m0 = x'y'z'
= complement of P (2,4,6,7) mi = x'y'z
i.e., = S(0, 1, 3, 5) m3 = x'yz
4 Marks Questions m5 = xy'z
.
2 Maxterms: It is the sum of all literals within the F = x'y'z' + x'y'z + x'yz + xy'z
yz
logic system. yz yz yz yz
X
Given function is,
F(P Q, R) = (P + Q).(P' + R')
To convert the function F into product of X 1
0
in 1 3 3 2
maxterms, we need to add missing variable in
these terms as,
F(P Q, R) = (P + Q).(P' + R') X 1
= (P + Q + 0).(P' + 0 + R') 4 5 7 6
= (P + Q + RR').(P' + QQ' + R')
(by complement law)
Pair 1 = xy
= ( P + Q + R ).(P + Q + R') Pair 2 = xz
, (P' + Q + R').(P' + Q' + R')
Pair 3 = yz
(by distributive law)
-
. . F(R Q, R) = Mo . Mj . M5 . M7 So reduced expression will be x'y' + x'z + y'z.
,
I
SELF ASSESSMENT PAPER 1 -
Maximum Marks: 25 Timing: 1 Hour
.
1 What is a proposition? [1]
2. Find minterm designation of xyz. [1]
3. Find maxterm designation of ( u' + v' + w) [1]
4. Find the dual of following:
(a + b) (b + c) (a + c) [1]
.
5 What are different types of connectives used in propositional logic? [2]
6. Prepare truth table for the following algebraic expression.
xy + x'y' + xz [2]
. = (a + b) (c' + a') (b + d ) Find F'.
7 If F ; [2]
8. Convert (x + z)(z + y) into conical pos form. [2]
9. Draw the truth table for a boolean function F defined on three input variables X, Y and Z such that the output is
1 if and only if number of 1 inputs is odd. Also express canonical sum of product form. [2]

10. Minimize the following using k-map


F (x, y, z, w) = wxyz + wx'y'z' + w'xyz + wxy'z' [3]

11. Draw and simplify map of a, b, c for


(a + b + c) (a' + b + c) (a + b + c') [3]

.
12 Given: X (A, B, C, D) = 7t(0, 2, 6, 8, 10, 14). Use k-map to reduce this function X using the given POS form. [5]
n

OSWAAL LEARNING TOOLS


For Solutions of the above Self Assessment Paper, follow the link

Visit: https:// bit.ly/ 3zJePhu Or Scan the Code


CHAPTER

COMPUTER
HARDWARE
-
Iuggp (a ) Elementary logic gates (NOT, AND, OR, NAND, NOR, XOR, XNOR)
and their use in circuits, ( b ) Applications of Boolean algebra and logic
gates to half adders, full adders, encoders, decoders, multiplexers, NAND,
NOR as universal gates.

I
Logic Gates Topic- 1
. Concepts covered: AND, OR , Not logic
TopiC-1 gates; Universal logic gates; XOR , XNOR
Logic Gates
.
Page No 36
gates; Realisation of logic gates using
Topic-2
universal gates.
Designing Simple Logic
Circuits
.
Page No 48
Topic- 3
Revision Notes
Combinational Circuits
. .
Page No 70
> A logic gate is an electronic circuit which operates on one or more signals
to produce an output signal.
> Every logic gate produces signals in the form of 0 and 1. If any gate acts as a open circuit, output for the given
inputs are not produced.
• types of Logic Gates:
The logic gates represent electronic circuits in Boolean algebra. There are two types of logic gates namely:
1. Fundamental or Elementary Logic Gates
2. Universal Gates
1. Fundamental Logic Gates: AND, OR and NOT gates are called fundamental logic gates.
(i) AND Gate: This logic gate contains at least two inputs and one output. It will give output when all
inputs are enabled in the form of 1.
A B X = A.B
0 0 0
P
^JAND ) X = A.B 0
1
1
1
0
1
0
0
1
(ii) OR Gate: This logic gate contain at least two inputs and single output. It enables or gives output if any
one of the inputs are enabled in the form of 1.
A B X =A+B
0 0 0
A
B
X = A+B 0 1 1
1 0 1
1 1 1
,
^3
A
>A©B = AB + AB

A B A©B
0 0 0
0 1 1
£agic Qatea
1 0 1
1 1 0

Universal Gates
AOB = AB + AB

A B AOB
0 0 1
0 1 0
1 0 0
NAND
1 1

Trace the Mind Map


* First Level Second Level Third Level

I
Combining the different gates
in a circuit
I
CO
00

Truth Table
9
y Sum Carry
I
txf Mux.
-.
e% o o 0
o n
0f two bits l l
a
(D
in
Truth Table
Sl So Y
§
CD
0 CD
A"
0 n
l
Io
1
Ii
Truth Table I
12 y z Sum Carry £
13 0 0 0 0
s?
0 1 1 0
o '
1
1
0
1
1
0
0
1
*sI
0
0
0
1
1
0
0
1 s2
1 0 0 1
1 1 1 1
2
30
Rm
Sum Z
xffiy® z n
Truth Table
Carry n
D2 Dl Do ST
x.y + z(x ®y)
0 0 1
0 0 1
0
1
1 0
o o 0
0
1 1
Truth Table
x y. Do Dl
{ >
* O— D -
o
0
1
l
o
0
l
[ 0

0
I

JL
o
1
1.
0
l
0
1.
1
D D‘ —
Trace the Mind Map
First Level Second Level ^
Third Level Logic diagra*1 .
^
I COMPUTER HARDWARE
(iii) NOT Gate: It has only single input and single output. It acts as inverter.
39

A A
A or A'
0 1
1 0
2. Universal Gates: NAND and NOR gates are known as universal gates. With the help of these gates all
fundamental gates can be created.
(i) NAND Gate: It is a universal logic gate. It is the combination of NOT and AND gate. All possible
outputs in NAND Gate is opposite of the outputs of AND gate.
A B X
0 0 1
A — NAND, X = (A . B)'
0 1 1
B — 1 0 1
1 1 0
(ii) NOR Gate: It is also a universal logic gate. It is combination of NOT gate and OR gate. All possible
outputs in NOR gate is opposite of the outputs of OR gate.
A B X
0 0 1
A X = (A + B)'
INOR ] 0 1 0
B
1 0 0
1 1 0
• Others Specific Logic Gates:
. -
1 Exclusive OR (X OR) Gate: It is a digital logic gate that gives a True (1) output when the number of True
inputs is odd.
X-OR gates are used to implement binary addition in computer. The algebraic notation used to represent
the XOR operation is X = A ® B
A B X
0 0 0
A X= A©B
|X OR 0 1 1
B or
X = A'B + AB’ 1 0 1
1 1 0
2. -
Exclusive NOR Gate: It is combination of Not gate and XOR gate. It is the logical complement of the XOR
gate. It gives a True (1) output when all of its inputs are True (1 or High) or when all of its inputs are false
(0 or Low). The algebraic notation used to represent the XNOR operation is S = A © B
A B X
0 0 1
A X = AOB
XNOR) or 0 1 0
B
X = A'B' + AB 1 0 0
1 1 1
• Realisation of Logic Gates using NAND Gate:

NOT Gate AND Gate


40 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
X =A+B

OR Gate
• Realisation of Logic Gates using NOR Gate: r

r
A'
A

NOT GATE AND Gate

(A + B)'
A X = (A + B)
B

OR Gate

|Key Terms
> Elementary Logic Gates are NOT, AND, OR Gates
> Universal Gates are NAND gate and NOR gate because with the help of these gates, fundamental/elementary
gates can be created.
> AND Gate: Two inputs (at least) and one output is required for AND gate. If both inputs are true (1), then output
will be true, otherwise false (0).
> OR Gate: At least two inputs and single output is required for OR gate. It is represented by ' + ' symbol in logical
expressions when any input out of the given inputs in True (1), then output will be True (1), otherwise False (0).
>
> NAND Gate: Complement of AND gate values is termed as NAND gate. It is also called universal gate.

NOT Gate: It acts as inverter. If input is True (1), then output is False (0) and vice-versa. It is shown by ' ' or ' ' '.

> NOR Gate: Complement of OR gate is termed as NOR gate.


> X-OR Gate: These are used to implement binary addition in computer. It is shown by '©' symbol.
> X-NOR Gate: It is the complement of XOR gate. It is represented by '©' symbol.

OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. When three NAND gates are placed in series, it Q. 2. With reference to the logic diagram given below,
performs: [ISC Sem-1 Paper 2021-22] where X, X', Y and Z are inputs and F is the
(A) NAND operation output, answer the question 2-4:
(B ) AND operation
(C) OR operation
(D) NOR operation
Ans. Option (A ) is correct.
Explanation: From first get it product NAND,
then second gate convert the NAND into AND
and third gate once again convert it into NAND.

[ISC Sem-1 Paper 2021-22]


I
Q. 3. What is the expression at (1)?
COMPUTER HARDWARE 41

(A) X.Y (B) X' + Y' (C) A


(C) X + Y (D) X + Y'
Ans. Option (C) is correct. (D) X [_
Explanation: OR gate produce X + Y
Q. 4. What is the expression at (2)? Ans. Option (C) is correct.
(A) (X + Z)' (B) (X + Z') Explanation: The word NOR gate is just an short
(C) X' + Z (D) (X'.Z)' of the NOT and OR gate combination. NOT gate
Ans. Option (D) is correct. is one that outputs the opposite state as what is
input.
Explanation: NAND gate produced (X'.Z)'
.
Q. 5 What is the final expression F(X,Y,Z)? The NOR gate is
(A) (XY + X'Z)' (B) ((X + Y) + (X'.Z)')'
(C) ((X + Y).(X'.Z)')' (D) (X' + Z) + (XY)'
Ans. Option (B) is correct. The NOR gate is
Explanation: NOR gate of expression 1 and 2 will
produce the output as ((X + Y) + (X'.Z)')'. Q. 9. Which of the following is the truth table of AND
.
Q. 6 Identify the following gate
gate?
A (A ) A B X ( B) A B X
X 0 0 0 0 0 0
B
0 1 1 0 1 0
(A) AND (B) OR
1 0 1 1 0 0
(C) NOT (D) XOR
Ans. Option (B) is correct. 1 1 1 1 1 1
Explanation: An OR gate is a digital logic with (C) A B X (D) A B X
two or more inputs and one output that performs
0 0 1 0 0 0
logical disjunction. The output of an OR gate is
true when one or more of its inputs are true. If all 0 1 0 0 1 1
of an OR gate's inputs are false, then the output of 10 0 1 0 1
the OR gate is false. 110 1 1 0
A
The OR gate is
B
X Ans. Option (B) is correct.
Explanation: The output state of the AND gate will
where A and B are inputs and X is output.
always be low when any of the inputs states is low.
..
Q 7 Which of the following is an electronic circuit Simply, if any input value in the AND gate is set to
involving execution of a designed Boolean/logical 0, then it will always return low output (0).
operation?
Truth table
( A ) Logic gate
(B) Truth table A B X
(C) Propositional logic 0 0 0
(D) Boolean algebra 0 1 0
Ans. Option ( A) is correct. 1 0 0
Explanation: A logic gate is an electronic circuit 1 1 1
involving execution of a designed Boolean/logical Q. 10. Which algebraic function is denoted the XOR ?
operation. It acts as a building block for digital
circuits. Logic gates will make decisions based on (A) X = A'B + AB' (B) X = A'B’ + AB
a combination of digital signals coming from its (C) X = (AB)’ (D) X = (A + B)'
inputs. Most logic gates have two inputs and one Ans. Option (A ) is correct.
output. Explanation: XOR gate stands for exclusive-OR
Q. 8. Which of the following gate represents NOT gate gate. This gate is a special type of gate used in
using NOR gate? different types of computational circuits. In EX-OR
function, the logic output '1' is obtained only when
either A = 1 or B = 1 but not both together at the
(A ) A
same time. Simply, the output of the XOR gate is
high (1) only when both the inputs are different
(A + B)’ from each other.
A F=A+ B
( B) XOR is denoted by
B
X = A'B + AB'
X = A©B
42 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 11. Which of the following is/are universal gate(s)? output level of the XNOR gate is high only when
I
(A) NAND (B ) NOR both of its inputs are the same, either 0 or 1. The
(C) NOT (D) Both a and b truth table of XNOR gate is:
Ans. Option (D) is correct. A B F
Explanation: NAND and NOR gates are known as 0 0 1
universal gates because all the other gates (AND,
0 1 0
NOT, OR) can be constructed using only these
two gates. Any Boolean or logic expression can be 1 0 0
realised by using AND, OR and NOT gate. These 1 1 1
two operations NAND and NOR are sufficient for
realisation of any logic expression. Q. 15. Which of the following gate is constructed by
Q. 12. Name the gate which is showing in following fig? expression F = A.B.C?
A
Input (A ) B
A Output C
B A
(B ) B
(A) NAND gate (B ) NOT gate C
(C) NOR gate (D) OR gate A—
Ans. Option (C) is correct.
(Q B
c—

Explanation: The NOR gate is a combination of OR A—
gate followed by an inverter. Its output is "True" if (D) B —
both inputs are "False", otherwise, the output is C—
"False". Ans. Option (C) is correct.
Input Explanation:
A Output
B represents the AND gate
Q. 13. The basic elements of circuits are called The output state of the AND gate will always be
(A) Logics (B ) Gates low when only of the inputs states is low. Simply, if
(C) Boolean (D) Adders any input value in the AND gate is set to (0), then
Ans. Option (B ) is correct. it will always return low output (0).
Explanation: The basic elements of circuits are So its expression is F = A.B.C
called gates. Using these gates, we can apply the Q. 16. What are the values of inputs if output = 1 for the
rules of Boolean algebra to design circuits that following logic gate?
performs a variety of tasks. Input
A Output
Q. 14. Which truth table is used for given gate?
B
A
B
(A ) A = 0, B = 1 (B ) A = 0, B = 0
(C) A = 1B = 0 (D) A = 1, B = 1
(A) A B F (B ) A B F Ans. Option (B ) is correct.
0 0 1 0 0 1 Explanation: The NOR gate is the combination of
0 1 0 0 1 0 the NOT-OR gate. The output state of the NOR
1 0 0 1 0 1 gate will be high only when all of the inputs are
1 1 1 1 1 1 low. Simply, this gate returns the complement
result of the OR gate
(C) A B F (D) A B F In NOR gate, when inputs A = 0 and B = 0 then
0 0 0 0 0 0 its output will be 1.
0 1 1 0 1 1 Q. 17. XNOR gate is represented by following graphic
1 0 0 1 0 1 symbol?
1 1 1 1 1 0 (A) © (B ) +

Ans. Option (A ) is correct.


a>
(c) < (D) ©
Ans. Option (D) is correct.
Explanation:
Explanation: XNOR gate is also known as Exclusive
A NOR gate. It is the complement of exclusive
B
OR and indicated by the © graphic symbol. Its
This is XNOR gate which is the complement algebraic expression is,
of the XOR gate. It is a hybrid gate. Simply, it is F = A © B = A'B' + AB
the combination of XOR gate and NOT gate. The
I COMPUTER HARDWARE 43

SUBJECTIVE TYPE QUESTIONS

<©> Short Answer Type


Questions-I (2 8 3 marks) Answering Tip
..
Q 1 Study the diagram given below and answer the w Logic gates and Logic circuits must be practiced
questions that follow: with almost every expression.

..
Q 4 From the logic circuit diagram given below, find
output 'F' and simplify it. Also, state the law
(i) Name the basic gate which is represented by the represented by the logic diagram. [ISC 2014]
diagram. [ISC, 2020] Q<
Ans. OR gate [ISC Marking Scheme, 2020]
(ii) What will be the value of X when A =1 and B = 0?
Ans. 1 [ISC Marking Scheme, 2020]
..
Q 2 Draw the logic circuit of a NAND gate using R
NOR gates only. [ISC, 2016]
Ans. ( P + Q ) ( P + R ) = P + Q.R Distributive Law
[ISC Marking Scheme, 2014]
Examiner's Comment
w Some candidates were not clear about the circuit i
and drew vague diagrams, but using NOR gates. ]
B w
Examiner's Comment
This part was well answered by most of the
candidates. Some candidates did not mention
Answering Tip the law, but wrote the expression correctly. Some
wrote only the intermediate expression.
w Logic gates and logic circuits must be practiced
with almost every expression, especially with
universal gates. Answering Tip
..
Q 3 Draw a logic circuit for (A + B ) (C + D) C
[ISC 2015]
- w Do practice for deriving an expression from a
logic circuit and also recognize the law used. Step
by step solving; of a circuit should be practiced.
Ans. Logic circuit for (A + B) (C + D) C -
A-
Detailed Answer:
B
From the logic diagram,
We have three input variables, i.e., Q, P, R. To find
the output F,
(i) We can see that Q and P input variables
formed one OR gate and P and R input
C variables formed another OR gate.
D- (ii) On the output of both OR gate, an AND
[ISC Marking Scheme, 2015] operation, is being performed.
To simplify this expression,
F = (Q + P)(P + R)
Examiner's Comment F = QP + QR + PP + PR
(by distributive law)
w Some candidates interchanged the gates i.e., OR
gate with AND gate and vice versa.
F = QP + QR + P + PR
(by idempotent law, i.e., PP = P)

These questions are for practice and their solutions are available at the end of the chapter
44 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
F = QP + QR + P (by absorption law) Simplify,
I
F = P + QR (by absorption law) X' = [A- (A + B) B(B + C')]'
Logic diagram represented distributive law. = [(AA + AB) (BB + BC')]'
Q. 5. Draw the truth table and logic circuit tor a 2 input (by distributive law)
XNOR gate. [ISC 2012] 0 = [(A + AB) (B + BC')]'
Q. 6. Name the logic gate tor the following circuit (by idempotent law)
diagram and write its truth table. [ISC 2011] = [AB] ' (by absorption law)
A B
= NAND gate
Since, NAND is a universal gate. Hence, the
(A + B)1 (A + B)" = A + B
complement of given expression is a universal gate.
Q. 9. Answer the following question related to the gate
given below: [ISC 2009]
Ans. In the given circuit diagram there are two NOR Input
gates ^ Output
First NOR gate B
A B
(i) What is the output of the above gate if input
A = 0, B = 1?
ii
( ) What are the values of the inputs if output
= 1?
Ans. (i) The output of the NOR gate is 0.
will produce output X = (A + B)' and this output is if inputs A = 0 and B = 1
being provided as input, to second NOR gate, i.e.,
(ii) A = 0, B = 0
Q. 10. State the dual for the following expression and
also draw the logic gate diagram for the dual
expression obtained using NOR gate only.
and second NOR gate being a single input NOR
gate will work as a NOT gate only. Hence, it will
P = AB + CD 0 [ISC 2009]
produce Y = X', i.e., Q. 11. Draw the logic gate diagram and truth table for
XOR gate. [ISC 2007]
= [{A + B}]' (by involution law)
\
=A+B x F = (x © y)
Hence, the given circuit diagram is just an OR
gate.
Q. 7. Draw the logic circuit of NOR using NAND gate Ans. Here, x and y are the inputs and F represents the
only. [ISC 2010] output of XOR. The truth table XOR is:
Ans.
x y F =x®y
X 0 0 0
ix' y')'r f = ((x’ y yy 0 1 1
1 0 1
y-
I I o
F = ((x '-yyr = (x '-y ') The algebraic expression is F = x © y = x'y + xy'
(by involution law) Q. 12. What is meant by a logic gate? State any one
= (x + y) ' application of a logic gate circuit. [ISC 2007]
Q. 8. Prove that the complement of A ( A + B ) B (B + C') Ans. Logic Gate: A logic gate is simply an electronic
is a universal gate. [ISC 2009] circuit, which operates no one or more input
Ans. Given expression, say signals to produce an output signal. Logic gates can
be constructed from diodes, transistor and resistor
-
X = A (A + B) B(B + C')
connected in such a way that circuit output is the
Its complement
result of a basic logic operations, performed on
-
X' = [A (A + B) B(B + C')]'
the input. Logic gates are used on bitwise Boolean

These questions are for practice and their solutions are available at the end of the chapter
I operations. The most popular application of logic
COMPUTER HARDWARE
Q. 15. Write the SOP expression corresponding to the
45

gate is switch. following truth table and draw its logic gate
Q. 13. Name the Universal Gates. [ISC 2007] diagram. 0
[ISC 2006]
Ans. Universal Gates: Combinations of NOR gate A B C F
and NAND gates may be arranged to create any
0 0 0 0
other possible combination of gates, making them
'universal gate'. 0 0 1 0
The NAND and NOR gates are said to be the 0 1 0 1
universal logic gates. These two gates can be used 0 1 1 1
to create all other logic gates.
1 0 0 0
NAND NOR 1 0 1 0
1 1 0 1
1 1 1 1
Q. 16. Using NOR gates only, draw AND, OR and NOT
x y z = (x-y) ' X y z = (x + y) '
gate. [ISC 2005]
o o I o o I Ans. (i) Construction of AND gate using NOR gate:

o I I o I o
I 0 1 1 0 0
1 1 0 1 1 0
Boolean expression Boolean expression
z = -
( x y) ' z = (x + y) '
(ii) Construction of OR gate using NOR gate:
. .
Q 14 Why is the NOR gate regarded as a universal
x
gate? Draw the logic gate symbol and make the (x + y)' x+ y =z
truth table for the two input NOR gates.
y*-
[ISC 2006]
Ans. NOR Gate is regarded as a universal gate because (iii) Construction of NOT gate using NOR gate
it can be used to construct many other gates like Here, we have only one input variable x and
AND, OR, NOT. it inverse using NOT gate produce x'. It passes
NOR gate means NOT OR, i.e., the NOR function through NOR, then the output will be:
is complement of OR function as shown:

F = (x + y)’

Answer Type
F = (x + y) '
<&\ Short
Questions- II (4 marks)
Q. 1. Draw the circuit of a two input XOR gate with the
help of NOR gates. [ISC 2020]
[Here, x and y are two inputs and F is output]
Ans. XOR gate using only NOR gates: Expression for
The truth table for 2-input NOR is:
XOR in POS: F = (A' + B') (A + B)
x y z = (x + y )'
o o I
o 1 0
1 0 0
1 1 0
[ISC Marking Scheme 2020]

These questions are for practice and their solutions are available at the end of the chapter
46 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
Q. 2. Derive a Boolean expression for the logic circuit
. I
given below and reduce the derived expression, Answering Tip
using the Boolean laws: [ISC 2015]
A- w Drawing of logic circuits using universal gates
must be learnt. Proving of universality of gates
B-HX must be learnt.
-X
c-»ri>o — Q. 4. Define universal gates. Give one example and
show how it works as an OR gate ?
Ans. 1. - -
(A' B' C')
| § [ISC, Specimen Question Paper 2016]
|
2. - -
(A' B' C')'
Q. 5. Derive a Boolean expression for the logic diagram
3. - - -
(A' B' C')' C given below and simplify it. [ISC 2014]
4. - - - - -
(A' B' C')' C + (A' B' C')'
-
(A + B + C) C + (A + B + C)
-
(A + B + C) (C + 1)
A+B+C [ISC Marking Scheme, 2015]

Examiner's Comment
w Most of the candidates answered this part correctly.
Some candidates gave incomplete answers. A few
candidates could not reduce the expression. Some
wrote the answer directly without mentioning the
intermediate points. Ans. The output will be:
(A + AB)(B + BC)(C + AB)
=> - -
A(1 + B) B(l + C) (C + AB)
Answering Tip --
A B (C + AB)
ABC + ABAB
ABC + AB
Do practice for deriving expression for any circuit
diagram and then reducing it. => AB(C + 1) = AB
[ISC Marking Scheme, 2014]

Q. 3. What are universal gates? Construct a logic


circuit using NAND gates only for the expression: Examiner's Comment
-
A (B + C) [ISC 2015]
Ans. Universal gates are derived gates which can w Most of the candidates answered this part well
perform the function of all basic gates. NAND except for a few who were not able to simplify the
gate and NOR gate are Universal gates. expression.

B*
(AB) . (AC) = AB + AC Answering Tip
w More practice should be done in deriving
expressions from a circuit diagram and simplifying
it. Laws must be implemented for minimizing
expressions.
[ISC Marking Scheme, 2015]

Q. 6. In the following truth table x and y are inputs and


Examiner's Comment B and D are outputs: [ISC 2013]
Input Output
w Some candidates used basic gates in drawing
x X B D
the logic circuit instead of NAND gates. The
0 0 0 0
concept of universal gates not clear to a number of
0 1 1 1
candidates.
1 0 0 1
1 1 0 0

These questions are for practice and their solutions are available at the end of the chapter
I Answer the following questions:
COMPUTER HARDWARE
Q. 9. Consider the following truth table where A and B
47

(i) Write the SOP expression for D. are two input and X is the output
(ii) Write the POS expression for B. A B X
(iii) Draw a logic diagram for the SOP expression 0 0 0
derived for D using only NAND gates. 0 1 1
Ans. (i) x'y + xy' 1 0 1
-
(ii) (x + y) (x' + y) (x' + y') - 1 1 0
(iii) (i) Name and draw the gate for the given truth
table. [ISC 2012]
X' (ii) Write the POS of X (A, B ).
Ans. (i ) XOR gate
x'y + xy1

y'
-
(ii) POS expression is (A + B) (A' + B')
Q. 10. Show with the help of a logic diagram how a
..
Q 7 Minimize the following expression using Boolean NAND gate is equivalent to an OR gate .
laws §
( > [ISC 2011]
--
Q (Q' + P) R (Q + R ) Q. 11. Draw the truth table representing a 2 input XNOR
Also draw the logic gate for the reduced gate and derive its SOP expression along with its
expression. [ISC 2012] logic gate diagram. [ISC 2010]
Ans.
.
Ans Given expression is,
F = Q (Q' + P) -R - (Q + R) Truth Table for XNOR gate

F = (Q- Q' + Q - P) - (R -Q + R - R) A B A0B


(using distributive law) 0 0 1
0 1 0
Next, F = (0 + Q-P) -(R-Q + R - R)
1 0 0
(using complement law)
1 1 1
Next, F = (Q-P) -(R -Q + R) SOP expression will be AB + AB
(using zero property idempotent law)
The logic diagram for SOP expression is:
Next, = (QP) -R (using absorption law)
F
Next, F = QP- R
F = Q- P- R.
Logic gate for F = Q - P-R is, Q. 12. Draw the logic gate diagram for the following
Q
p*-—— F = Q.PR
three input function F(x, y, z ) using NOR gates
only.
R* F(x, y, z) = S(0, 1, 3, 4, 7) [ISC 2008]
Q. 8. Represent the Boolean expression X + YZ' with Ans. Given expression,
the help of NOR gates only. [ISC 2012] F(x, y, z) = S(0, 1, 3, 4, 7)
Ans. Expression = +
X YZ'
For NOR implementation, we need to convert it to
= (X + Y) (X + Z') - POS form
(x + y)(x + z) F(x, y, z) = S(0, 1, 3, 4, 7)
= P(2, 5, 6) = M2-M5-M6
M2(010) = X + y' + Z
z
M5(101) = x ' + y + z'
M6(110) = x ' + y' + z
F = (x + y' + z )( x' + y + z' )( x' + y' + z)
These questions are for practice and their solutions are available at the end of the chapter
48 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
From the above expression, the logic diagram is: Produces 1 (high) Produces 1 (high) as
I
x z

o CH
as output when the output when the inputs
input combination combination has odd
has even number of number of Is.
Os
Logic Diagram of a 3 input XNOR gate:
F

Cl
Truth table for 3 input XNOR gate:
Q. 13. Draw the logic gate diagram for the Boolean A B C X
function. [ISC 2006] 0 0 0 0
= (A' + B) (B' + C)
F(A, B, C) 0 0 1 1
Making use of NOR gates only. 0 1 0 1
F(A, B, C) = (A' + B) (B' + C) 0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
fA' + B)(B' + C)
Expression: X = A © B 0 C
[ISC Marking Scheme, 2016]

Examiner's Comment
Long Answer Type w Some candidates were confused between XNOR
-
Question I (5 marks each) and XOR gates and interchanged the answers.
Some were confused with the 3 input XNOR truth
Q. 1. Differentiate between XNOR and XOR gates. table.
Draw the truth table and logic diagrams of 3
input XNOR gates. [ISC 2014]
Ans.The differences between XNOR and XOR gate are Answering Tip
as follows:
XNOR XOR w More practice should be done for understanding
the various gates (AND, OR, NOT, XOR, XNOR,
Logically equivalent Logically equivalent to NAND and NoR). Students should be told that in
to an inverted an exclusive OR. i.e., if odd number of inputs, XOR, and XNOR outputs
XOR, i.e., XOR gate both inputs are 1 then are same and in even number of inputs XOR is
followed by a NOT output is 0 (reverse of the complement of XNOR.
gate. inclusive OR)

I Designing Simple Logic Circuits


Topic- 2 Concepts covered: Designing circuits for given Boolean expression

m
>
Revision Notes
The K-map is a systematic way of simplifying Boolean expressions. With the help of the K-map method, we can
find the simplest POS and SOP expression, which is known as the minimum expression.
• The K-map provides a cookbook for simplification.
• The K-map method is used for expressions containing 2, 3, 4, and 5 variables.
I • There are the following steps used to solve the expressions using K-map:
COMPUTER HARDWARE 49

1. First, we find the K-map as per the number of variables as 2, 3, 4, and 5 variables.
2. Find the maxterm and minterm in the given expression.
3. Fill cells of K-map for SOP with 1 respective to the minterms.
4. Fill cells of the block for POS with 0 respective to the maxterm.
5. Next, we create rectangular groups that contain total terms in the power of two like 2, 4, 8, ... and try to
cover as many elements as we can in one group.
6. With the help of these groups, we find the product terms and sum them up for the SOP form.

OBJECTIVE TYPE (1 mark each)


Q. 1. Identity the correct logic diagram for the
simplified expression.
F = A . (A' + B) . C. (A + C)
A o-
(A ) B
— A'BC
C
A AB'C
(B) B -*o-
C
A ABC
(C) B
C
A ABC'
(D) B
C -*o-
Ans. Option (C) is correct. (D) All of these
Explanation: Ans. Option (D) is correct.
F = A . (A’ + B) . C . (A + C) Q. 4. Given F(P, Q, R, S) 2(0, 2, 5, 7, 8, 10, 11, 13, 14, 15)
=
F = (A . A' + A . B) . (CA + C . C) the diagram using NAND gates only will be:
F = AB (C . A + C)
F = ABC
So, is logic diagram is
A F = ABC
B
C
Q. 2. The equivalent expression for the below given
logical circuit is:
a-
b- Y

C*
(A) Y = ab + be + ca
(B ) Y = ab + be + ca
— s (C) Both (A) and (B)
(D) None of these
Ans. Option (A ) is correct.
(C) Y = (a + b)(b + c)(c + a) Q. 5.
(D) None of these. X

Ans. Option (A ) is correct.


-d >
Q. 3. F = AB + AB + AB. Using only NOR gates the
circuit will be:
(A )
A
B“
'

T> The given circuit diagram represents the function.


(A) F(x, y, z) = 2(0, 3, 4, 7)
(B) F(x, y, z) = n( l , 2, 5, 6)
£> (C) F(x, y, z) = 7t(0, 3, 4, 7)
(D) Both (A) and (B)
Ans. Option (D) is correct.
50
..
Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q 6 Consider the circuit diagram given below: The output at X in the above diagram is:
I
A- (A) AB (B) A'B'
(C) A'C (D) AC

B
.
Ans Option (A) is correct
..
Q 9
A* X
The output Y is: Z
B
(A) A'B
(C) A
(B) AB
(D) B fez
.
Ans Option (A) is correct The output at Y in the above diagram is:
..
Q 7 (A) BC (B ) AC
A- (C) AB (D) None of these.
.
Ans Option (B) is correct
B . .
Q 10
A* X
The output Z in the given figure is: B Z
(A) A'B (B) AB
(C) AB' (D) A'B’
.
Ans Option (C) is correct The output at Z is:
(A) (A + B)(B + C)(C + A)
..
Q 8
(B) A'B' + B'C + CA'
(C) AB + BC + CA
(D) All of these.
.
Ans Option (C) is correct

SUBJECTIVE TYPE QUESTIONS


Ans .
Short Answer Type
<©> Questions I - (2 marks)
B’
D
..
Q 1 The Boolean function
F(A, B, C, D) = E(0,1, 2, 3, 4, 5, 8, 9,10, 11, 12,13, 14).
is represented as B' + C' + AD' .
Draw the logic gate diagram for the reduced
A'
D’
B
C
x>
D
.
expression Assume that the variables and their
complements are available as inputs .
Answer Type
Ans.
B'-
<©> Short
Questions-II (3 marks)
..
Q 1 From the logic circuit diagram given below, name
c - > .
the outputs (1), (2) and (3) Finally derive the
A' — > Boolean expression and simplify it to show that it
.
represents a logic gate Name and draw the logic
D!—> [ISC 2013]
[ISC Marking Scheme, 2020]
..
Q 2 The Boolean function:
F(A, B, C, D) = 7t( 3, 4, 6, 9, 11, 12, 13, 14, 15 )
is represented as (B' + D) (A' + D') (B + C' + D') .
Draw the logic gate diagram for the reduced
expression. Assume that the variables and their
complements are available as inputs.
I
Ans. (i) X + Y ' (ii) X -Z (iii) XZ (X + Y ') -
COMPUTER HARDWARE
Q. 4. Reduce the following expression using the laws
51

Final expression = XZ(X + Y ') + Z ' of Boolean using the laws of Boolean algebra.
=> XZ + XYZ + Z ' (by distributive law) Draw the logic gate diagram for the simplified
=> XZ (1 Y
+ + ') Z (by distributive law) expression. [ISC 2008] 0
=> XZ + Z '
(by complement law) -
F = A (A + B ) C (A + C)
'

=> + X Z '
Q. 5. How is an XOR gate different from an OR gate?
It represents the OR gate, X + Z ' Draw a truth table representing a three input XOR
operation. Derive its SOP expression and draw
the logic gate diagram for the SOP expression.
[ISC 2008]
Ans. OR gate produces output 1 for any input
Q. 2. Simplify the following expression and also draw combination having one or more l's, but XOR
the circuit/gate for the reduced expression. [Show gate produces output 1 for only those input
the stepwise working along with laws] [ISC 2010] combinations that have odd number of l's. Symbol
© is used to denote XOR gate.
-
F = X- (Y + Z (X - Y + X -Z) ')
Ans. Given expression, x y z F ^ x ©,»«© Zj Minterms
- - -
F = X (Y + Z (X Y + X Z) ') - 0 0 0 0 x ' y 'z '
- -
F = X (Y + Z[(X Y) + (X Z)] ') - 0 0 1 1 x 'y 'z
-
F = X (Y + Z[(X ' + Y ') (X ' + Z')]') - 0 1 0 1 x 'yz '
[On applying Demorgan's theorem,
i.e., (XY) ' = X ' + Y '] 0 1 1 0 x 'yz
Next, F = XY + XZ[(X ' + Y ') (X ' + Z')]) - 1 0 0 1 xy 'z '
(by distributive law)
F = XY + XZ(X ' X ' + X 'Z ' + X 'Y '
1 0 1 0 xy 'z
+ Y 'Z ')) 1 1 0 0 xyz
(using distributive law) 1 1 1 1 xyz
= XY + XZ(X ' + X 'Z ' + X 'Y ' + Y 'Z ')) F = x y z + x 'yz ' + xy 'z ' + xyz
' '
(using idempotent law)
= XY + XZ(X ' + X 'Y ' + Y 'Z ')) Logic circuit diagram for given SOP expression (F)
( using absorption law) is shown below:
= XY + XZ(X ' + Y 'Z ')) x-
( using absorption law)
= XY + X 'XZ
+ XZY 'Z ' y-
(using distributive law) z-
= XY (using complement law)
Logic circuit for reduced expression is: x
y
x <
z
Y
- tx>y
*
Q. 3. From the logic circuit diagram given below, name
the parts (1), (2), ( 3) and finally derive the Boolean
expression and simplify it: [ISC 2009] z-
x
A- y
01 z
B

C-
Long Answer Type
F(A, B, C) Questions -I (5 marks each)
Q. 1. A school intends to select candidates for an Inter-
School Essay Competition as per the criteria given
Ans. (1) OR gate A + B below: [ISC 2017]
(2) AND gate C(A + B) The student has participated in an earlier
(3) NOT gate [C(A + B)]' competition and is very creative.
Simplify = A + B + [C(A + B)] ' OR
(DeMorgan’s law) The student is very creative and has excellent
= A + B + C ' + A 'B ' general awareness, but has not participated in any
= A + A 'B ' + B + C ' competition earlier.
These questions are for practice and their solutions are available at the end of the chapter
52 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
OR The passenger is a lady and is not accompanied
I
The student has excellent general awareness and by an adult
has won prize in an inter-house competition. OR
The inputs are: The passenger is not below 15 years, but is
travelling for the first time.
INPUTS The inputs are:
A participated in a competition earlier
INPUTS
B is very creative
A The passenger is below 15 years age.
C won prize in an inter house -
competition C The passenger is accompanied by an
D has excellent general awareness adult.
(In all the above cases 1 indicates yes and 0 L The passenger is a lady.
indicates no). F The passenger is travelling for the
Output: X [1 indicates yes, 0 indicates no for all first time.
cases]
(In all the above cases 1 indicates yes and 0
Draw the truth table for the inputs and outputs indicates no).
given above and write the POS expression for Output: W - Denotes the passenger is allotted a
X( A, B, C, D). window seat (1 indicates yes and 0 indicates no)
Ans.
Draw the truth table for the inputs and outputs
A B C D X given above and write the SOP expression for
0 0 0 0 0 W(A, C, L, F ). [ISC 2016]
0 0 0 1 0 Ans .
0 0 1 0 0 A C L F W
0 0 1 1 1 (OUTPUT)
0 1 0 0 0 0 0 0 0 0
0 1 0 1 0 0 0 0 1 1
0 1 1 0 1 0 0 1 0 1
0 1 1 1 1 0 0 1 1 1
1 0 0 0 0 0 1 0 0 0
1 0 0 1 0
0 1 0 1 1
1 0 1 0 0
0 1 1 0 0
1 0 1 1 1
0 1 1 1 1
1 1 0 0 1
1 0 0 0 0
1 1 0 1 1
1 0 0 1 0
1 1 1 0 1
1 1 1 1 1 1 0 1 0 1
1 0 1 1 1
X = (A + B + C + D) (A + B + C + D ') (A + B
+ C + D ) (A + B + C + D) (A + B + C 1 1 0 0 1
+ D ') (A ' + B + C + D) (A' + B + C + D ')
1 1 0 1 1
(A' + B + C ' + D)
X = (A + B + C + D ) (A + B + C + D') (A + B 1 1 1 0 1
+ C ' + D) (A + B ' + C + D) (A + B ' + C 1 1 1 1 1
+ D ') (A ' + B + C + D) (A' + B + C + D ')
(A' + B + C ' + D). SOP Expression:
Q. 2. A passenger is allotted a window seat in an W(A, C, L, F) = 2(1, 2, 3, 5, 7, 10, 11, 12, 13, 14, 15)
aircraft, if he/she satisfies the criteria given below: W = A 'C 'I/ F + A 'C 'LF ' + A 'CL 'F + A 'CLF
The passenger is below 15 years and is + AC 'LF ' + AC 'LF + ACL 'F ' + ACL 'F
accompanied by an adult. + ACLF ' + ACLF
OR [ISC Marking Scheme 2016]
COMPUTER HARDWARE 53

Examiner's Comment Examiner's Comments


w Some candidates were not clear about the circuit w Several candidates made errors in place value
and drew vague diagrams, but using NOR gates. and putting variables in K-Map. In some cases,
the groups were reduced by laws. A number of
-
candidates drew the K Map incorrectly. Many
Answering Tip candidates included the redundant group in the
final expression.
w Students must practice on Fundamental gates w Some candidates drew the logic circuit using
(AND, OR, NOT) and Universal gates (NAND,
universal gates while some others drew vague
NOR) With their symbols and truth tables.
diagrams.
Q. 3. Given the Boolean function
F( A, B, C, D) = S(0, 1, 2, 3, 4, 5, 6, 7, 10, 13, 14, 15) Answering Tips
[ISC 2014]
(i) Reduce the above expression by using w Emphasize on arranging the variables in
4-variable Karnaugh's map, showing the proper order and the importance of cell values
various groups (i.e., octet, quads and pairs). corresponding with the variables. Explain
(ii) Draw the logic gate diagram of the reduced clearly how the groups are framed and reduced.
expression. Assume that the variables and Redundant groups are not to be included in the
their complements are available as inputs. final reduced expression.

Ans. (i) For F(A, B, C, D) = 2(0,1, 2, 3, 5, 6, 7, 10, 13,14, 15) w More practice should be given in drawing logic
circuits using basic gates and also with universal
CD gates.
AB CD CD CD CD

AB :i X i X i;
0
' '
3 2 Q. 4. Given the Boolean function: P( A, B, C, D) = FI(0,
;1 1 1 1, 2, 3, 5, 6, 7, 10, 13, 14, 15 ) [ISC 2014]
AB
4 5 7 6 (i) Reduce the above expression by using
AB ;I I I 4-variable Karnaugh's map, showing the
12 13 15 14 various groups (i.e., octet, quads and pairs).
AB 1 (ii) Draw the logic gate diagram of the reduced
8 9 11 10 expression. Assume that the variables and
,
1st quad (mg + m + m 2 + m3) = AB their complements are available as inputs.
Ilnd quad (m2 + mg + m10 + m14) = CD Ans. (i) For P(A, B, C, D) = 11(0, 1, 2, 3, 5, 6, 7, 10, 13,
Illrd quad (m6 + m7 + m13 + m15) = BD 14, 15)
So, final expression is, CD
F(A, B, C, D) = AB + CD + BD AB C+D C+D C+D C+ D
(ii) Logic gate diagram for expression
A+B :.o. .0 .Q .: O '

=
F (A, B, C, D) = AB + CD + BD is 0 1 3 2

J Th A+ B

A+ B
4
0

0
5
0:

0:

! 7
0

0
6

F=AB+ CD+ BD
12 - - -13 : 15 14
A+ B 1 0
8 9 11 10

1st quad (Mg- Mj-Mj-Mj) = (A + B)


Ilnd quad (M2 M6 M10 M14) = (C + D)
The output from three AND gates will be Illrd quad (M5 M7 M13 M15) = (B + D)
AB,CD,BD and the output from the OR gate So, final expression is,
represents the sum of all AND gate, i.e.,
AB + CD + BD. [ISC Marking Scheme 2014] P(A, B, C, D) = (A + B)(C+ D)(B + D)
54 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII

(ii) The logic diagram for the final expression is


RS
. I
PQ R +S R +S R +S R +S
A '

B P+ Q : 0. '
6; o:
0 1 • 3 2
P+ Q 0 () •
A+ B 4 5 7 6
cjy C+D P = (A + B)(C + D) + (B + D)
P+ Q
12 13
0
15
0
14
B+D
P+ Q 0 0 0 0
B 8 9 11 10

D-
Ist Quad (M0 MJ M8 M9) = (Q + R)
[ISC Marking Scheme 2014]
Ilnd Quad = (P +S)
Illrd Quad (M15 M14 MnM10) = (P + R)
Examiner's Comments So, the reduced expression is,
F(P, Q, R, S) = (Q + R) (P + S) (P + R)
w A number of candidates were not able to draw
(ii) Logic circuit diagram for F(P Q, R, S) is shown
the K-Map for the POS expression correctly. For
below:
many candidates the "Map rolling" concept was
not very clear. Some converted the canonical form
Q - Q+R
to cardinal form and then reduced it. R-

w Some candidates drew the logic circuit using

J
^ ^ J
universal gates while some others drew vague p P +S = (Q + R)(P +S)(P + R)
)
diagrams.

V' Answering Tip


w Make students reduce POS and SOP expressions Q. 7. Given the Boolean function F(A, B, C, D) = 2(4, 6,
-
using K Map simultaneously. Students should be 7, 10, 11, 12, 14, 15) [ISC 2012]
told not to include the redundant group in the (i) Reduce the above expression by using
final expression. 4-variable K-map, showing the various
groups (i.e., octet, quads and pairs).
(ii) Draw the logic gate diagram of the reduced
Q. 5. Given the Boolean functions F(A, B, C, D) = 2(0,
expression. Assume that the variables and
2, 4, 5, 8, 9, 10, 12, 13) [ISC 2013] 0 their complements are available as inputs.
(i) Reduce the above expression by using Ans. (i) Given expression,
4-variable K-map, showing the various F(A, B, C, D) = 2(4, 6, 7, 10, 11, 12, 14, 15)
groups (i.e., octet, quads and pairs). 1st quad (m7 + m6 + m15 + m14) = BC
(ii) Draw the logic gate diagram of the reduced Ilnd quad (m15 + m14 + mn + m10) = AC
expression. Assume that the variables and Illrd quad (m6 + m14 + m4 + m12) = BD
their complements are available as inputs. Hence, reduced expression is,
Q.6. Given the Boolean function F(P Q, R, S) = 11(0, 1, F(A, B, C, D) = BC + AC + BD
3, 5, 7, 8, 9, 10, 11, 14, 15) [ISC 2013] CD
AB CD CD CD CD
(i) Reduce the above expression by using
4-variable K-map, showing the various group AB
(i.e., octet, quads and pairs ). 0 1 3 2

(ii) Draw the logic gate diagram of the reduced AB 1 1 i!


expression. Assume that the variable and 4 5 7 : : 6
their complements are available as inputs.
Ans. (i) The given expression,
AB i
12 13
i.
15
iri 14
F(P, Q, R, S) = P(0, 1, 3, 5, 7, 8, 9, 10, 11, 14, 15) AB 1 1 1
8 9 11 10

These questions are for practice and their solutions are available at the end of the chapter
I(ii) The logic gate diagram is shown below:
COMPUTER HARDWARE
diagram of the reduced expression using NOR
55

F(A, B, C, D) = BC + BD + AC gate only. [ISC 2011]


A ' AC Ans. The given expression is
C F(P, Q, R, S) = P(2, 3, 6, 7, 9, 11, 12, 13, 14, 15)
NRS
B BD PQN. R +S R+ S R +S R +S
D —+ F =; P+ Q
C

P+ Q
B
Q. 8. Given the Boolean function F(P Q, R, S) = P( 0, 5, P+ Q
7, 8, 10, 12, 13, 14, 15 ) [ISC 2002]
(i) Reduce the above expression by using P+ Q
4-variable K-map, showing the various
groups (i.e., octet, quads and pairs ). - - -
1st Quad (M2 M3 M6 M7) = (R + P)
(ii) Draw the logic gate diagram of the reduced - - - „
End Quad (Ml3 Mls M9 M ) = (P +S)
expression. Assume that the variables and - - -
HIrd Quad (M12 M13 M15 M14) = (P + Q)
their complements are available as inputs. Reduced expression is,
Ans. (i) Given function is, -
F(P Q, R, S) = (P + R) (P + Q) (P + S) -
F(P Q, R, S) = P(0, 5, 7, 8, 10, 12, 13, 14, 15) The logic diagram for above expression is:
RS
PQ R +S , R +S R +S R +S P+R

P+ Q 0
0 1 3 2
F = (P + R).(P + Q).(P + S)
P+ Q 0 0
4 5 7 6
P+ Q 0 0 0 0
12 13 15 14
P+ Q JJ. 8
0
9 11
0
10
Q. 10. Given the functions:
-
1st Pair (M0 M8) = R + S + Q
- - -
1st Quad (M5 M7 M13 M15) = S + Q
F( A, B, C, D ) = ABCD + ABCD + ABCD _
+ ABCD + ABCD + ABCD
- - -
Ilnd Quad (M8 M10 M12 M14) = S + P
Reduce the above expression by using 4-variable
Reduced expression is,
Karnaugh's map. Draw the logic gate diagram of
- -
F(A, B, C, D) = (S + Q) (S + P) (R + S + Q) the reduced expression using NAND gate only.
(ii) Logic diagram of given expression is: [ISC 2011]
Ans. Given expression,
Q--
S-
^TNQ +I F(A, B, C, D) = ABCD + ABCD + ABCD _ _
+ ABCD + ABCD + ABCD
CD
F = (Q + S)(P +S)(Q + R +S) AB ; CD CD ; CD CD

AB 1 i;
0 1 3 2
AB li :1
4 5 7 6
AB
Q. 9. Given expression is F(R Q, R, S) = P(2, 3, 6, 7, 9, 12 13 15 14
11, 12, 13, 14, 15). AB 1 1 1 1
Reduce the above expression by using four 8 9 11 10
variable Karnaugh's map. Draw the logic gate
56 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
1st Pair (m4 + m6) = ABD Q. 12. Given:
. I
1st Quad (mo + irij + m8 + m9) = BC F( A, B, C, D) = ( A + B + C + D) (A + B + C + D )
Final reduced expression is, (A + B + C + D ') (A + B + C' + D)
F(A, B, C, D) = ABD + BC (A + B + C + D ' ) (A + B + C + D )
(A + B + C + D) ( A + B + C + D)
Logic gate diagram for the reduced expression
using NAND gate only is as follows: 0 [ISC 2010]
B B (i) Reduce the above expression by using
4-variable K-Map, showing the various
groups (i.e., octet, quads and pairs).
F = BC + ABD (ii) Draw the logic gate diagram of the reduced
expression using NOR gate only.
Q. 13. F(I» Q, R, S) = P'Q 'RS ' + PQRS ' + PQ 'R 'S

. .
B

°—o —
Q 11 Given F(P, Q, R, S) = 2(0, 2, 5, 7, 8, 10, 11, 13, 14,
+ PQ 'RS ' + PQ 'RS + PQR 'S
+ PQRS ' + PQRS
Use Karnaugh's map to reduce the given function
15) [ISC 2010] F using the SOP form. Draw a logic gate diagram
(i) Reduce the above expression by using 4 for the reduced SOP form. You may use gate with

..
-
variable K map, showing the various groups
.
more than two inputs. Assume that the variables
and their complements are available as inputs.
(i e , octet, quads and pairs)
[ISC 2009]
(ii) Draw the logic gate diagram of the reduced
expression using NAND gate only . Ans. Given expression,
.
Ans (i) Given expression is, F(P, Q, R, S) = P Q RS ' + P QRS ' + PQ 'R 'S
+ PQ 'RS + PQR 'S + PQRS'
F(P Q, R, S) = 2(0, 2, 5, 7, 8, 10, 11, 13, 14, 15)
+ PQRS + PQ 'RS '
sRS
R’S’ R'S RS RS' To draw the K-map we need four input variables,
PQ % as shown:
P'Q' 1 : 1 1.1
0 1 3
''
2 sRS R'S1 R'S RS RS'
PQ\
P'Q 1 1 1 P'Q' 1
4 5 7 6 0 1 3 2
PQ 1 1 1 1
P'Q
12 13 15 14 4 5 7 6
1
PQ' 1 :
8 9
1 . 11. To PQ
12 13
1
15
1
14
11
1 1
1st Quad (m5 + m7 + m13 + m15) = QS PQ’ .1.
8 9 11 10
Ilnd Quad (m15 + m14 + mn + m10) = PR
Illrd Quad (mg + m2 + m8 + m10) = Q 'S ' 1st Quad (m13 + m15 + m9 + mn ) = SP
Reduced expression, F = QS + PR + Q 'S ' Ilnd Quad (m2 + m6 + m14 + m10) = RS '
(ii) The logic gate diagram for the reduced The reduced SOP expression, F = SP + RS '
expression using NAND gate only is given From the given expression, the logic gate will be
below: formed as:
P P R SS’

F = PR + QS + QS

S- Q^-T
These questions are for practice and their solutions are available at the end of the chapter
I
Q. 14. F( A, B, C, D) = P(0, 1, 2, 3, 5, 7, 9, 13)
COMPUTER HARDWARE
Ans. Given, F(A, B, C, D) = 2(0, 2, 3, 4, 6, 7, 9, 13)
57

Use Karnaugh's map to reduce the given function CD


AB CD CD CD CD
F using the POS form. Draw a logic gate diagram
for the reduced POS form. You may use gate with AB 1 1 1
more than two inputs. Assume that the variables 0 1 3 2
and their complements are available as inputs. AB 1 1 1
[ISC 2009] 4 5 7
' "''6'
Ans. Given expression , l l
AB
F(A, B, C, D) = P(0, 1, 2, 3, 5, 7, 9, 13) 12 13 15 14

AIK C+ D C + D' C + D' C' + D AB


8
. 1
9
1
11 10
0 ;0 0[ 0;
A+B
0 1 3 2 „
1st Quad (m + m2 + m4 + m6) = AD
.0.1. 0 II nd Quad (m2 + m3 + m6 + m7) = AC
A + B'
4 5 7 6 1st Pair (m9 + m13) = ACD
A’ + B' 0 So, the final expression will be,
12 13 15 14 F(A, B, C, D) = AC + AD + ACD
A’ + B 0 Logic diagram representation:
8 9 11 10 A- AC
Now to construct the K-map, we take four variable C-
inputs and put maxterms from M0 to M15, as
shown: F = AC + AD + ACD
-
1st Quad (M0 MrM3 M2) = A + B - D-
- - -
Ilnd Quad (Ml M3 M5 M7) = A + D ' A-
^ - -
Illrd Quad (M Mg M Mg) = C + D ' iCD
^ C-
Thus, the final reduced POS expression is,
D-
F = (A + B)(C + D ')(A + D ')
Q. 17. Given X(A, B, C, D) = 11(2, 3, 4, 5, 12, 14)
The logic diagram for above expression is:
A B C DD’ Use Karnaugh's map to reduce this function X
using the given POS form. Draw a logic gate
diagram for the reduced POS form. You may use
gates with more than two inputs.
Q. 18. Given the Boolean function
£+ D' F(A, B, C, D ) = 2(1, 6, 7, 8, 9, 10, 14, 15)
Use Karnaugh's map to reduce the function F,
F(A+ B)(C+ D)(A + D) using the given SOP form. Draw a logic gate
+ D' diagram for the reduced SOP form. You may use
gates with more than two inputs. Assume that the
variables and their complements are available as
Q. 15. Given X( A, B, C, D) = P(0, 2, 6, 8, 10, 14) inputs.
Use Karnaugh's map to reduce the given function Ans. Given,
X using the POS form. Draw a logic gate diagram F(A, B, C, D) = 2(1, 6, 7, 8, 9, 10, 14, 15)
for the reduced POS form. You may use gates with CD
AB \ CD :CD : CD CD
more than two inputs. Assume that the variables
and their complements are available as inputs. ( | ff AB
0
: 1:
1 3 2
Q. 16. Given the Boolean function
AB 1 1
F( A, B, C, D) = 2(0, 2, 3, 4, 6, 7, 9, 13) 4 5 7 6
Use Karnaugh's map to reduce the function F,
AB 1 1
using the SOP form. Draw a logic diagram for the 12 13 15 14
reduced SOP form. You may use gates with more
than two inputs. Assume that the variables and AB . 1: 1 1 :i
'

their complements are available as inputs. 8 9 ii 10

These questions are for practice and their solutions are available at the end of the chapter
58 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
Here, A, B, C, D are the input variables and X is the
.
Q. 20. Given the Boolean function F(A, B, C, D) = 2(0, 1,
I
-
output variable, m0 m15 represents the minterms of 2, 4, 5, 7, 11, 13, 15). [ISC 2006]
the K map. - Use Karnaugh's map to reduce this function
1st Quad (m7 + m6 + m15 + m14) = BC F, using the given SOP form. Draw logic gate
1st Pair (nij + m9) = BCD diagram for the reduced SOP form. You may use
gates with more than two inputs. Assume that
Ilnd Pair (m8 + m10) = ABD
variables and their complements are available as
So, the final expression will be inputs.
F(A, B, C, D) = BCD + ABD + BC Ans. The given expression is,
Logic diagram for final expression is: F(A, B, C, D) = 2(0, 1, 2, 4, 5, 7, 11, 13, 15)
B -
^
BC .CD C’D' C'D CD CD'
C AB
A:B: 1 1
~ 0 1 3 2
B

^
BCD
C ) X = BCD+ ABD+ BC A 'B 1 1 1
D- 4 5 7 6
AB 1 1
A 12 13 15 14
B 1
D ABD AB' 1
8 9 11 10
Q. 19. Given X( A, B, C, D) = P(0, 2, 3, 4, 5, 11, 12, 13) 1st Quad (mo + nij + m4 + m5) = A C ' "

Use Karnaugh's map to reduce this function X Ilnd Quad (m5 + m7 + m13 + m15) = BD
using the given POS form. Draw a logic gate 1st Pair (m0 + m2) = A 'B 'D '
diagram for the reduced POS form. You may use Ilnd Pair (mn + m15) = ACD
gates with more than two inputs. Assume that the So, the final SOP expression will be
variables and their complements are available as
F(A, B, C, D) = A 'C ' + BD + A 'B 'D ' + ACD
inputs. [ISC 2006]
.
Ans Given X(A B C D) = P(0 2 3 4 5 11 12, 13)
, , , , , , , , , , Logical diagram for expression:

^ CD
-
K map Representation
-
C+D
_
,
C+ D C +D C+D
_ . A1 -
AB

A+ B 0 0 :0 D , ,
F(A,B,C,D) = A C + A'B 'D'
0 1 3 2 +BD + ACD
B
A+B 0 0 D
4 5 7 6
A+B 0 0. c
12 13 15 14
' '

A+B 0
8 9 11 10 Very Long Answer Type
1st Quad (M4 M5 M12 M13) = (B + C)
Questions I -
(10 marks each)
1st Pair (MO-M2) = (A + B + D) Q.l. (a) Given the Boolean function F(A, B, C, D) =
Ilnd Pair (M3 Mn ) = (B + C + D) 2(2, 3, 4, 5, 6, 7, 8, 10, 11). [ISC 2017]
Final expression, (i) Reduce the above expression by using
X(A, B, C, D) = (B + C) (A + B + D)-(B + C + D) 4-variable Karnaugh map, showing the
various groups (i.e., octal, quads and pairs).
Logical diagram for expression is:
(ii) Draw the logic gate diagram for the
B
C t> B+C

X(A,B,C,D)
reduced expression. Assume that the
variables and their complements are
available as inputs.
D
+B+ D , = (B + C).(A + B + D).(B + C + D) (b) Given the Boolean function:
A '
F(P, Q, R, S) = 7i(0, 1, 2, 4, 5, 6, 8, 10)
(i) Reduce the above expression by using
B B + C+ D 4-variable Karnaugh map, showing the
C various groups (i.e., octal, quads and pairs).
D
I (ii) Draw the logic gate diagram for the
COMPUTER HARDWARE
Q. 2. (a) Given the Boolean function F(A, B, C, D)
59
=
reduced expression. Assume that the 2(1, 3, 5, 7, 8, 9, 10, 11, 14, 15).
variables and their complements are (i) Reduce the above expression by using
available as inputs. 4-variable Karnaugh map, showing the
Ans. various groups (i.e., octal, quads and
(a) (i ) pairs).
CD' CD CD CD'
(ii) Draw the logic gate diagram for the
A'B' 1 1
reduced expression. Assume that the
0 1 3 2
variables and their complements are
A'B [I
4
i
5
i
7
n6 available as inputs.
(b) Given the Boolean function:
AB
12 13 15 14 F( A, B, C, D ) = p(4, 6, 7, 10, 11, 12, 14, 15)
AB' 1 d (i ) Reduce the above expression by using
8 9 11 10 4-variable Karnaugh map, showing the
various groups (i .e., octal, quads and
2 quads — A B, B C
' '

pairs ) .
1 pair — AB ' D '
(ii ) Draw the logic gate diagram for the
F = A 'B + B 'C + AB 'D ' reduced expression. Assume that the
<fl> A' variables and their complements are
AND,
B available as inputs. [ISC 2016]
Ans .
B' F (a ) (i) F(A, B, C, D) = 2(1, 3, 5, 7, 8, 9, 10, 11, 14,15)
AND , OR
C
CD' CD CD CD'
A
AND, 0 1 3 2
D' A 'B' 0 1
(b) (i)
A'B 4 5 7
R +S R + S' R' + S' R' + S 0 1

0 (0 12 13 15
P+Q AB 0 0
0 1 3 2
0 0 0 8 9 11
P + Q’. AB' 1 1
4 5 7 6
P’ + Q 1
There are three quads:
12 13 15 14
Quad 1 (mj + m3 + m5 + m7) = A 'D
P' + Q/ rrx Quad 2 (m8 + m9 + m10 + mn ) = AB '
8 9 11
\ Quad 3 (m10 + mn + m14 + m15) = AC

3 Quads Hence, F(A, B, C, D) = A 'D + AB ' + AC


F = ( P + R).( Q + S).( P + S)

3>
(ii) P
R

Q
s T3> B'

A -
C -
d3>
60 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII

(b) (i) F(A, B, C, D) = 7t (4, 6, 7, 10, 11, 12, 14, 15)


. I
Answering Tips
C+D C + D' C + D' C+D
w Students should have sufficient knowledge about
A+B
0
1
1
1
3
1
2
1
- -
Sum of products (SOP) and Product of Sum - -
(POS) form. Student should solve the SOP and
A + B’ 4 5 7 A -
POS expressions using K Map method.
0 1 0 0
w Students should practice on designing the
12 13 15 14 logic circuits with the help of logic gates for all
A' + B'
0 1 0 11 expressions.
8 9 11 10
A' + B w Students must learn to derive minterms and
1 1 0 0
maxterms by using truth table and also learn how
There are three quads: to use them in the expressions.
Quad 1 (M4M6M12M14) =B +D '

Quad 2 (M6M7M14M15) = B ' + C ' Q. 3. (a) Given F(A, B, C, D) = 2(0, 2, 3, 6, 8, 10, 11, 14, 15)
Quad 3 (M10MnM14M15) = A ' + C' (i) Reduce the above expression by using
Hence, F(A, B, C, D) = (B ' + D) (B ' + C ') - (A ' 4-variable Karnaugh map, showing the
various groups (i.e., octet, quads and
pairs).
(ii) Draw the logic gate diagram for the
reduced expression. Assume that the
variables and their complements are
available as inputs.
(b) Given F(P, Q, R, S) = TI(5, 7, 8, 10, 12, 14, 15)
(i) Reduce the above expression by using
4-variable Karnaugh map, showing the
various groups (i.e., octet, quads and
pairs).
[ISC Marking Scheme 2016] (ii) Draw the logic gate diagram for the
reduced expression. Assume that the
variables and their complements are
Examiner's Comments available as inputs.
Ans. (a) Given, F(A, B, C, D) = 2(0, 2, 3, 6, 8, 10, 11, 14,15)
w (i) Most candidates fared well in this part. Some
candidates were not able to draw the K Map - CD
AW
C'D' C'D : CD CD' j
for the SOP expression correctly. For a number
of candidates the "Map rolling" concept was 1:
not very clear. Some converted the canonical
A'B' L 1- '
0 1 3
form to cardinal form and then reduced it.
A 'B 1
(ii) Most of the candidates attempted this part 4 5 7 6
correctly. Some drew the logic circuit using
NOR gates while some others drew vague AB 1 1
12 13 15 14
diagrams.
w (i) Most candidates answered this question
correctly. Some candidates made errors in
AB' 1:
8 9
1
ii - - - Jio -
: :-1- - - -

place value and putting variables in K Map. In - (i) Quad 1 = B'D'


some cases, the groups were reduced by laws.
-
Some candidates drew the K Map incorrectly. Quad 2 = B 'C
Many candidates included the redundant Quad 3 = AC
group in the final expression.
Quad 4 = CD '
(ii) Several candidates answered this part correctly.
Some drew the logic circuit using diagrams. So, F(A, B, C, D) = B 'D ' + B 'C + AC + CD '
I (ii) Logic gate diagram, The inputs are:
COMPUTER HARDWARE 61

INPUTS
A' R The person has a valid reservation
ticket .
B'
B Do P The person holds a valid pass issued
by the Railway department .
C* D The person has a valid ID proof .
D' H The person is a disabled person.
D* (In all the above cases 1 indicates yes and 0
indicates no)
Output: T - Denotes allowed to travel (1 indicates
(b) Given, F(P, Q, R, S) = n (5, 7, 8, 10, 12, 14, 15) yes and 0 indicates no in all the cases)
\RS R + S R + S' R ' + S' R' + S (a) Draw the truth table for the inputs and
PQ \
outputs given above and write the POS
P+Q expression for T( R, P, D, H ) .
0 1 3 2
(b) Reduce T( R, P, D, H) using Karnaugh map.
P + Q' i.o Draw the logic gate diagram for the reduced POS
4 5 7 6
expression for T ( R, P, D, H ) using only NOR
P' + Q’ 0 0 0 gates. You may use gates with two or more inputs.
12 13 15 14 Assume that the variable and their components
are available as inputs . || »
P' + Q 0 0
8 9 11 10 Q . 5 . (a ) Given the Boolean function F( A, B, C, D)
= n(0, 1, 2 , 3, 5, 7, 8, 9, 10 , 11).
(i) Quad P ' + S (i ) Reduce the above expression by using
Pair P + Q ' + S ' 4-variable Karnaugh map, showing the
Pair Q ' + R ' + S '
various groups ( i .e., octet, quads and
pairs ) .
So, F(P, Q, R, S) = ( P ' + S) - ( P + Q ' + S ') (ii ) Draw the logic gate diagram for the
• (Q ' + R ' + S ') reduced expression. Assume that the
( ii ) Logic gate diagram, variables and their complements are
available as inputs.
P - eoE—L >
P' + S
(b) Given the Boolean function:
P( A, B, C, D ) = ABC' D + ABC'D '
'

Q' P + Q’ + S' + ABC ' D + ABC'D


Q* F
R' + A BCD + ABCD
R* N— (i ) Reduce the above expression by using
s - Q' + R' + S' 4-variable Karnaugh map, showing the
various groups ( i .e., octet, quads and
pairs ) .
(ii ) Draw the logic gate diagram for the
Q. 4. A person is allowed to travel in a reserved coach reduced expression. Assume that the
of the train, if he/she satisfies the criteria given variables and their complements are
below: available as inputs.
The person has a valid reservation ticket and a Ans. (a) F(A, B, C, D) = 7t(0, 1, 2 , 3, 5, 7, 8, 9, 10 , 11)
valid ID proof. C+ D C + D' C + D' C+ D
or
0 1 3 2
The person does not have a valid reservation A+ B 0 0 0 0
ticket, but holds a valid pass issued by the
Railway department with a valid ID proof. A + B' 4 5 7 6
1 0 0 1
or
12 13 15 14
A' + B'
The person is a disabled person and holds a valid 1 1 1 1
pass issued by the Railway department along 8 9 11 10
with a valid ID proof. A' + B 0 0 0 0

|
|g These questions are for practice and their solutions are available at the end of the chapter
62 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
There is one Octet and one Quad:
.
(a) Draw the truth table for the inputs and
I
Octet: (M0M1M2M3M8M9M10Mn ) = B outputs given above and write the SOP
Quad: (M]M3M5M7) = A + D ' expression for X(S, W, H, A).
(b) Reduce X(S, W, H, A) using Karnaugh's map.
Hence, F(A, B, C, D) = B-(A + D ') Draw the logic gate diagram for the reduced SOP
B F = B.(A + D') expression for X(S, W, H, A) using AND and OR
(A + D ) 1
gate. You may use gates with two or more inputs.
A Assume that the variable and their complements
D’ are available as inputs.
Ans. (a) The truth table for given input and output is:
(b) P(A, B, C, D) = ABC 'D ' + A 'BC 'D ' Inputs Output
+ A 'BC 'D + ABC 'D
+ A 'BCD + ABCD S W H A X

CD' CD CD CD'
0 0 0 0 0 mo
0 0 0 1 0 mi
0 1 3 2 0 0 1 0 0 m2
A’B 1

0 0 1 1 0 m3
A'B 4 5 7 6
1 1 1 0 1 0 0 0 m4
12 13 15 14 0 1 0 1 0 m5
AB
1 1 1 0 1 1 0 1 m6
8 9 11 10 0 1 1 1 1 m7
AB’
1 0 0 0 0 m8
P(A, B, C, D) = BC 'BD 1 0 0 1 1 m9
B*
G
—— i
1 0 1 0 1 mio

BC' + BD
1 0 1 1 1 mn
1 1 0 0 0 m12
1 1 0 1 1 m13
D*
1 1 1 0 0 m14
Q. 6. A school intends to select candidates for the Inter
1 1 1 1 1 m15
School Athletic Meet, as per the criteria given
below: Required SOP expression is
The candidate is from the Senior School and has X(S, W, H, A) = SWHA + SWHA + SWHA
participated in an Inter School Athletic Meet + SWHA + SWHA + SWHA
earlier.
or + SWHA
The candidate is not from the Senior School, but (b) The -
K map representation: Required
the height is between 5 ft. and 6 ft. and weight is expression is in a SOP form which is sum
between 50 kg and 60 kg. of product form. The inputs are taken in
or multiplication order. Here, 0 represents
The candidate is from the Senior School and has
complement of input.
height between 5 ft. and 6 ft. but the weight is not
NHA HA HA HA HA
between 50 kg and 60 kg. w\
The inputs are:
SW
Inputs 0 1 3 2
S Student is from the Senior School SW 0 i1 1:
W Weight is between 50 kg and 60 kg 4 5 7 6

H Height is between 5 ft. and 6 ft. SW 1 1:


12 13 : 15 14
A Taken part in Inter School Athletic Meet
earlier SW 1
. :1 J 1:
(In all of above cases 1 indicates yes and 0 8 9 11 10
indicates no)
Output: X-denotes the selection criteria [1 indicates
1st quad (m13 + m15 + m9 + mn) = SA
selected and 0 indicates rejected in all cases].
I In this the S and A does not change while H .
COMPUTER HARDWARE
Ans (i) The truth table is shown below. Here C, D, F,
63

and W changes in each line. Hence, output G are the input variables of table while X is
will be SA. output variable. The M0-M15 represents the
1st pair (m6 + m7) = SWH max terms of the K map. -
Ilnd pair (m10 + mn ) = SWH C D F G X
Final reduced expression is,
0 0 0 0 0 M0
X(S, W, H, A) = SA + SWH + SWH
The logic diagram for the reduced expression 0 0 0 1 0 Mi
0 0 1 0 0 M2
0 0 1 1 0 M3
0 1 0 0 0 M4
0 1 0 1 1 M5
0 1 1 0 0 M6
X(S,W,H,A) = SA + SWH + SWH 0 1 1 1 1 M7
1 0 0 0 0 M8
1 0 0 1 0 M9
1 0 1 0 1 Mio
..
Q 7 A Football Association coach analysis the criteria 1 0 1 1 1 M „
for a win/draw of his team depending on the 1 1 0 0 0 M12
following conditions:
1 1 0 1 0 M13
If the Centre and Forward players perform well
but Defenders do not perform well. 1 1 1 0 0 Mu
OR 1 1 1 1 1 Mis
If Goal keeper and Defenders perform well but The POS expression is,
the Centre players do not perform well. X(C, D, F, G) = n(0, 1, 2, 3, 4, 6, 8, 9, 12, 13, 14)
OR = (C + D + F + G)(C + D + F + G)
If all the players perform well. (C + D + F + G)(C + D + F + G)
(C + D + F + G)(C + D + F + G )
The inputs are: (C + D + F + G)(C + D + F + G)
Inputs (C + D + F + G)(C + D + F + G)
(C + D + F + G)
C Centre players perform well.
(ii) Using the expression,
D Defenders perform well. X(C, D, F, G) = n(0, 1, 2, 3, 4, 6, 8, 9, 12, 13, 14)
F Forward players perform well. FG
CD F+G F+G F+ G F+G
G Goalkeeper performs well.
(In all of the above case 1 indicates YES C+D : 0 0 0 0:
0 1 3 2
and 0 indicates NO)
Output: X-Denotes the win/draw criteria [1 C+D 0 0
indicates win/draw and 0 indicates defeat in all : 4 5 7 6
the cases]. C+D 0:
12
0
13 15
:p.. 14
(i) Draw the truth table for the inputs and
outputs given above and write the POS C+D 0 0
expression for X(C, D, F, G ). 8 9 11 10
(ii) Reduce X(C, D, F, G ), using Karnaugh's map.
- - -
1st Quad (M0 MJ M2 M3) = C + D
Draw the logic gate diagram for the reduced POS Ilnd Quad (M4 M6 M12 M14) = D + C
expression for X(C, D, F, G ) using AND and OR
Illrd Quad (M8-M9-M12-M13) = F + C
gate. You may use gates with two or more inputs.
Assume that the variable and their complements Reduced expression is,
are available as inputs. F = (C + D)(D + C)(C + F)
64 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
The logic circuit diagram for the reduced S P
.
C T X
I
expression is given below: 0 0 0 0 0 MSL
C+D 0 0 0 1 1 MI
0 0 1 0 0 M?
0 0 1 1 1 Mi.
0 1 0 0 1 Mt
X = (C + D)(D + G)(C + F) 0 1 0 1 1 Ms
0 1 1 0 1 Mg .

0 1 1 1 1 Mz
1 0 0 0 0 M&
c 1 0 0 1 0 M9
.

F
1 0 1 0 1 M10
Q. 8. The principal of a school intends to select students 1 0 1 1 1 Mu
for admission to class XI on the following criteria: 1 1 0 0 1 M „
Student is of the same school and has passed the 1 1 0 1 1 Mu
class X Board Examination with more than 60% 1 1 1 0 1 Mu
marks. 1 1 1 1 1 M15
OR The SOP expression is,
Student is of the same school, has passed the X(S, P, C, T) = 2(1, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14,
class X Board Examination with less than 60% 15)
marks but has taken active part in co-curricular = SPCT + SPCT + SPCT + SPCT
activities. + SPCT + SPCT + SPCT + SPCT
OR + SPCT + SPCT + SPCT + SPCT
(ii) Using the expression,
Student is not from the same school but has either
passed the class X Board Examination with more X(S, P, C, T) = 2(1, 3, 4, 5, 6, 7,10,11,12,13, 14,15)
than 60% marks or has participated in sports at CT
SP CT CT CT CT
the national level.
The inputs are: SP i 1
0 1 3 2
Inputs
SP 1 1 1 1
S Student of the same school.
4 5 7 6
P Has passed the class X Board
Examination with more than 60 % marks. SP 1. 1. 1 1
12 13 15 14
C Has taken active part in co-curricular
activities. SP 1 1
8 9 11 10
T Has participated in sports at the national
level. 1st Octet (M4 + M5 + M6 + M7 + M12 + M13
Output X: Denotes admission status [1 indicates + M14 + M15) = P
granted and 0 indicates refused in all the cases]. 1st Quad (Mj + M3 + M5 + M7) = ST
(i) Draw the truth table for the inputs and Ilnd Quad (M10 + Mu + M14 + M15) = SC
outputs given above and write the SOP Reduced expression is,
expression. X = P + SC + ST
(ii) Reduce X(S, P C, T) using Karnaugh's Map. The logic circuit diagram for the reduced
Draw the logic gate diagram for the reduced SOP expression is given below:
expression for X(S, I* C, T) using AND and OR
gate. You may use gates with two or more inputs.
Assume that the variable and their complements
are available as inputs.
Ans. (i) The truth table is shown below. Here, S, P,
C, T are the input variables of table while X
-
is output variable. The M0 M15 represents the
maximum of the K map. -
I
Q. 9. A government Institution intends to award a
COMPUTER HARDWARE
(ii) Reduce X(E, R, S, C) using Karnaugh's map.
65

medal to a person who qualifies any one of the Draw the logic gate diagram for the reduced SOP
following criteria: expression for X(E, R, S, C) using AND and OR
The person should have been an Indian citizen gates. You may use gates with two or more inputs.
and had lost his/her life in a war but had not Assume that the variable and their complements
completed 25 year of service. are available as inputs.
OR
Ans. (i) According to the question, we have four inputs
The person must be an Indian citizen and has
E, R, S, C and X represents output value. The
served the nation for a continuous period of 25
truth table for given expression X(E, R, S, C) as
year or more but has not lost his/her life in a war.
shown:
OR
The person is not an Indian citizen but has taken E R S X c
active part in activities for the upliftment of the 0 0 00 0
nation. 0 0 10 1
The inputs are: 0 0 01 0
Inputs 0 0 11 1
A The person is/was an Indian citizen. 0 1 00 1
B Has a continuous service of more than 0 1 10 0
25 year. 0 1 01 1
C Lost his/her life in a war. 0 1 11 0
D Taken part in activities for upliftment 1 0 00 0
of the nation. 1 0 10 1
Output: X denotes eligible for medal [1 indicates 1 0 01 1
YES and 0 indicates NO in all cases]. 1 0 1 1 1
(i) Draw the truth table for the inputs and 1 1 0 0 0
outputs given above and write the POS 1 1 0 1 0
expression for X(A, B, C, D ). 1 1 1 0 1
(ii) Reduce X(A, B, C, D) using Karnaugh's map. 1 1 1 1 1
Draw the logic gate diagram for the reduced ,
(ii) 1st Quad (m + m3 4- m9 + mrl ) = R 'C
POS expression for X(A, B, C, D). You may use Ilnd Quad (m10 + mn + m14 + m15) = ES
gates with two or more inputs. Assume that the
1st Pair (m4 + mg) = E 'RC '
variables and their complements are available as
inputs. Final SOI) F = R 'C + ES + E 'RC '
. .
Q 10 A provisional store announces a special discount
.
SC
S'C ; S'C SC SC’
ER"
on all its products as a festival offers only to those
who satisfy any one of the following conditions: E 'R1 : 1 1
0 1 3 2
If he/she is an employee of the store and has a
service of more than 10 year. E 'R 1: :1
'

OR 4 5 7 6
If he/she is a regular customer of the store whose ER :1 1
age is less than 65 year and is not a employee of 12 13 15 14
the store.
OR ER’ 1 1 : 1: 1
If he/she is a senior citizen but not a regular 8 9 ; ii 10
customer of the store. Logic gate diagram for expression
The inputs are:
F = R 'C + ES + E 'RC ' is,
Inputs
R- 1
R'C
E Employee of the store
Regular customer of the store
C
R
S Service of the employee is more than 10 yr
C Senior citizen of 65 yr or above E F = R'C+ ES + E’RC
S
Output X: Denotes eligible for discount
[1 indicates YES and 0 indicates NO in all cases],
(i) Draw the truth table for the inputs and E' - E’RC'
R
outputs given above and write the SOP
expression for X(E, R, S, C).
These questions are for practice and their solutions are available at the end of the chapter
66 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
Q. 11. Given the Boolean function F(A, B, C, D) = 2(5, 6,
. I
The applicant possesses certain special skills as
7, 8, 9, 10, 14) specified in the 'Skill Requirement List' of the
Use Karnaugh's map to reduce the function F, country and is sponsored by a permanent resident
using the SOP form. Draw a logic gate diagram of that country.
for the reduced SOP form. You may use gates with The inputs are:
more than two inputs. Assume that the variables
Inputs
and their complements are available as inputs.
A The spouse or sponsor has permanent
-
Ans. K map representation residence status.
.CD B The spouse has lived in the country for 4
CD1 CD CD CD’
AB or more years.
A’B1 1 C The applicant possesses the required
0 1 3 2
special skills.
A’B . 1.1; i; D Sponsorships by a permanent resident.
4 5 7 6
Output X: Denotes eligible for discount (1
AB 1 indicates YES and 0 indicates NO in all cases).
12 13 15 14
1: (i) Draw the truth table for the inputs and
AB’ i .J. 1
outputs given above and write the SOP
8 9 11 10
expression for X(A, B, C, D).
Here, A, B, C and D are four variables. So, we will (ii) Reduce X(A, B, C, D) using Karnaugh's map.
use 4-variable K-map.
Draw the logic gate diagram for the reduced SOP
1st Pair (m5 + m7) = ABD expression for X(A, B, C, D) using AND and OR
Ilnd Pair (m7 + m6) = A 'BC gates. You may use gates with two or more inputs.
Illrd Pair (m10 + m14) = ACD ' Assume that the variable and their complements
IVth Pair (m8 + m9) = AB 'C ' are available as inputs.
Here, expression Ans. (i) From the above, we have four inputs A, B, C
X (A, B, C, D) = A 'BD + A 'BC + ACD' + AB 'C ' and D and one output X. The truth table for
given variables is shown:
Logic gate diagram for the expression is:
A B C D X
A'BD 0 0 0 0 0
0 0 0 1 0
0 0 1 0 0
A'BC 0 0 1 1 1
X = A'BD + A'BC 0 1 0 0 0
+ ACD' + AB'C' 0 1 0 1 0
0 1 1 0 0
0 1 1 1 1
1 0 0 0 0
1 0 0 1 0
1 0 1 0 0
1 0 1 1 1
Q. 12. The immigration rules of a country allow the issue
1 1 0 0 1
of work-cum-stay permits to an applicant only if
the applicant satisfies any one of the following 1 1 0 1 1
conditions. [ISC 2008] 1 1 1 0 1
The spouse of the applicant is a permanent 1 1 1 1 1
resident of that country, having lived there for at So, the SOP expression is,
least 4 year. A B 'C D + A BCD + AB 'CD + ABC 'D '
OR + ABC 'D + ABCD ' + ABCD
I -
(ii) K map for above SOP expression is,
COMPUTER HARDWARE
(ii) Draw X(A, B, C, D) using Karnaugh's map.
67

.CD C'D' CD CD CD' Draw the logic gate diagram for the reduced SOP
AB expression for X(A, B, C, D) as AND and OR
A'B' 1 gates. You may use gates with two or more inputs.
0 1 3 2 Assume that variables and their complements are
A'B 1 available as inputs.
4 5 7 6 Ans. (i) Truth table for given inputs is given below:
AB [i 1 T: A B c D X
12 13 15 14
0 0 0 0 0
AB' 1
8 9 11 10 0 0 0 1 0
0 0 1 0 0
1st Quad (m12 + m13 + m14 + m15) = AB
0 0 1 1 0
Ilnd Quad (m3 + m7 + mn + m15) = CD
The SOP expression X(A, B, C, D) 0 1 0 0 0
= AB + CD
The logic diagram of expression is: 0 1 0 1 1
0 1 1 0 1
0 1 1 1 1
X = AB + CD
1 0 0 0 0
AB
1 0 0 1 0
1 0 1 0 1
Q. 13. The inaugural function of the newly constructed
1 0 1 1 1
flyover has been organised by the Public Works
Department. Apart from a few special invites, 1 1 0 0 0
entry is permitted only, if: [ISC 2007] 1 1 0 1 1
The person is an employee of the PWD of class 1 1 1 0 1
I category with more than 10 year of working 1 1 1 1 1
experience.
(ii) SOP for X(A, B, C, D)
OR
= A 'BC 'D + A 'BCD ' + A BCD
The person is an employee of any other + AB 'CD ' + AB 'CD + A B C D
government or authorised private organisation + ABCD ' + ABCD
either at the managerial level or with more than K-map representation
10 yr of working experience. NCD
The inputs are:
^
AB
C’D1 C’D CD CD’

Inputs A'B’
0 1 3 2
A The person is a class I employee of PWD.
B The person is an employee of any other A'B i l l!
4 5 7 ; 6
government or authorised private
organisation. AB 1 .0 .1:
12 13 15 14
C The person has more than 10 yr of
AB'
1 1 1
working experience.
8 9 11 10
D The person is holding a managerial post.
A, B, C, D are the input variables.
Output: 1st Quad (m5 + m7 + m13 + m15) = BD
X: Denotes eligible for entry [1 indicates YES and Ilnd Quad (m7 + m6 + m15 + m14) = BC
0 indicates NO in all cases]. Illrd Quad (m15 + m14 + mn + m10) = AC
(i) Draw the truth tables for the inputs and So, the final expression will be
outputs given above and write the S X(A, B, C, D) = BD + BC + AC
expression for X(A, B, C, D).
Logic diagram for X = BD + BC + AC is
68
B-
Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Assume that variables and their complements are
I
D- D BD available as inputs.
Ans. (i) The truth table is given below:
A B C D R Minterms
B 0 0 0 0 0
X = BD + BC + AC
C 0 0 0 1 0
0 0 1 0 0
A-
0 0 1 1 0
0 1 0 0 0
c-
0 1 0 1 0
Q. 14. A combinational circuit with 3 inputs A, B, C
detects an error during transmission of code and 0 1 1 0 1 —> ABCD
gives the output D as 1 if any two of the inputs
are low (0).
0 1 1 1 1 —> ABCD
1 0 0 0 0
(i) Write the truth table with inputs A, B, C and 1 0 0 1 0
output D.
1 0 1 0 0
(ii) Write the SOP expression for D(A, B, C) using
minterms. Implements D using NAND gates 1 0 1 1 1 —> ABCD
only. 1 1 0 0 0
(iii) Write the POS expression for D(A, B, C) 1 1 0 1 0
using maxterms. Implements D using NOR
1 1 1 0 1 ABCD
gates only. [ISC 2007] 0 1 1 1 1 1 -> ABCD
Q. 15. The National College of Journalism is offering
courses in three different categories of journalism, -
(ii) K map representation
which are the print the web and the broadcasting Required SOP expression
media. [ISC 2006] XID
C'D' CD CD CD1
A student is eligible to apply, if he/she satisfies AB
any one of the following conditions: A'B’
0 1 3 2
The student is a graduate in any discipline with
an aggregate percentage of 75 or above and with a A'B 1 1
record of literary skills. 4 5 7 6
OR AB 1 1
The student is a graduate in Mass Communication 12 13 15 14
with aggregate percentage of 75 or above. 1 1
AB' L .l
The inputs are: 8 9 11 10

Inputs R(A, B, C, D) = 2(6, 7, 11, 14, 15)


A Graduate in any discipline. 1st Pair (m15 + mn ) = ACD
B Graduate in Mass Communication 1st Quad (m7 + m6 + m15 + m14) = BC
Final expression
C Aggregate percentage of 75 and above
R(A, B, C, D) = BC + ACD
D Record of literary skills Logic diagram for expression is:
Output R:Denotes eligible to apply [1 indicates
Yes and 0 indicates No in all cases].
(i) Draw the truth table for the inputs and
A
C
D D ACD

outputs given above and write the SOP BC + ACD


expression for R(A, B, C, D).
(ii) Reduce R(A, B, C, D) using Karnaugh's map.
Draw a logic gate diagram for the reduced SOP B
expression for R(A, B, C, D) using AND and OR
BC
gates. You may use gates with two or more inputs.
These questions are for practice and their solutions are available at the end of the chapter
I
Q. 16. Given X(A, B, C, D) = n(2, 3, 4, 7, 9, 10, 11, 12). CD
COMPUTER HARDWARE 69

AB CD CD CD CD
[ISC 2005]
•i

Use Karnaugh's map to reduce this function AB . jl : 1


0 1 3 2
X using the given POS form. Draw logic gate
diagram for the reduced POS form. You may use AB 1 1
4 5 7 6
gates with more than two inputs. Assume that
variables and their complements are available as AB 1 . i .i;
12 13 15 14
inputs.
Ans. From the above expression, AB 1 1
8 9 11 10
X (A, B, C, D) = 11(2, 3, 4, 7, 9, 10, 11, 12)
CD 1st Quad (m0 + + m4 + m5) = A'C'
C+D C + D’ C + D' C' + D Ilnd Quad (m5 + m7 + m13 + m15) = BD
AIT
0 0 1st Pair (m15 + mn) = ACD
A+B
0 1 3 2 Ilnd Pair (m0 + m 2) = ABD
0 0. Final expression will be,
A + B'
4 5 7 6 F = AC + BD + ACD + A'B'D'
A' + B’ 0. Logic diagram for expression:
12 13 15 14 A

A’ + B :0 To ; o c
8 9 11 10

-
1st Quad (M2- M3 M10 - M11) = B + C ' B IBD F

1st Pair (M4- M12) = B ' + C + D D

Ilnd Pair (M3- M7) = A + C ' + D '


Illrd Pair (M9 M11) = A ' + B + D ' C -T
So, the final POS expression will be A
X (A, B, C, D) = (B + C ' ) - (B ' + C + D) - (A + C ' + D ' )
(A ' + B + D ')

Logic diagram for expression: \AB D


B
B-
C- D>B+C
Q . 18. The past Pupil Association of RK University
Computer Science Department is organising a
reunion function at the campus. The invitation
card is to be issued to a person, if:
Xf = (B + C').(B' + C + D).
(A + C' + D'.(A' + B + D') The person is an ex-student of the department
and had passed out in 1995 .
OR
The person is not an ex-student of the department
but passed out from the same university in 1995
and has made a contribution of ' 1000.
B- The inputs are:
A- Inputs
D-
E The person is ex-student of the
Q. 17. Given the Boolean function F(A, B, C, D) = 2(0, 1, department.
2, 4, 5, 7, 11, 13, 15 ). Use Karnaugh's map to reduce U The person is not an ex-student of the
this function F, using the given SOP form. Draw department but a student of the same
logic gate diagram for the reduced SOP form. university.
You may use gates with more than two inputs. P The person passed out in 1995.
Assume that variables and their complements are S The person contributes ?1000
available as inputs. [ISC 2005]
[1 indicates YES and 0 indicates NO in all
Ans. F(A, B, C, D) = 2(0, 1, 2, 4, 5, 7, 11, 13, 15) the cases] ,
70 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Output: I: Denotes the invitation card is issued. [1 (ii) The SOP expression for,
I
indicates YES and 0 indicates NO] I(E, U, P S) = 2(7, 10, 11, 14, 15)
(i) Draw the truth table for the inputs and = E 'UPS + EU 'PS' + EU 'PS
outputs given above and write the SOP + EUPS ' + EUPS
expression for I(E, U, R S). PS
P'S' P’S PS PS1
(ii) Reduce I(E, U, p S) using Karnaugh's map. EIT
Draw the logic gate diagram for the reduced SOP EXT
expression for I(E, U, P S) using AND and OR 0 1 3 2
gates. You may use gates with two or more inputs. ETJ 1 1
Assume that variables and their complements are 4 5 7 6
available as inputs.
EU I
Ans. (i) The truth table is given below: 12 13 15 14
E U P S I(E, U, 1 1
EU'
P S) 8 9 11 10
0 0 0 0 0
0 0 0 1 0 1st Quad (m10 + mn + m14 + m15) = EP
0 0 1 0 0 1st Pair (m7 + m15) = UPS
0 0 1 1 0 So, the final expression will be
0 1 0 0 0
I(E, U, P S) = EP + UPS
0 1 0 1 0
0 1 1 0 0 Logic diagram of expression is:
0 1 1 1 1 E-
1 0 0 0 0
1 0 0 1 0

£>
I = EP + UPS
1 0 1 0 1
1 0 1 1 1
1 1 0 0 0
1 1 0 1 0 s
1 1 1 0 1 u- UPS
1 1 1 1 1

Combinational Circuits
Topic- 3 Concepts covered: Combinational circuits: Adder (Half and Full);
Encoder and decoder; Multiplexer and Demultiplexer

Revision Notes
> Combinational logic circuit is a circuit in which we combine the different gates in the circuit. For Example, Half
Adder, Full Adder, Encoder, Decoder, Multiplexes and Demultiplexer.
Characteristics of combinational circuits:
• A combinational circuit can have an n number of inputs and m number of outputs.
A A'
B Combinationed B'
i Circuit i
i

i i
N M

Fig. Block Diagram


• The output of combinational circuit at any instance of time depends only on the levels present at input points.
• They do not use any memory. The previous state of input doesn't have any effect on the present state of the
circuit.
A combinational circuit consists of related logic gates whose output at any time can be determined directly
from the present combination of inputs irrespective of previous inputs.
(eg.) half adder, full adder, decoder, encoder, multiplexer, etc.
I Circuit Description Expression Truth Table
COMPUTER HARDWARE

Logic diagram
71

Half Performs the S = x ' y + xy ' x y S C


x - 1
Adder addition of two = x©y s
bits C = xy
0 0 0 0 Y ' J
0 1 1 0
1 0 1 1
c
1 1 0 1

c
£>
Full Adder Performs the S= x©y©z x y z S y s
addition of C = xy + yz + 0 0 0 0 0 z
three bits. xz 0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
c
1 1 0 0 1
1 1 1 1 1

Decoder Converts binary 2 x 4 Decoder

1T T
X y Do A D2 2B
information from m < 2n 0 o I 0 o 0
n input lines to a n=2 o I o l o 0 ?x' ? y' ?z: '
maximum of 2n
unique output
1 0 0
1 1 0
0
0
1
0
0
1 D D0

lines.
D A

D A

D A

D A

D A

D A

D D7

Encoder 2n input Decimal number F, F, Fi oj


Decimal lines 0 0 0 0 0
to n output 1 0 0 0 1
Binary lines 2 0 0 1 0 C/3

n =4 3 0 0 1 1
0/
4 ,
3A
*

4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
v,
8 1 0 0 0
9 1 0 0 1
za
F0 = , 3, 5, 7, 9)
Fa = 2(2, 3, 6, 7) F3 F2 F3 F0
F2 = 2(4, 5, 6, 7)
F3 = 2(8, 9)
72 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Multiplexer S e l e c t s
I
b i n a r y
information
from one
of many
inputs lines
and directs
it to a single
output line.
4x1 4 input Y
MUX lines
Si So
2 selection 0 0
Y
lines 0 1 Ii
0
k
1 h
1 1 I3

8x1 8 input s2 s0 Y s2 st s0
MUX lines
Si
0 0 0 lo 1?
-
(23) 3 selec - lo ; =D
tion lines 0 0 1 II k
r
i0 = s'2s [ s'0 0 o l o h 4-
0 1 1 I3
1
1
0
0
0
1
I4
I5
4-
1> F

1 1 0
1 1 1 I7

|Key Terms
> Half Adder: It performs the addition of two bits. There are two inputs A and B and the two outputs are Sum (S)
and Carry (C).
> Full Adder: A combinational circuit that performs the addition of three bits as two significant bits and one
previous carry.
> Decoder: It is a combinational circuit that converts binary information from n input lines to a maximum of 2"
unique output lines.
> Encoder: It produces a reverse operation of decoder. Basically. It is a process of converting signals from one type
to another type.
> Multiplexer: It selects binary information from one of many input lines and directs it to a single output line.
Since, it selects the data, it is also termed as a data selects.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


..
Q 1 A decoder is a combinational circuit which: .
Ans Option (C) is correct .
-
[ISC Sem 1 Paper 2021 22] - Explanation: Decoder circuit used for convert
(A) inputs 2" lines and output V lines binary number to other number system like
(B) converts parallel data into serial data Decimal, Octal etc. It accepts n bit binary value
(C) inputs V lines and outputs 2" lines and produces 2n value as output.
(D) adds more than two binary bits
I
Q. 2. The expression for Sum of a Full adder is:
COMPUTER HARDWARE
Q. 7. In full adder, the SOP expression for sum is
73

[ISC Sem-1 Paper 2021-22] (A ) x © y (B ) y © z


(A) (a + b').(b + c').(a + c') (C) x © z (D ) x © y © z
(B ) a © b © c Ans. Option (D) is correct.
(C) a'b + ab' + a'c Explanation: A combinational circuit that performs
(D ) a © b the addition of three bits (two significant bits and
Ans. Option (B ) is correct. one previous carry) is known as full adder.
Explanation: In Full adder expression for Sum is The SOP expression for sum is
A'B'C + A'BC' + AB'C' + ABC. After simplification it S = x©y©z
produces two XOR gate, i.e. a © b © c.
Q. 8. Which of the following are used to keep
Q. 3. Multiplexers are combinational circuits which are abstraction and modularity in hardware design ?
used for: -
[ISC Sem 1 Paper 2021 22] - (A) Decoders (B ) Encoders
(A) converting High Level signals into Low Level (C) Multiplexer (D) Half adders
signals
Ans. Option (A) is correct.
(B ) data transmission
(C) converting binary to decimal
Explanation: A decoder is a combinational circuit
that converts binary information from 'n1 input
(D) adding binary bits
line to a maximum of 2” unique output lines. This
Ans. Option (B ) is correct. decoder is called n-to-m line decoder where m
Explanation: Multiplexer allowing the transmission < 21. Decoders are used to keep abstraction and
of data from different channels and produced one modularity in hardware design.
output. It is used in data transmission. Q. 9 . Name the combinational circuit that represents
Q. 4. Which of the following is a combinational circuit the following truth table
that produces a reverse operation of decodes ?
Si So 4
(A) Half adder (B ) Full adder 0 0 lo
(C) Multiplexer (D) Decoder
0 1 h
Ans. Option (D) is correct.
1 0 I2
Explanation: Encoder is a combinational circuit
1 1 k
that produces a reverse operation of decoder. If it
has maximum of 2” input lines and n output lines (A) 8 x 1 multiplexer
with n bits. (B ) 6 x 1 multiplexer
..
Q 5 A multiplexes is also called a j since it
(C) 2 x 1 multiplexer
selects one of many inputs. (D) X 1 multiplexer
4
(A) encoder (B ) decoder Ans. Option (D ) is correct.
(C) data selector (D) half adder Explanation: In 4 X 1 multiplexer, there are 4 input
Ans. Option (C) is correct. lines and one output line. Because 4 = 22, So these
Explanation: A digital multiplexer is a combinational ,
are 2 selection lines S0 and S are used to select the
circuit that selects binary information from one of particular input on output.
many input lines and directs it to a single output Truth table,
line. A multiplexer is also called a data selector, Si So 4
since it selects one of many inputs. The selection
of a particular input line is controlled by a set of
0 0 lo
0 1 Ii
selection lines. For n selection lines, there are 2n
input lines. 1 0 h
1 1 k
Q. 6. A combinational circuit that performs the addition
of two bits is called a Q. 10. Multiplexers are used for
(A) full adder (B ) half adder (A) routing several words to same destination
(C) encoder (D) decoder such as bus
Ans. Option (B ) is correct. (B ) parallel to serial conversion
Explanation: A combinational circuit that performs (C) Both (A) and (B)
the addition of two bits is called a half adder. The (D) None of these
two inputs are x and y and the two outputs are Ans. Option (C) is correct.
S(fro sum) and C(for carry) Explanation: Multiplexer is a combinational circuit
Sum (s) = x'y + xy' = x © y that select binary information from one of many
Carry (c) = xy input lines and directs it to a single output line.
Multiplexers are used for
74 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
(i) routing several words to same destination such Ans. Option (B ) is correct.
I
as bus Explanation: This decoder is called n to m line
(ii) parallel to serial conversion decoder, where m < 2n. The purpose of a general
Q. 11. What will be the carry expression of half adder? decoder is to generate 2n or less minterms of n
(A ) x + y (B) x’y input variables. A decoder has n inputs and m
(C) xy' (D) xy outputs and is also referred as n x m decoder.
Ans. Option (D) is correct. Q. 14. An encoder consists of 2n (or less) input lines and
Explanation: A combinational circuit that performs output lines.
the addition of two bits is called a half adder. The (A) n (B) n + 1
two inputs are x and y an the two outputs are S(for (C) n - 1 (D) 2n
sum) and C (for carry). Ans. Option (A ) is correct.
The expression for S and C: Explanation: An encoder is a combinational circuit
Sum (S) = x'y + xy' or x © y that produces a reverse operation of decoder. An
Carry (C) = xy encoder consists of 2n (or less) input lines and n
Q. 12. Which of the following is/are examples of output lines, which generates the binary code for
combinational circuits? the 2n input variables.
(A) Half adder (B) Full adder Q. 15. In 8 x 1 multiplexer, these are B input lines and
(C) Encoder (D) All of these
Ans. Option (D) is correct. (A) two input lines
Explanation: A combinational circuit consists of (B) three output lines
related logic gates whose output at any time can be (C) one output lines
determined directly from the present combination (D )two output lines
of inputs irrespective of previous inputs e.g. half Ans. Option (C) is correct.
adder, full adder, decoder, encoder, multiplexer etc. Explanation: In 8 x 1 multiplexer, there are
Q. 13. A decoder has n inputs and m outputs and is also 8 input lines and one output line. Because
referred as 8 = 23, so there are three selection lines so, Sj and
(A) n x n decoder (B ) n x m decoder S2 used in
(C) m x n decoder (D) m x m decoder

SUBJECTIVE TYPE QUESTIONS


Ans. Difference between multiplexer and decoders are
Short Answer Type
<©> Questions I - (2 marks)
as follows:
Multiplexer Decoders
Q.l. What are Decoders? How are they different form (i) A digital multiplexer A decoder is a
Encoders? [ISC 2013] is a combinational combinational
circuit that selects circuit that coverts
Ans. Decoders: A decoder is a combinational circuit binary information binary information
that converts binary information from 'n' input from one of many from 'n' input lines
lines to a maximum of 2n unique output lines. input lines and to a maximum of 2n
-
This decoder is called n-to m line decoder, directs it to a single
output line.
unique output lines
where m [ 2n. Here, the decoder has n inputs
and m output lines and is also referred as n x m (ii) It is called as data This decoder is called
selector, since it n-to-m line decoder
decoder.
selects one of many where m < 2n
An encoder is different from decoder because it inputs
produces a reverse operation from that of decoder, (iii) A multiplexer is Decoders are used
i.e., an encoder provides signals into binary form, used to share several to keep abstraction
whereas decoder provides various signals into signals to one device and modularity in
decimal form. like A/D convertor hardware design.

Q. 2. State the difference between multiplexer and e.£.,4-to-l line e.g., 3-to-8 decoder.
multiplexer
decoders. [ISC 2009]
( Any two)
I
Q. 3. State the difference between an encoder and a Circuit for carry:
COMPUTER HARDWARE 75

multiplexer circuit. [ISC 2005]


C0 = AB + BC + AC
Ans. Difference between encoder and multiplexer are as
follows: A '
AB
B
Encoder Multiplexer
(i) Encoder converts A multiplexer is a
signals from one type circuit with many B BC CARRY
to another type inputs but only one
output
(ii) It does not allow It allows time
the process of time sharing between
sharing signals
(iii) It is a reverse It is also called data [ISC Marking Scheme, 2020]
operation of decoder selector, since it
selects one of many Q. 2. What is a multiplexer ? [ISC 2017]
inputs Ans. Multiplexer is a special type of combinational
e.g., Octal-to-binary e.g., 4-to-l line circuit. There are n-data inputs, one output and
Multiplexer m select inputs with 2m = n. It is a digital circuit
which selects one of the n data inputs and routes it
(Any two) to the output.
..
Q 4 What is an encoder ? State its application. Multiplexer:
[ISC 2005]
Ans. An encoder is a logic circuit that converts signals of
r DZD,
one type to another. An encoder consists of 2n (or Dz
less) input lines and n output lines, which generates Dz
the binary code for the 2n input variables. Data n:1
Input Multiplexer -> Y (output)
Applications of Encoder
(i) It is used in conversion of decimal to binary,
hexadecimal to binary, octal to binary system. Dz - s -
E

<©>
(ii) They are used in computer to convert the
various input forms to binary form.

Short Answer Type


Enable
Input rrr
Sa - s sasa
Questions- II (3 marks)
Select Input
..
Q 1 Draw the truth table and derive an SOP expression Circuit diagram for 8: 1 MUX:
for sum and carry for a full adder. Also, draw the
logic circuit for the carry of a full adder. IN0
T>
Ans. Truth Table for a Full adder:
A
0
B
0
C
0
S
0
C0
0
INI

IN2
4>
-t>
i>
D
0 0 1 1 0
0 1 0 1 0 IN3

0 1 1 0 1
IN4
->
1 0 0 1 0 x
1 0 1 0 1 IN5
H>
1 1 0 0 1 IN6
i
SOP Expression:
i i i i
IN7
D
Sum = A'B'C + A'BC' + AB'C' + ABC
2 (1,2,4,7)
S2 SI SO
D
Carry = A'BC + AB'C + ABC' + ABC
2(3,5,6,7)
76 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 3. State the application of Half Adder. Draw the Ans. A 4: 1 multiplexer consists of four data input lines
I
truth table and circuit diagram for a Half Adder. as D0 to D3, two select lines. S0 and Sj and a single
output line Y.
0 [ISC 2017]
Q. 4. What is a decoder? Draw the logic diagram for a Si S0 Y
binary to octal (3 to 8) decoder ? [ISC 2016] 0 0 D0
Ans. Decoder: It is a combinational circuit inputs 'n' 0 1 Di
lines and outputs 2n or fewer lines. It converts 1 0 D2
LLL to HLL.
1 1 D3
Logic Diagram:
A
R BRCR 0
h
>
1
Y
2
>
3

I2

6 I3

Si
[ISC Marking Scheme 2016] SQ -t»
Q. 6. State how a half adder is different from a full
adder. Also give their respective uses.
Examiner's Comment [ISC 2012, 05]
Ans. Difference between half adder and full adder are
w The definition was written correctly by most of
as follows:
the candidates. Some candidates were confused
with the logic diagram of a decoder and made Half Adder Full Adder
the diagram of an encoder instead. A few used
A combinational circuit A combinational circuit
the OR gate instead of the AND gate in the logic
that performs the that performs the
diagram.
addition of two bits is addition of three bits
called a half adder. (two bits are significant
Answering Tip and a one is a previous
carry) is called a full
w Students should learn the concept of combinational adder.
circuits as encoders, decoders and multiplexer. The half adder circuit It consists of three
They should also practice on designing the logic needs two binary inputs binary inputs and two
circuits. and two binary outputs. binary outputs.
Half adder does not Full adder has carry in
Q. 5. Briefly explain the working of a 4: 1 multiplexer. has carry in input. input.
Also, draw the logic diagram of 4: 1 multiplexer.
Q. 7. Draw the circuit diagram for a 3 to 8 decoder.
[ISC Specimen Question Paper 2016] [ISC 2010]

These questions are for practice and their solutions are available at the end of the chapter
I
Ans. The logic diagram for 3 to 8 decoder is:
COMPUTER HARDWARE
Multiplexers are used for:
77

Finn
...
x' y' z.
D0
(i) Routing several words to same destination
such as bus.
(ii) Parallel to serial conversion
Q. 10. Using two halt adder and an OR gate, construct
full adder. [ISC 2007, 05]
D. Ans. As we know, the function expression of Sum and
Carry of full adder are:
Sum (S) = x © y © z
D2
Carry (C) = xy + yz + xz
To construct the full adder, using two half adder
D3
and an OR gate, we take three input variables, x, y
and z. As shown in truth table:
D4
x y z s c
0 0 0 0 0
D5
0 0 1 1 0
0 1 0 1 0
Do 0 1 1 0 1
1 0 0 1 0
D7 1 0 1 0 1
1 1 0 0 1
..
Q 8 Draw the truth table for half adder. Also derive 1 1 1 1 1
a POS expression for the half adder and draw its From the above truth table, logic diagram using
logic circuit. two half adder and OR gate.
Ans. Truth Table for Half Adder x< x ®y
P S = xeysz
x y s c

o o 0 0
C = xy + z(x©y)
0 1 1 0 xy = xy + yz + zx
l o l o
l l o l
The algebraic expression of Sum and Carry are,
-
Sum (S) = (x + y) (x ' + y ') on applying XOR gate,
Long Answer Type
So, Sum (S) = x © y <©> Questions -I (4 marks each)
Carry (C) = xy
Its logic circuit diagram is: Q. 1. How is a half adder different from a full adder?

E>-
X* Draw the truth table and derive the SUM and
CARRY expression for a full adder. Also, draw the
logic diagram for a full adder. [ISC 2016]
Ans. Half adder adds only two binary bits where as a

D *c
Full adder adds three input binary bits. Half adder
performs partial addition whereas a Full adder
performs total addition.
Q. 9. What is the purpose of a multiplexer? Mention Truth table for a Full Adder:
any two application of a multiplexer. [ISC 2008]
A B C Sum (S) Carry Zero (Cn)
Ans. A digital multiplexer is a combinational circuit that
0 0 0 0 0
select binary information from one of many input
0 0 1 1 0
lines and directs it to a single output line.
0 1 0 1 0
The selection of a particular input line is controlled 0 1 1 0 1
by a set of selection lines. For n selection lines, 1 0 0 1 0
there are 2n input lines. A multiplexer is also called
1 0 1 0 1
a data selector, since it selects one of many inputs,
1 1 0 0 1
e.g., 4 to 1 line multiplexer, 8 to 1 line multiplexer,
1 1 1 1 1
etc.
78 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Expression for Ans. Truth table for Octal to Binary Encoder:
I
Sum =A©B©C
Input Output
and Carry = AB + AC + BC
ABC
Octal number B2 Br B0
SUM 0 0 0 0
1 0 0 1
2 0 1 0
D AB
3 0 1 1
4 1 0 0
D BC CARRY
5
6
1
1
0
1
1
0
D AC

[ISC Marking Scheme 2016]


7 1 1 1
Logic Diagram for Octal to Binary Encoder:
0
1
2
Examiner's Comment 3
4 ,

w Candidates were able to answer this part correctly. 5 L


6
A few candidates did not write the expression and 7,
some others drew the logic diagram. The truth
table was not proper in some cases.

Answering Tip
'B2 BI '
[ISC Marking Scheme
B 0

2015]
w Students should learn the concept of combinational
circuits as half adder and full adder. They should
also practice on designing the logic circuits with
the truth tables. Examiner's Comment
w Most of the candidates answered this part correctly,
Q. 2. Define Half Adders. Draw the circuit diagram a few candidates drew the decimal encoder while
and the truth table for a Half Adder. <fg)[ISC 2015] some others drew the gates wrong.

n
w
Examiner's Comment
Some candidates drew wrong circuit diagrams.
The circuits for partial sum and carry were done
separately and not as one circuit in some cases.
w
V' Answering Tip
More practice should be done in drawing encoder
and decoder and proper use of connectors and
gates must be there.

Answering Tip Q. 4. What is a Multiplexer? State an application of


a MUX. Also draw the logic diagram of a 4: 1
r' More practice should be done in drawing half Multiplexer.
adder and full adder and also the truth table [ISC 2015, Specimen Question Paper 2016]
and expression of both adders. Students must be Ans. Multiplexer: It is a combinational circuit which
told that Half Adder is one circuit and not two inputs parallel data and outputs one serial data.
different circuits.
Application:
(1) It is used as data selector.
Q. 3. Draw the truth table and logic gate diagram for an (2) Routing of signals
Octal to Binary encoder. [ISC 2015] (3) Data transmission
(4) Telephone exchange, TV etc.
These questions are for practice and their solutions are available at the end of the chapter
I COMPUTER HARDWARE 79

Jo- JoS'iS'o

w

LJK
4S'iS0
Y
w
Answering Tip
Application of logic gates should be learnt along
with definition, truth table, logic diagram and

k
De* J S'0
expressions.

Q. 5. With the help of a logic diagram and a truth table,


explain a decimal to binary encoder. [ISC 2014]
Z3S1S0
OR
s0 - Draw the truth table and logic circuit diagram for
[ISC Marking Scheme 2016] converting a decimal number to binary Explain.
Detailed Answer: .
the working principle with an example [ISC 2005]
4: 1 Multiplexer: In 4 to 1 multiplexer, there are 4 Ans. The truth table for decimal to binary is shown below:
input lines and one output line. Because 4 = 22, Truth Table of Decimal to Binary Encoder
,
so there are 2 selection lines S0 and S are used to
Inputs Outputs
select the particular input on output.
The truth table is shown for a 4 x 1 multiplexer: I A B C D
0 0 0 0 0
Truth Table
1 0 0 0 1
Si S0 V
2 0 0 1 0
0 0 Jo
3 0 0 1 1
0 1 4 4 0 1 0 0
1 0 4 5 0 1 0 1
1 1 4 6 0 1 1 0
The size of the multiplexer is specified by the
number 2n of its data input lines and the single 7 0 1 1 1
output line. The function expression drawn from 8 1 0 0 0
the above truth table is:
9 1 0 0 1
- - - - - - - -
Y = I0 S1' S0' + I1 S1' S0' + I2 S1' S0' + I3 S1' S0'
[ISC Marking Scheme 2014]
Each of the four inputs I0 to I3 is applied to one
input of an AND gate. Selection lines A and B are
decoded to select a particular AND gate. Examiner's Comment
4- /QS'IS'O
w Some candidates drew the AND gate instead of OR
4s'lSo gate, some drew the octal/hexadecimal encoder
4 instead of decimal encoder. However, most of
Y the candidates answered this part correctly. The
4- working/explanation was shown in some cases
which was not required.
4SiS'o
4
4S1S0 Answering Tip
s0
*l»—1 w Practice should be done in deriving the encoders
along with the expression, truth table and logic
Examiner's Comment circuit/diagram.

w Several candidates drew the block diagram instead Detailed Answer:


of the logic circuit diagram. In some cases, the From the above truth table, we will considered
definition was not clear and vague answers were
only those output where the binary value of A, B,
given. C, D is 1 only. From expression,
80 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
A = S(8, 9) From the given truth table,
I
B = S(4, 5, 6, 7 ) (i) When both inputs are equal to 0, then F0
C = S(2, 3, 6, 7) produces 1 as output.
D = S(l, 3, 5, 7, 9) (ii) When input A = 0 and B = 1, then Fj produces
Logic diagram of decimal to binary encoder is: 1 as output.
o (iii) When input A = 1 and B = 0, then F2 produces
JL 1 as output.
l (iv) When both inputs A and B are equal to 1, then
F3 produces 1 as output.
2.
3 Q. 7. Define multiplexer and state one of its uses. Draw
the logic diagram for a 4 x 1 multiplexer.
[ISC 2012]
-& Ans. Multiplexer: A multiplexer is a combinational
-6- circuit that selects binary information from one of
many input lines and directs it to a single output
-8- line.
y It is a device that accepts data from one of many
input sources for transmission over a common
shared line. For n selection lines there are 2n input
lines. A multiplexer is also called a data selector,
since it selects one of many inputs. A logic diagram
A B C D
for 4 x 1 line multiplexer is as follows:
Q. 6. Draw the truth table and logic gate diagram for a hr
2 to 4 decoder and briefly explain its working.
k
[ISC 2013] Y = /o +
k +h+h
* i
OR 1
What is a decoder? Draw the truth table and logic
circuit diagram for a 2 to 4 decoder. [ISC 2011, 06]
Ans. Decoder is a digital electronic circuit, which
hr M
converts binary information from 'n' input lines to
a maximum of 2n unique output lines.
Sj=A S0 = B k k
YY Si '

F0 s2-
Q. 8. What is a full adder? Draw the truth table for a

Fi full adder. Also derive SOP expression for the full
adder and draw its logic circuit. [ISC 2011]
Ans. Full Adder: A combinational circuit that performs
F2 the additions of three bits (two significant bits and
one previous carry) is known as full adder.
F3 Truth Table for Full Adder
x y z Sum Carry
Here, A and B are two input variables and F0, Fj, F2 0 0 0 0 0
and F3 are outputs.
0 0 1 1 0
The truth table for 2 to 4 decoder is: 0 1 0 1 0
Truth Table of 2 x 4 Decoder 0 1 1 0 1
A B F0 Fi F2 F3 1 0 0 1 0
0 0 1 0 0 0 1 0 1 0 1
0 1 0 1 0 0 1 1 0 0 1
1 0 0 0 1 0 1 1 1 1 1
1 1 0 0 0 1 Sum = xyz + xyz + xyz + xyz = x © y © z
Carry = xyz + xyz + xyz + xyz = xy + yz + xz
I x —Njj ~~
oSum(S) = x®y®z
COMPUTER HARDWARE 81

y
^ xy
Long Answer Type
<& Questions-II (5 marks each)
Q. 1. Draw the logic circuit diagram for an octal to binary
encoder and explain its working when a particular
Carry (C) = xy + yz + zx digit is pressed. Also, state the difference between
encoders and decoders . [ISC, 2020]
z zx Ans. Circuit diagram of a octal to binary encoder:
x 0 1
Q. 9. What is a multiplexer? Draw the truth table and
logic diagram of a 8 X 1 multiplexer. [ISC 2010] 2 -
1"

3
Ans. A multiplexer is a combinational circuit that selects 4 --
1

binary information from 2n input lines and directs 5 --


1

to a single output line. 6 --


11

8 x 1 Line Multiplexer In 8 X 1 multiplexer, we


take one output lines and 8 input lines and 3
selection lines.
Selection Line Output B2 B1 BO

h . So .
F Working: It converts High Level to Low Level.
0 0 0 o Example: If input is (5)8 the output will be (101)2,
i.e., binary value of 5 and so on. To convert the
0 0 1 1
output signal to 1, a trigger is applied to the
0 1 0 2 required gate otherwise it remains 0 as default.
0 1 1 3 An encoder is a combinational circuit which
1 0 0 4 inputs 2n or fewer lines and outputs 'n' lines.
1 0 1 5
It converts HLL to LLL e.g. octal, decimal and
1 1 0 hexadecimal to binary
6
A decoder is a combinational circuit which
1 1 1 7
inputs 'n' lines and outputs 2n or fewer lines. It
From the given truth table, we conclude some converts LLL to HLL e.g. binary to octal, decimal
expression as follows: and hexadecimal. [ISC Marking Scheme, 2020]
I0 = S2'S1'S0T0 Q. 2. Draw the logic diagram and truth table to encode
It = S2'S/S0'I , the decimal numbers (2, 3, 5, 7, 8) and briefly
12 = S2'S/S0'I2 explain its working.
13 = S2'S/S0'I3 [ISC, Specimen Question Paper 2016]
14 = S2'S/S0T4 Ans. Given F(A, B, C, D) = 2(2, 3, 5, 7, 8).
15 = S2'S/S0T5 Truth Table
16 = S2'S/S0T6 A B C D F
¥ = S2'S/S0'I7 0 0 0 0 0
From the expression, the logic diagram is formed 0 0 0 1 0
as follows: 0 0 1 0 1
S2 S, So 0 0 1 1 1
0 1 0 0 0
4-
k
MD 0
0
1
1
0
1
1
0
1
0
0 1 1 1 1
1 0 0 0 1
1 0 0 1 0
1A - :
-Mk > i> r
1
1
0
0
1
1
0
1
0
0
1 1 0 0 0
4- = =o 1
1
1
1
0
1
1
0
0
0
1 1 1 1 0
82 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
p(«rt«c-s
Sum of Product (SOP) expression, (x®y)
F(A, B, C, D) = A 'B'CD' + A 'B'CD
+ A 'BC 'D + A 'BCD
X
)E >
+ AB 'C 'D' (x0y).C
Logic gate diagram, c D (x®y)c + x.y = K

A . {>
A'
A'BC'D

A'B’CD'
D- xy

Truth table for Full adder is


A B C Sum Carry
F
B )AB'C'D 0 0 0 0 0
B
C' A'B'CD 0 0 1 1 0
O
0 1 0 1 0
D* f> ’ 0 1 1 0 1
D
OA'BCD i 0 0 1 0
..
Q 3 Draw the truth table and logic circuit diagram for 1 0 1 0 1
a hexadecimal to binary encoder [ISC 2007] . 0 1 1 0 0 1
..
Q 4 What is full adder? Write the SOP expression 1 1 1 1 1
for sum and carry simplify the expressions SOP Expressions from the above truth tables.
algebraically using Boolean algebra [ISC 2007] . Sum = A'B'C + A'BC' + AB'C' + ABC
.
Ans Full adder: Full adder is a logic circuit that can add = C(A'B' + AB) + C'(A'B + AB')
three bits at a time producing two outputs, one of
which is the sum bit and the other the carry bit. = C®A®B
Carry = A'BC + AB'C + ABC' + ABC
= AB + BC + AC.

These questions are for practice and their solutions are available at the end of the chapter
I COMPUTER HARDWARE

Solutions for Practice Questions


TOPIC-1 4 Marks Questions
2 Marks Questions .
4 Universal Gates NAND and NOR gates are
. known as universal gates because all the other
2 Logic circuit of NAND gate using NOR gates:
gates (AND, OR, NOT) can be constructed using
NAND expression = A' + B ' or (AB) '
only these two gates.
Using NAND,

[ISC Marking Scheme 2016]


.
5 The truth table of XNOR gate for 2 input is shown Using NOR,
as below:
X Y
o 0 1
0 1 0 10. Let us take two input values A and B. Now
the implementation of OR gate using NAND
1 0 0
gate is shown below:
1 1 1
Function expression is, A. A’

F = X' Y' + X Y - _=
F (A'.B’)’ = A + B

F = X?Y
B'
The logic diagram is shown as: B"

\
F = (X'Y' + XY) TOPIC- 2
3 Marks Questions
/
4. Given expression is
10. P = AB + CD. -
F = A (A ' + B) C (A + C)- -
-
Dual of expression P is (A + B) (C + D) On applying distributive law,
The logic diagram for dual expression is: - - -
F = (A A ' + A B) (CA + CC)
A- (A + B)' So, - - -
F = (A B) (C A + C)
B (using complement law and idempotent law)
(A + B) . (C + D) F = A B(C) - (using absorption law)
F = ABC --
c The required logic gate diagram for the reduced

.
D- (C + Dl -
ls SOP expression of given truth table will be:
expression above is given below:

A'BC' + A'BC + ABC ' + ABC


Logic gate diagram of above expression as shown 5 Marks Questions
below:
.
5 (i) The given expression,
F(A, B, C, D) = 2(0, 2, 4, 5, 8, 9, 10, 12, 13)
1st Quad(m8 + m9 + m12 + m13) = AC
Ilnd Quad (m4 + m5 + m12 + m13) = BC
\ CD
AB — —
CD CD CD —
CD

AB
3
ii 2
AB
7 6
AB
15 14
AB 1
ii 10

Illrd Quad (mg + m2 + m8 + m10) = BD


84 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII

Hence, expression will be


.
Here, we put all the maxterms of the given input
I
F = BD + BC + AC and we conclude that,
(ii) Logic diagram of expression F = BD + BC + AC - - -
1st Quad (M2 M0 M10 M8) = B + D
Ilnd Quad (M2 M6 M10 M14) = C ' + D
The POS expression is F = (B + D) (C ' + D) -
Its logic circuit diagram is as follows:
B C D
~
^ 7
B+ D

tF= (B+D).(C'+ D)

.
12 (i) Given expression r+p]
F(A, B, C, D) = (A + B + C + D) (A + B + C + D ')
(A + B + C ' + D') (A + B + C ' + D)
(A + B ' + C + D') (A + B ' + - . -
17 K map representation,
1st Pair (M2-M3) = A + B + C
C ' + D ')-(A ' + B + C + D)
(A ' + B + C ' + D) Ilnd Pair (M4 M5) = A + B + C
.^CD C+D C + D’ C + D' : C’+ D
Illrd Pair (M12 M14) = A + B + D
All So, the final expression will be
0
A+ B 0: 0 0 F(A, B, C, D) = (A + B + C)-(A + B + C) (A + B + D)
0 1 3 2
CD
A + B' 0. 0. AB C+ D C+D C+D C+D
4 5 7 6 :0 0;
A+ B
A' + B’ 0 1 3 2
12 13 15 14
A+ B : 0 0: 1
A' + B 0 0 4 5 7 6
8 9 11 10
A+ B 0! :0
12 13 15 14
We get 2 quads,
1st Quad (Mj Mj Mg M = A + D ' A+ B 1
Ilnd Quad (M10 M8 Mo M2) = B + D ^ Logic diagram for expression,
8 9 !
! 10

Thus, the final output is,


F = (A + D ')-(B + D) F = (A + B + C) (A + B + C)-(A + B + D)
A-
(ii) The logic gate diagram using NOR gate for
reduced expression is:
B
C- £> A+ B + C

A-
A +B+ C
F = (A + D').(B + D) B F
C-

A-
+ B+ D
fi -
.
ls Here, given X(A, B, C, D) = P(0, 2, 6, 8, 10, 14) D-

«
A
C+ D C + D' C + D' :C' +D 10 Marks Questions
4.
A+B 0
0 1 3 °-i- 2 T
(a) R P D H
A + B' 0 (OUTPUT)
4 5 7 6 0 0 0 0 0
A' + B’ 0 0 0 0 1 0
12 13 15 14
0 0 1 0 0
A’+ B 0 0 0 0 1 1 0
8 9 11 10
0 1 0 0 0
0 1 0 1 0
I COMPUTER HARDWARE 85

0 1 1 0 1 •(A '
+ B ' + C ' + D) (A ' + B ' + C ' +
0 1 1 1 1 D ')
1 0 0 0 0 -
(ii) From K map, we get
1
1
0
0
0
1
1
0
0
1
- - -
1st Quad (M0 M2 M4 M6) = A + D

1 0 1 1 1 AB" C+D C + D' C' + D' C' + D


1 1 0 0 0
A+B 0 0
1 1 0 1 0
0 1 3 2
1 1 1 0 1
1 1 1 1 1 A + B' 0 0
POS Expression: T(R, R D, H) = 31(0, 1, 2, 3, 4, 4 5 7 6
5, 8, 9, 12, 13) :0 0:
A' + B '
(b) 12 13 15 14

D+H D + H' D ' + H' D' + H A' + B : 6 0: 0


8 9 11 10
0 L 3 2
R+P 0 0 0 0 1st Pair (M15- M14) = A + B + C ' ' '

Ilnd Pair ( M8-M9) = A ' + B + C


R + P' 4 5 7 6
0 0 1 1 1ST QUAD (m0,m2,m4,m6) = (A + D)
12 13 15 14 Thus, the final output is,
R' +F
0 0 1 1 F = (A + D) - (A ' + B + C ' ) - (A ' + B + C)
8 9 11 10 The logic diagram for the expression is:
R' + P 0 0 1 1

There is one Octal and one Quad:


A
D- D A+D

octet: (M0M1M4M5MgM12M13) = D B' -


Quad: (M0MIM2M3) = R + P
Hence, T(R, P, D, H) = D (R + P)
C'-
A" D A' + B' + C F=(A+D).(A'+ B+q A'+B+q
^

P
>
(R + P)'
[(R + P) ' + D' ]'
B-
c-
14. (i )
D A' + B + C

ei >
A B C D
.
9 (i) Given expression X (A, B, C, D) has four
inputs and X represents output values. The 0 0 0 0
truth table for given inputs is, 0 0 1 1
A B C D X 0 1 0 1
0 0 0 0 0
0 0 0 1 1 0 1 1 0
0 0 1 0 0 1 0 0 1
0 0 1 1 1
0 1 0 0 0 1 0 1 0
0 1 0 1 1 1 1 0 0
0 1 1 0 0
1 1 1 0
0 1 1 1 1
1 0 0 0 0 (ii) D(A, B, C) = ABC + ABC + ABC
1 0 0 1 0
1 0 1 0 1
1 0 1 1 1
1 1 0 0 1
1
1
1
1
0
1
1
0
1
0
A
B
— ABC
1 1 1 0
1
Using above truth table the following POS
C -=0
expression will be drawn: A
(A + B + C + D)-(A + B + C ' + D) B —=0
-
(A + B ' + C + D) (A + B ' + C ' + D)
(A ' + B + C + D)-(A ' + B + C + D')
c — =0=-
1
86 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class-XII

_
I
(in) D(A, B, C) = (A + B + C) (A + B + C) (A + B + C) 5 Marks Questions
(A + B + C) - (A + B + C) .
3 The truth table for hexadecimal to binary encoder
A+ B +C will be as follows:
Hex No. Jk A A Jjo .

A +B+C 0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
A + B+ C 3 0 0 1 1
-D
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
A +B + C
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
A 1 0 1 0
B 1 0 1 1
C 1 1 0 0
TOPIC-3
3 Marks Questions D 1 1 0 1
.
3 Half adder is a combinational logic circuit with E 1 1 1 0
two inputs and two outputs. The half adder F 1 1 1 1
circuit is designed to add two single bit binary From the truth table it can be seen that to receive
number A and B. It is the basic building block for high (1) signal.
addition of two single bit numbers. This circuit B0 must be connected to switches for 1 , 3 , 5 , 7, 9,
has two outputs carry and sum. B, D and F.
Truth Table :
Bi 2, 3, 6, 7, A, B, E and F
Inputs Output Circuit Diagram : B2 4, 5 , 6, 7 , D, E and F
A B S C A- B3 8, 9, A, B, C, D, E and F.
B Therefore, using 16 input push button switches
0 0 0 0
for entries 0, 1, ..., 9, A, B, C, D, E, F and 4 OR -
0 1 1 0
c -
gates to generate a 4 bit word B2BjB0 for output,
a diagram for hexadecimal to binary encoder may
1 0 1 0
be drawn.
1 1 0 1
0 LU
4 Marks Questions 1
.
2 Half adders are combinational circuits which adds 2
two input binary bits and output two binary bits. 3
(Partial Sum and Carry). 4 LLI
Circuit Diagram: 5
A- itx> 6
B 7
Sum
8
9
LU
D Carry A
B
Truth Table of Half Adder C
A B Partial Sum Carry D LU
0 0 0 0 E
0 1 1 0
1 0 1 0
F
1 1 0 1
[ISC Marking Scheme 2015] f >3 B2 BI B0
I 87

SELF ASSESSMENT PAPER 2 -


Maximum Marks: 25 Timing: 1 Hour
.
1 Gates are digital circuits. Why? [1]
2. Draw truth table for two input NOR Gate. [1]
3. Identify the gate in (i) & (ii) [1]
(i) Odd number of is produce output 1.
(ii) If all the inputs are 1 then the output produced is 0.

.
4 Draw the logic diagram and truth table for a 2 input XNOR gate. [2]
5. Study the diagram given below and answer the question that follow:

(i) Name the basic gate which is represented by the diagram.


(ii) What will be the value of X when A = 1 and B = 0? [2]
.
6 Using only NAND gates, draw the logic circuit diagram For A' + B. [2]
7. Differentiate between Half Adder and Full Adder. Draw the logic circuit diagram for a full odder. [2]

8. Draw a logic circuit for the boolean expression: [3]


(U + V').W' + z
9. What is a Multiplexer? How is it different from a decoder? Draw the circuit diagram for a 8: 1 Multiplexer. [5]

10. F(A, B, C, D) = Jt(0, 1, 2, 3, 5, 7, 9, 13). Use K-map to reduce the given function fusing the given POS form. Draw
a logic gate diagram for the reduced POS form. You may use gate with more than two inputs. Assume that the
variables and their complements are equitable as inputs. [5]

OSWAAL LEARNING TOOLS


For Solutions of the above Self Assessment Paper, follow the link

Visit: https: // bit .ly/ 3zMlRiP Or Scan the Code


Section B

CHAPTER

PROGRAMMING
IN JAVA
Programming in Java ( Review of Class XI Sections B and C ); Objects:
Objects as data ( attributes ) + behaviour ( methods or functions );
(a )
object as an instance of a class. Constructors, ( b ) Analysis of some real
*world programming examples in terms of objects and classes, (c ) Basic input/ output using Scanner and Printer
'classes from JDK; input/ output exceptions.Tokens in an input stream,concept of white space,extracting tokens
' from an input stream ( String Tokenizer Class ).; Primitive values,wrapper classes,types and casting: Primitive
Values and its types. Corresponding wrapper classes for each primitive type.; Class as type of the object, as
'mechanism for user defined types. Variables Expressions: Variables as names for values named constants
ffinal ); expressions (arithmetic and logical ) and their evaluation ( operators, associativity, precedence).
'/ Assignment operation; difference between left hand side and right hand side of assignment. Statements,
'scope: Statements: conditional ( if, if else, if switch, case ternary operators ), looping ( for, while, continue,
'break ); grouping statements in blocks, scope and visibility of variables. Methods: Methods (as abstractions
for complex user defined operations on objects). Formal arguments and actual arguments in methods; different
1behaviour of primitive and object arguments. Static method and variables. The this operator. Examples of
algorithmic problem solving using methods ( number problems, finding roots of algebraic equations etc.)
;Arrays, strings: Structured data types - arrays, strings, algorithms: missing searching, finding maximum/
\minimum,sorting techniques, solving systems of linear equations, substring,concatenation, length,access to
'char in string, etc.).; Recursion: Concept of recursion, simple recursive functions ( e.g. factorial, GCD, binary
search, conversion of representations of numbers between different bas!
1 Topic- 1
-will notConcepts
*Note These are only for your reference. Questions from these
be asked in the Final Examination. Fundamentals of Java
parts
Page No. 88

Fundamentals of Java Topic-2


Concepts covered: Introduction to Methods, Recursion
Java; OOPs and its concepts; Tokens Page No. 106
TopiC-1 in Java; Datatypes in java ; Scope of Topic-3
identifiers; Wrapper classes; Type
Arrays Page No. 127
casting; Conditional Constructs;
Iterative constructs Topic-4
Strings Page No. 146
Topic-5
File Handling Page No. 157
Revision Notes Topic-6
Exception Handling & JVM
> Java is a high level programming language originally developed
Page No. 159
by Sun Micro systems and released in 1995. Java runs on several
platforms as windows, Unix and Mac OS.
Byte Code is independent of
the processer of a Computer
> oaa_ va Byte cod i

pndent ^
"Java Virtual Machine" converts
Objects
Byte code to Machine Language.
Features of Java (instance of a class )
Oriented

L
Pr° grammi
(blue print that describes the
behaviour or state of the object)

fPwoiffuunmmfy in Jana
(All related data and methods
( fundamentals ) ] enclosed within one boundary)

( reusability)
J
Variables Data Types Wrapper Classes
eg. al, $ price,
value, sum.

ett simple

eg. abstract, class,


for, try etc. eg. for 'byte' data
type there is 'Byte'
wrapper class.

“O

Scn
eg. class A
{ fun 0 2
{ int x; 1
} Java compiler automatically Z
} to change an entity of O
one datatype to another upgrades lower type to
class A
eg. arrays, eg. byte (1 byte)
by programmer.
higher type. z
classes,
{
static int X;
}
interfaces.
int (4 bytes)
eg - double d = 100.5;
long 1= (long)d;
Trace the Mind Map
1
First Level Second Level Third Level oo
vo

I
90 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class- XII
I
e of the method f 3
"

S
' 3
g--
If
X -
£ S
I s 3

s iV
5- 1
I g (
I u <
IT
§
£
1/
( method body)
S II
S'
.s
(Type, order, and «
number of parameters) 1
T3
3
.s is
(statements of body)
I

c S11 S S
§

.5 5 -g - 3 ~

C
Sg
A
-aii a -
9

i§ -g
i *i
me U U

o*
'

-
5* '
-
jeUcol sizel; imel 1 = new
•0 1
v es-
6> (i) int A [ ] = new int [10];
(ii) double B [ ] = {1.2, 3.5, 6.2, 1.8};
*

Storage of elements
3 int A [ ] = {5,12,8,17,10};
One dimensional in an array
%
%

Two dimensional
Jwxytamminp in Jauu int B [ ] = new int [5];
(i) int A [ ] = new int [5];
( Avuup ) A [0] = 6; A [1] = 8; (ii) scanner sc = new scanner (System.in );
System.out . println ("Enter 5 numbers");
for (int i = 0; i < 5; i+ + )
( A [i] = sc.nextlnt ();}

A[p] [q] ©Address at row p and col q.

B ©Base address
W®storage space in bytes

Li®Lower index of the Row


Ui®Upper index of the Row

Lc®Upper index of the col.


Uc®Upper index of the col.
Trace the Mind Map (p
-
tc®Total no. of col. (Uc Lc +1)
trUTotal no. of rows (Ur Lr +1) -
First Level Second Level Third Level I>
VO

I
92 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class-XII

ostructor of a base class


is

inherit
Uctor f a Base class
°
Objects of subclass can use
Base - abstract methods
Enormous situation
in program

try
(block of code to
monitor for errors. )

Catch
(It allows to define a block
of code to be executed,
eg. Missing semicolon, when an error occur in
missing brackets ( ) etc try block.)
u
~
Finally
(block of code to be executed s
after try and catch block ends. )
>
2
eg. if any body uses % 1
Z
for multiplication C\
eg. IO Exception
( Input Output Exception ) m [j Z
First Level Second Level Third Level
I
VO
«

I
94
>
Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Object Oriented Programming (OOP) is a programming paradigm which deals with the concepts of object to
I
create programme and software applications. The features of OOP are closely linked with the features of real -
world.

• Objects Objects have characteristics and behaviours. For example a student has states or characteristics:
:
name, age, group as well as behaviour such as student studies, plays, acts, etc.
;

• ofClassits type
: A class can be defined as a template or blueprint that describes the behaviour or state that the object
supports. An object is an instance of a class. A class is a way to bind the data and its associated
functions together.

• are
Methods Method basically is behaviour. A class contains many behaviour. It is in methods where the logics
:
written, data is manipulated and all actions are executed.

• already
Inheritance In Java, classes can be derived from classes. If you require to create a new class and here is
:
a class that has some of the code you need, then it is possible to derive your new class from the
already existing code. The feature is termed as inheritance. The existing class is called super class and the
derived class is called the subclass.

• Data Abstraction An act of representing main features without having the background details or internal
:
details. It deals with the outside view of an object as interface. For example, We all are performing several
operations on ATM machine like withdrawals, depositing, mini-statement, etc. but we can't know internal
details of ATM.

• achieved
Data Encapsulation Process of wrapping of data and methods in a single unit is called encapsulation. It is
:
by using class concept in Java. The isolation of the data from direct access by the program is called
'data hiding'.
• aPolymorphism A process of representing one entity in various forms is called 'Polymorphism'. For example,
:
single person acts like customer in the shopping mall, student in a school, a son at home, a passenger in a
-
bus/train. It means that one person in different different behaviours.
> Java Identifiers:
All components of a Java program require names. Names used for classes, variables and methods are called
identifiers. There are following points to remember for identifiers:

• All identifier should begin with a letter (A to Z or a to z), $ (dollar sign), ( ) underscore).

• A key word cannot be used as an identifier.


• Identifiers are case-sensitive.
• Legal identifiers: age, $ salary, value, l value.
• Illegal identifiers: 123abc, salary
> Java Keywords: The following lists show the reserved words in Java. These reserved words may not be used as
constant or variable or any other identifier names.
abstract private double synchronized new float
byte short final while public implements
class switch goto catch strictly interface
do throws instance of continue this package
extends volatile native else try return

for assert protected finally char super


import case static if default throw
long const transient int enum void

> Constructors: A constructor is the member function of a class that is used to initialize the data members when an
object of that class is created. The java compiler builds a default constructor for each class. Each time a new object
is created, at least one constructor will be invoked. The main rule of constructors is that they have the same name
as the class. A class can have more than one constructor.
I Example:
PROGRAMMING IN JAVA 95

Public class student

Public student ( )

}
Public student (string name)

//This constructor has one parameter

> Data Types:


Data types specify the different sizes and values that can be stored in the variable. There are two data types
available in Java:
• Primitive Data Types
• Reference ( Non-primitive) Data Types
> Primitive Data Types:
Primitive data Types are defined by the language and named by a keyword. There are eight primitive data types
supported by Java.
Data Type Size Range Default Value
Byte 1 byte - 128 to + 127 0
short 2 bytes 32768 to + 32767 0
int 4 bytes - 231 to + (231 - 1) 0
Long 8 bytes - 263 to + (263 -1) OL
Float 4 bytes 1.4e - 0.45 to 3.4e + 0.38 0.0F
double 8 bytes 4.9 e - 324 to 1.8e + 308 O.Od
Boolean 1 bit True/False False
Char 2 bytes 0 to 65535 can store any character
> Non Primitive Data Types:
It is a variable that can contain the reference or an address of dynamically created object. The non-primitive data
types are arrays, class and interfaces.
> Java Literals: A Literal is a source code representation of a fixed value. They are represented directly in the code
without any computation. Literals can be assigned to any primitive type variable.
Example: byte a = 23;
Char P = 'S';
> Variables: A Variable provides us with named storage that our programs can manipulate. It is also termed as
identifier that holds values, used in Java program. Example, Sum, Total marks, average etc. It may consist of
_
alphabet, digit, special symbols like ( ), $.etc.
data type variable [ = value] [, variable [ = value] ];
Example: int a, b, c //declares three integers a, b and c.
int a = 10, b = 10; // Example of initialization.
byte A = 25; // Initializes a byte type variable A.
double Pi = 3.14159 ; // declares and assigns a value of PI.
There are three types of variables used in Java
(i) Local Variables: These are declared in methods, constructors or blocks. These are implemented at stack level
internally. There is no default value for local variable, that's why when local variable is declared, an initial
value should be assigned to it before the first use. These have scope only within the block in which they are
declared.
Syntax: < Variable Name >
Example: Age //defined inside student Age () method
96 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
(ii) Instance variables: These are declared in a class, but outside a method, constructor or any block. Every object
created from a class definition would have its own copy of variable. These are non-static variables.
Syntax: Object Reference. < Variable name >
(iii) Class Variables: These are static variables declared with the static keyword in a class, but outside a method,
constructor. It can be accessed by calling with class name.
Syntax: Class Name. Variable Name
> Public members are the members that can be directly accessed by any function.
> Private members are the class members that are hidden from the outside world. They can be used only by
member functions (and friends) of the class in which it is declared.
> Protected members are the members that can be used only by member functions, friend functions and sub class
functions.
> A constructor is a member function of a class that is automatically called when an object is created of that class.
It has the same name as that of the class's name and its primary job is to initialize the object to a legal value.
> Default constructor is a constructor that accepts no parameter. If a class has no explicit constructor defined, the
compiler will supply a default constructor.
> Parameterized constructors can accept parameters.
> Copy constructor takes one argument, also called one argument constructor. The main use of copy constructor is
to initialize the objects while in creation, also used to copy an object. The copy constructor allows the programmer
to create a new object from an existing one by initialization.
> Wrapper Classes in Java:
For each fundamental data type there exist a pre-defined class, such predefined class is called 'wrapper class'. The
purpose of wrapper class is to convert a value of primitive type in an object.
Example: String s = "10.6f "
float x = Float.parseFloat (S) ;
Object of wrapper wrapper method
class Float class name
System.out.prinln (x); //10.6
There are two uses of wrapper classes:
• To convert simple data types into objects.
• To convert strings into numbers and then to other primitive type.
Conversion method from numeric
Fundamental Data type Wrapper Class Name
string to numeric value
byte Byte static byte
parseByte (String)
short Short Static short
parseShort (String)
int Integer Static integer
parselnt (String)
long Long Static Long
parseLong (String)
double Double Static double
parseDouble (String)
float Float Static Float
parseFloat (String)
char Character charValue()
Boolean Boolean static Boolean
parseBoolean (String)
> Type Casting:
Assigning a value of one type to a variable of another type is called 'type casting'.
These are two type of type casting as follows:
(i) Implicit Type casting: Lower size data type is assigned to higher size data type. Java compiler upgrades lower
type to higher type and it is termed as implicit type casting.
I PROGRAMMING IN JAVA
(ii) Explicit Type casting: Higher size date type cannot be assigned to a data type of lower size implicitly.
97

Control Structure Syntax


If-else statement if (condition 1){
action 1;
if else statement tests the result of a }else if (condition 2){
condition, and perform appropriate action 2;
action based on result. }else{
action 3;
}
where condition is Boolean expression, it returns True or False
value;
Switch-case Switch(expression){
case 1:
It can be used as an alternative for if - action 1 statement ;
else condition. If the programmer has break;
to make number of decision, and all case 2:
the decisions depend on the value of action 2 statement;
variable, then switch case is used instead
break;
of if else condition.

case N:
action N statement;
break; default;
default statement;
}
Where expression: is variable containing the value to be
evaluated . It must be of type byte, short, int, char,
default: is an optional keyword used to specify the statements to
be executed only when all the case statements evaluate to false .
while loop executes till condition is Syntax of while loop:
specified . It executes the steps mentioned While (condition){
in the loop only if the condition is true. action statements:
This is useful where programmer doesn't
know in advance that how many times
the loop will be executed.
}
Where condition: is any Boolean expression that returns a true or
false value. The loop continues upto condition returns true value.
Do-while loop do
!
The do-while loops execute certain action statements;
statements till the specified condition }while(condition){
is true. This loop ensures that the loop action statements;
body is executed atleast once.

}
For loop for(initialization statements; condition; increment/decrement
All loops have some common feature; statement){
a counter variable that is initialized action statements;
before the loop begins. The for loop
provides the feature that, initialized the
variable before loop begins, a condition }
for counter variable and counter upto where initialization statements: sets or initialize the value for
which loop lasts. counter variable.
condition: A Boolean expression that returns true or false value.
The loop terminates if false value is returned.
98 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Increment/decrement statements: Modifies the counter variable.


I
This statements are always executed after the action statements,
and before the subsequent condition check.
Break statement break;
The break statements are used to,
Terminate a statement sequence in a
switch statement
Exit a loop
Continue statement continue;
continue is used to skip the remaining
statements of the current iteration and
start the next iteration.

|Key Terms
> Objects: Objects contains several states and behaviours.
> Class: A template or blueprint that describes the behaviour as state that the object of its types supports.
> Data Abstraction: It is the process that involves identifying the essential features without including the internal
details.
> Data Encapsulation: A mechanism to bind the code and data together for manipulation is called data manipulation.
> Inheritance: It is the process by which one object acquires the properties of another objects. It can provide the
idea of reusability, drive a new class from the existing code. It means that a process in which a class is derived
from the base class is called inheritance.
> Polymorphism: An ability to take one operation and acts with different behaviour according to situation, is
known as polymorphism.
• The scope of a variable is the part of the program over which the variable name can be referenced.

>
• Assigning a value of one type to a variable to another type is called type casting.
Default constructor: It is automatically created by complier in the absence of explicit constructor.
> Parameterized constructor: These constructors are needed to pass parameters on creation of objects.
> Constructors with default arguments: It is required to define constructors with default arguments.
> Autoboxing: It is the automatic conversion that the Java compiler makes between the primitive types and their
corresponding object wrapper class
> Unboxing: a reverse process of autoboxing is known as unboxing.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


Q.l. What is the output of the code given below? Q. 2. The following is an if-else code.
void main () if (x!=y)
{ int s= l ,c; P = x +y ;
for (int i= l ;i< =3;i++) else
{ c=i; P=12 ;
while (c! =0) What is the representation of the above code in
s=s*c-; ternary form? [ISC Sem-1 Paper 2021-22]
(A) P = (x!= y)? x + y, 12;
(B ) P = (x!= y)? P = x + y; P =12;
System.out.println(s); (C) P = (x!= y)? x + y : 12;
} [ISC Sem-1 Paper 2021-22] (D) P = (x!= y) x + y, 12;
(A) 18 (B ) 12 Ans. Option (C) is correct
(C) 36 (D ) 4 Explanation: In ternary operator ? (question mark)
Ans. Option (B ) is correct and : (colon) will be used not the , (comma).
Explanation: Value of S will b e l x 2 x l x 3 x 2 x l
which is equal to 12
I
Q. 3. With reference to the following program code, Ans. Option (D) is correct.
PROGRAMMING IN JAVA 99

answer the question that follow: Explanation: In this code after case 1 there is break
void trick (int a , int b) statement, which occurs fall through in switch
{ int p=l; case. To avoid fall through we must add break
for (int j=l; j< =b;j++ , p*=a) ; statement at the end of every case statement.

System.out.println(p) ; Q. 5. With reference to the following program code,


answer the questions that follow:

(i) What will be the output of the method trick() void play (int n)
when the values of a = 3 and b = 4? { int s=0;
- -
[ISC Sem 1 Paper 2021 22]
while (n!=0)
(A) 12 (B) 127
(C) 81 (D) 64 { s=s*10+n- (n/10)*10;
.
Ans Option ( C) is correct. n/=10;
Explanation: Here loop will execute 4 times and 3 }
will be multiply with p which is initially 1, 4 times.
Output will b e 3 x 3 x 3 x 3 = 8 1 System.out. println(s) ;
(ii) What is the method trick() computing?
-
[ISC Sem 1 Paper 2021 22]- (i) What will be the output of the method play()
(A) Factorial of a number when the value of n = 6957?
(B ) Product of the number -
[ISC Sem 1 Paper 2021 22] -
(C) Power of a number raised to a number (A) 27 (B) 695
(D) HCF of the two numbers
(C) 5679 (D ) 7596
.
Ans Option (C) is correct.
Ans. Option (D ) is correct.
Explanation: It will produce 34, i.e. 81.
Explanation: Here while will execute and print the
..
Q 4 With reference to the following program code,
passed digit in reverse order.
answer the questions that follow:
.
void funny (int p int m , int n) (ii) What is the method play() performing?
-
[ISC Sem 1 Paper 2021 22] -
{ for(int i=p;i<=p;i++)
(A) Arranging the digits in ascending order
{ switch (i) (B) Reversing the number
{ case 1: m+=10; (C) Extracting the first 3 digits
case 2: n-=l; break; (D) Sum of the digits
case 3: m+=n;n+=3;break; Ans. Option (B) is correct.
default: m+=2; Explanation: It will produce the reversing the
number.
System ,out.println(m+ ” ; ”+n) ; Q. 6. What is the output of the code given below?
void main ()
} { int a , b, c ;
(i) What will be the output of the method funny()
for ( a =150 , b = 65 , c = 0 ; a % b ! = 0 ; c = a % b , a = b ,
when the values of p = l,m = 12 and n = 6?
[ISC Sem-1 Paper 2021-22] b=c) ;
(A) 20:4 (B ) 22:5 System.out.print(b+ ””) ;
(C) Error (D) 24:7 [ISC Sem-1 Paper 2021-22]
Ans. Option (B ) is correct. (A) 0 (B ) 65
Explanation: Case 1 will execute which increase (C) 5 (D) Error
the value of m by 10 after that control moves to
case 2 and reduce the value of n by 1. So output Ans. Option (C) is correct.
will be 22:5 Explanation: Loop will continue till a % b not equals
(ii) What is the keyword used in Java to avoid a fall to 0. In first iteration c = 20, a = 65, b = 20. In second
through condition? [ISC Sem-1 Paper 2021-22] iteration c = 5 a = 20 and b = 5. Here a is divisible by
(A) case (B ) continue b, so loop will stop and it will produce the output
(C) switch (D) break 5, as the value of b.
100 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 7. Java complier makes automaticconversion between Q. 13. Consider the following lines of code and find the
I
the primitive type and their corresponding object error if any:
wrapper class. This is called: import java.util .*;
(A) Implicit type casting
class xyz
(B) Coercion
(C) Explicit type casting
(D) Autoboxing public static void main (Strings [] args)
Ans. Option (D) is correct
Q. 8. Data items that have fixed data values are: Scanner sc=new Scanner(System.in) ;
(A) Static (B) Literals int a , b, res=0 ;
C
( ) Identifiers (D) None of these char OP;
Ans. Option (B) is correct
System.out.println("Enter first
-
Q 9 ... complies the Java source code program number") ;
file(.java files) into byte code.
a=sc.nextlnt () ;
(A) JVM compiler
System.out.println("Enter second
(B) java interpreter program
number") ;
(C) Virtual machine
(D) None of these. b=sc.nextlnt () ;
Ans. Option (A ) is correct System.out.println("Enter an
operator") ;
Q. 10. is a machine instruction for a Java
processor chip called JVM. OP=sc.next ().charAt (0) ;
(A) Java source code (B) Java program switch (ch)
(C) Java Byte code (D) All of these
Ans. Option (C) is correct caseV :
Q. 11. A Java class that has the same name as that of the res =a +b;
Java program is called break;
(A) main class (B) first class
default:
(C) initial class (D) None of these
Ans. Option (C) is correct System.out.println("Invalid
operator") ;
Q. 12. Consider the following lines of code and select
the most appropriate output
case'-':
res =a-b;
class ABC
break;
{
public static void main (String [] args)
}
{
int x=5;
(A) case for ' / &'% ' operators are missing.
if (x== 5); ( B) Data types of a &b variables should be double.
System.out.println("Welcome'') ; (C) default is placed at wrong position.
else (D ) No error in this code.
Ans. Option (D) is correct
System.out.println("Oops! Sorry");
Q. 14. Which of the following constructs can not be
nested in Java?
(A) if (B) switch
(A) Welcome (C) do...while (D) All can be nested
(B) Oops! Sorry Ans. Option (D) is correct
(C) Welcome Q. 15. The two jump statements in Java are:
Oops! Sorry (A) switch & break (B) break & jump
(D) Nothing will be printed on screen. (C) break & continue (D) for & continue
Ans. Option (D) is correct Ans. Option (C) is correct
I
Q. 16. The of an identifier is the part of the
PROGRAMMING IN JAVA 101
Q. 20. The methods and variables defined within a class
program in which the identifier is accessible. are called
(A) level (B) class (A) objects of a class
(C) scope (D) method (B) statements of class
(C) operations of class
Ans. Option (C) is correct.
(D) members of class
Q. 17. Which of the following is a symbol that takes Ans. Option (D) is correct.
one or more arguments and operates on them to Explanation: Methods are declared inside the body
produce a result? of the class but immediately after the declaration
(A) Operator (B) Literal of instance variables. Collectively, the methods are
(C) Identifies (D) Comment variables defined within a class are called members
of a class.
Ans. Option (A ) is correct.
Explanation: An operator is a symbol that takes Q. 21. Which type of access specifier is not accessible
one ore more arguments and operates on them to within the subclass inside the same package ?
(A) Private (B) Protected
produce a result. It performs an action on one or
(C) Public (D) Default
more operands. Operator are following types as
Ans. Option (A) is correct.
• Unary operators
• Ternaryoperators
Binary Explanation: Private access specifier denotes a
variable or method as being private to the class
• operator
and may not be accessed outside the class. It is
Q. 18. Identify the correct syntax for instance variable not accessible within the subclass inside the same
from the following options. package.
(A) Variable Name Q. 22. Evaluate the following Java expression, if x = 2, y
(B ) Class Name. Variable Name = 6, and z = 18.
(C) Object Reference. Variable Name ++ z + y-y + z + x ++
(D) None of these Choose the correct answer from the following
Ans. Option (C) is correct. (A) 38 (B) 39
Explanation: Non-static variables are called (C) 35 (D ) 40
instance variables. Instance variables are used to Ans. Option (D ) is correct.
store the state of an object. Every object created Explanation: In the above expression, ++ z means
from a class definition would have its own copy that the value will first increment by 1, i.e., 19.
of variable. Now, evaluate the statement by putting the values
of x, y and z. On evaluating the expression, we get
Syntax Object Reference. Variable Name 40, as shown below.
Q. 19. Choose the correct output for the following code ++ z + y-y-z + x ++
int a = 7, b = 5: 19 + 6 - 6 + 19 + 2 = 40
if (a < b) Q. 23. What will be the output of the following program?
public class Test
System.out.print ("a is small") ;
public static void main (String [ ] args)

else
int count = 1;
while (count<=13)
System.out.print fb is small'') ; {
System.out.println (count % 2 == 1?
(A) a is small (B) b is small "$ $ $": "****") ;
(C) Either a or b (D) None of these ++count ;
Ans. Option (B) is correct. }
Explanation: The if-else statement can be used to }
route program execution through two different
paths. In above code, there is condition (a < b)
(A) 13 times $$$
which is false according the values given, so else
( B) 13 times ****
part will be executed. The output will come "b is (C) 7 times $$$ and 6 times ****
small". (D) Both will print only once
102 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Ans. Option (C) is correct Q. 27. What will be the output of the following
I
Java
Explanation: In the above code, we have declared program ?
count =1. The value of count will be increased till class Test
12, because of the while (count < =13) statement. If
the remainder is equal to 1 on dividing the count
by 2, it will print ($$$) else print (****). Therefore, public static void main (String args [ ])
for all odd number till 13 (1, 3, 5, 7, 9, 11, 13), it will
print ($$$) and for all even numbers till 12 (2, 4, 6,
8, 10, 12) it will print (****). int a = 2;
Hence, dollar ($$$) will be printed 7 times and int b = 3;
asterisk (****) will be printed 6 times. if ((b = 1) == a)
Q. 24. Which of the following is not a valid jump System.out.print (b) ;
statement?
(A) break (B ) goto else
(C) continue (D) return System.out.print (++b) ;
Ans. Option (B ) is correct
Explanation: Jump statements are used do
unconditionally transfer program control from
(A ) 1 (B ) 2
one point to else where in the program. Jump
statements are primarily used to interrupt loop (C) 3 (D) 4
or switch case instantly. Java supports three jump Ans. Option (B ) is correct
statements: break, continue and return. Explanation: b is initialised to 1. The conditional
Q. 25. What will be the output of the following Java statement returns false and the else part gets
program? executed.
class Test Q. 28. What will be the output of the following Java
{ program ?
public static void main (String args [ ]) class Test
{
int a =5; public static void main (String args [ ])
System.out.print (++a * 9) ; {
int total=0;
} for (int i=0, j=0; i < 6 & j < 6; ++ j, j=i+l)
(A) 54 (B ) 45
total + =i;
(C) 48 (D) 59
Ans. Option (A ) is correct
System.out.println (total) ;
Explanation: Operator + + has more preference }
than *. thus a becomes 6 and when multiplied by }
9 gives 54. (A ) 6 (B ) 10
Q. 26. With a = 1, which of the following are legal lines (C) 15 (D) Compilation error
of Java code for changing the value of a to 2? Ans. Option (C) is correct
a + +; Explanation: Using comma operator, we can include
a = a + 1; more than one statement in the initialization and
a + = 1; iteration portion of the for loop. Therefore both
a = + 1;
+ + i and j = i + l is executed (gets the value - 0, 1, 2,
3, 4, 5 & j gets the values - 0, 1, 2, 3, 4, 5, 6.
(A) 1, 2, 3 (B ) 1, 4
(C) 1, 2, 3, 4 (D) 2, 3, 4, 5 So, the output is 0 + l + 2 + 3 + 4 + 5 = 15
Ans. Option (A ) is correct Q. 29. What will be the output of the following Java
Explanation: Operator + + increases value of code?
variable by 1. class Test
a = a + 1 can also be written in shorthand form as
a + = 1. Also a = + 1 will set the value of a to 1.
public static void main (String args [ ])
I PROGRAMMING IN JAVA 103
Q. 31. Which of the following is/aretype(s) of constructor?
(A) Default constructor
int a =5;
(B ) Parameterized constructor
System.out.println (++a*2 +" " +a) ; (C) Constructor with default arguments
(D) All of these
Ans. Option (D) is correct.
}
Explanation: Constructor has the same name as the
(A) 10 5 (B ) 10 6
name of the class to which it belongs. Constructor's
(C) 12 5 (D) 12 6 syntax does not include a return type, since
.
Ans Option (D) is correct . constructors never return a value. If may include
Explanation: Operator + + has higher precedence parameters of various types constructors have
different types as
than multiplication operation, *, a is incremented
to 6 than multiplied with 2 giving 12. •Default constructor

. .
Q 30 Which of the following is a combination of
•Parameterized constructor

operators and / or operands?


•Constructor with default arguments
Q. 32. Which of the following is a value that can be
(A) Expression (B) Keyword passed to a variable or constant is a program ?
(C) Class (D) Object (A) Identifier (B) Operator
.
Ans Option (A ) is correct. (C) Literal (D) Comment
Explanation: An expression is a combination of Ans. Option (C) is correct.
operators and / or operands. Java expressions Explanation: A literal is a value that can be passed
are used to create objects, arrays, pass values to to a variable or constant in a program. It can be nay
number, text or other information that represents
methods and call them, assigning value do variable
a value. Literals can be integer, floating point,
and so on. Boolean, character, string notations or null literals.

SUBJECTIVE TYPE QUESTIONS


else
Short Answer Type
<&\ Questions- I (2 marks) System.out.ptintlnfBye ” + count) ;
..
Q 1 Define the term fall through condition with test ( -- count) ;
reference to switch case. [ISC 2016] System.out.printlnf ” + count) ;
Ans. Fall Through: If a case does not end with a break }
statement, it will execute the following cases until }
and unless it counters a break statement. This Q. 3. The following function is a part of some class.
condition is called fall through condition. Assume n is a positive integer. Answer the given
[ISC Marking Scheme 2016] .
questions along with dry run/working [ISC 2013]

n w -
Examiner's Comment
This part was well answered by most of the
candidates. Some wrote vague definition of 'fall
through'. Others explained using examples.
int unknown (int n)

int i. k = 0
if (n % 2 ==0)
{
i = n/ 2 ;
Q. 2. The following is a function of some class. What k = 1;
will be the output of the function test ( ) When the
value of count is equal to 4? Show the dry run/ else
working.|| § [ISC Specimen Question Paper 2016]
void test (int count) k = n;
n- -;
if (count == 0)
i= n / 2 ;
System.out.printlnf ”) ;
}
|
|g These questions are for practice and their solutions are available at the end of the chapter
104 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
while (i > 0) Output
I
{
k = k * i * n;
Similarly, when n is odd
n- -; Output

return k; n( n - l )
}
(i) What will be returned by unknown (5) ? Q. 4. The following function is a part of some class
What will be returned by unknown (6) ? which computes and returns greatest common
(ii)
divisor of any two numbers. There are some place
(iii) What is being computed by unknown (int n)? in the co-marked ?l ?r 121, 131, ?4? and 151 which
Ans. (i) for n = 5 must be replaced by statement expression so that
if (5% 2 = = 0) (False) the function works correctly, [ISC 2011]
Then, int gcd (int a , int b)
k =5
int r;
n =4 while ( ?1?)
i = 4/2 = 2 {
Iteration 1. 2 > 0 (True) r = ? 2 ?;
k = 5 * 2 * 4 > 40 = b = ? 3? ;
So, i =1 a = ?4 P ;
n =3 if (a ==0)
Iteration 2.1 > 0 (True) return ? 5 ? ;
k = 40 x 1 x 3 else
= 120 return -1;
}
i =0 (i) What is the expression or statement at ?1?
n =2 (ii) What is the expression or statement at 121
Iteration 3. 0 > 0 (False)
(iii) What is the expression or statement at ?3?
Return k = 120 (iv) What is the expression or statement at ?4?
(ii) Similarly, as n is 6 which is even, so the (v ) What is the expression or statement at 151
condition under if will be executed, Ans. (i) a > 0
n = 6, i = 3, k = 1 (ii) b% a;
condition (i > 0) n i k (iii) a;
(iv) r;
True 5 2 18
(v ) b;
True 4 1 180
Q. 5. The following is a function of some class. It
True 3 0 720 returns 1 if the number is a perfect number
False otherwise it return 0. [ISC 2008]
720 will be returned /*A perfect number is a number which is
(iii ) When n is even equal to the sum of its factors other than the
number litself /
n i k int perfectNo (int n)
n n/2 1 {
int ?1? ;
” -l n2 for (int j = 1; ? 2 ? ; j++)
:—
(n - l ) !* *
: : {
if ( ? 3 ? )
(n - 2) —2 -2 sum ? 4 ? ;
if (?5?)
return 1;
(n - 3) else
-- 3 return 0;
:
tf j
- 2 * (» - 2) }
I (i) What is the expression/value of ?1?
PROGRAMMING IN JAVA
Q. 7. Give the output of the following program
105

(ii) What is the expression/value of ?2? segment. [ISC 2006]


(iii) What is the expression/value of ?3? int x = 0;
(iv) What is the expression/value of ?4? do
(v ) What is the expression/value of ?5?
Ans. (i) sum = 0;
if (x < 3)
(ii) j < n;
{
(iii) n % j = = 0;
x + = 2;
(iv) sum + = j;
(v ) sum = = n;
System.out.println(x) ;
continue;
Q. 6. State the final value of q at the end of the
following program segment. [ISC 2007]
int m , n , p, q = 0; else
for (m - 2; m <= 3; ++m)
System.out.println(++x) ;
for(n = 1; n <= m; ++n)
break ;
{
p = m + n - 1;
if (p%3 == 0) }
q += p; while(x < 10) ;
else Ans. Initially x = 0;
q += p + 4; Iteration 1: if (x < 3)
condition true,
then
Ans. The given program, iterates the values of m, n, p
and q as given in table;
x+ =2
x=x+2
m n p = m + n -1 if (p%3 = = 0 ) <7
x=0+2
for m 1 p = 2 + 1- 1 False, x =2
=2 =2 Print —» 2
q = q + p Iteration 2: while (x < 10)
+4 condition true,
=0+2+4
if (x < 3) condition true,
=6 q=6
then x+ =2
2 p = 2 + 2 -1 True,
x =2+2=4
=3
Print > 4
-
q=q+p
Iteration 3: while (x < 10) condition true if (x < 3)
=6+3=9 q=9
condition false,
form 1 p = 3 + 1-1 True,
=3 =3 then + +x = x + 1
q=q+p q= =4+1=5
= 9 + 3 = 1 2 12 Print 5
2 p = 3 + 2 - 1 False, Output = 245
=4 Long Answer Type
q = q + p
+4
Question -I (5 marks)
= 12 + 4 + 4 q = Q. 1. The following is a function of some class which
= 20 20
checks if a positive integer is an Armstrong
3 p = 3 + 3 -1 False, number by returning true or false. (A number is
=5 said to be Armstrong if the sum of the cubes of
q = q + p all its digits is equal to the original number.) The
+4 function does not use modulus ( %) operator to
= 20 + 5 + 4 q = extract digit. There are some places in the code
= 29 29 marked by ?1?, ?2?, ?3?, ?4?, ?5? which may be
Output = 29
106 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
replaced by a statement/ expression so that the else
I
function works properly. [ISC 2015] return false;
Boolean Armstrong Num (int N) (i) What is the statement or expression at ?1?
{ (ii) What is the statement or expression at ?2?
int sum = ?1? (iii) What is the statement or expression at ?3?
int num = N ; (iv) What is the statement or expression at ?4?
while (num > 0) (v) What is the statement or expression at ?5?
Ans. (i) 0
int f = num/10;
(ii) f *10;
int s = ? 2 ? ;
(iii) digit *digit*digit;
int digit = num - s ;
OR Math.pow(digit, 3));
sum + = ?3? ;
(iv) num/10; OR f;
num = ?4 ? ;
(v) sum = = N OR | N = = sum
if (?5?) [ISC Marking Scheme 2015]
return true ;

Methods and Recursion


Topic -2 Concepts covered: Methods; Need for methods; Call by value; Call by
reference; Recursion; Recursive functions

Revision Notes
> A function or method in Java contains the executable code.
> Need for methods
• Complex problem can be broken into smaller and more easily understandable tasks.
• Low level details about as to how a method is accomplishing a task are hidden from the users.
• Reusability of the code increases.
A function must be defined before it is used anywhere in the program.
> Syntax of a method:
Public static int method name (int a , int b)

//body
}
public Static - > modifier
int - > return type
methodName - > name of the method
a, b - > formal parameters
int a , int b - > list of parameters
> A method in Java has to be inside a class.
> The first line of the function definition that tells the program about the type of the value returned by the function
and the number and type of arguments.
> A function is called by providing the function name followed by the parameters enclosed in parentheses.
> A function can be invoked in two ways:
• Call by value: value of actual parameters are copied into the formal parameters.
• Call by reference: A reference of the actual parameters are passed to the formal parameters.
> A function terminates either when a return statement is encountered or the last statement of the function is
executed.
> main() method is the logical entry point of the program.
> A static method of a class can't access a non-static method or variable of its own class.
> Recursive function: A function definition that calls itself.
> A recursive function must have two cases
I• The recursive case
PROGRAMMING IN JAVA 107

>
• The base case
When many methods have the same name with different functionality it is called overloading.
> Table: Function and their description
Function Description
sin (x) Returns the sine of the angle x in radians
cos (x) Returns the cosine of the angle x in radians
tan (x) Returns the tangent of the angle x in radians
asin (y) Returns the angle whose sine is y
acos (y) Returns the angle whose cosine is y
atan (y) Returns the angle whose tangent is y
atan 2 (x, y) Returns the angle whose tangent is x/y
pow (x, y) Returns x raised to y (xy)
exp (x) Returns e raised to x (ex)
log (*) Returns the natural logarithm of x
ceil (x) Returns the square root of x
sqrt (x) Returns the square root of x
ceil (x) Returns smallest whole number greater than or equal to x
floor (x) Returns the largest whole number less than or equal to x
rint (x) Returns the truncated value of x
round (x) Returns the integer closest to the argument
abs (a ) Returns the absolute value of a
max (a, b) Returns the maximum of a and b
min (a, b) Returns the minimum of a and b

HH
>
Key Terms
Recursion is when a function calls itself . That is, in the course of the function definition there is a call to that very
same function.
> Method Overloading: When a class has two or more methods by the same name but different parameters

OBJECTIVE TYPE QUESTIONS (1 mark each)


..
Q 1 int Toy (int n ) Ans. Option ( B ) is correct.
return (n <=0) ? 1: n %10 + Toy (n /10) ; }
{ Explanation: This case is very important because
With reference to the program code given above,
upon reaching at base case, the termination of
recursive function occurs as base case does not
what will the function Toy () return when the
value of n = 56 ? [1]
invoke the function again, rather it returns a pre -
known result, in the absence of base case, the
(A) 65 (B ) 12 recursive function executes endlessly.
(C) 651 (D) 11
Q. 3. Recursive case is:
Ans. Option (B ) is correct.
(A) that calls itself
Explanation: Function Toy(56) will return
Toy(56) 11 56 < 0 false 11
— (B ) the case that invokes the function again
(C) when a recursive function calls itself endlessly
return(6 + Toy(5)) 1156%10 = 6 & 56/10 = 5 (D) None of these
5 < 0 = false 11 Ans. Option (B ) is correct.
return(6 +5 + Toy(0)) | | 5% 10 = 5 & 5/10 = 0 Explanation: Recursive case is the case that invokes
0 < = 0 True ||Toy(0) = 1 || return (6 + 5+1) the function again and again.
12 Q. 4. When a recursive function calls itself endlessly it
is called:
Q. 2. Preknown case of recursive function, whose
solution is pre-known. (A) Infinite recursion (B ) Iteration
(A) Recursion (B ) Base case (C) Base case (D) Recursive case
(C) Recursive case (D) Both (B) & (C) Ans. Option (A ) is correct.
108 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 5. Absence of base case: Ans. Option (C) is correct
I
(A) generates syntax error Q. 10. If the changes made insider functions do not
(B) is a logical error persist even after the function call it indicates:
(C) results in infinite recursion (A) Invalid function definition
(D) both (B) & (C) (B) Invalid function cell
Ans. Option (D) is correct (C) Invalid function parameter list
Q. 6. When changes made in formal parameters are (D) Function is called by value
reflected back in actual parameters then the Ans. Option (D) is correct
function call is: Q. 11. The functions that returns the value of a data
(A) by value member of the class is called:
(B) by reference (A) Accessor method
(C) invalid (B) Setter method
(D) None of these. (C) Mutator method
(D) Recursive method
Ans. Option (B) is correct
Ans. Option (A ) is correct
Explanation: It is an approach that passes a
Q. 12. Which keyword is used in a method to refer to the
reference (i.e., address) of the value to a method. object that invoked it, i.e., it refers to the current
This means when we call the method by passing object?
the copy of a reference (i.e. address) to the value (A) static (B) this
of that method & not a copy of value itself, then (C) goto (D) break
the calling method has a reference (i.e. address) of Ans. Option (B) is correct
that value. Explanation: 'this' keyword is used in a method to
Q. 7. Parameters specified in the definition of the refer to the object that invoked it, i.e., it refers to
method are called: current object. Whenever a reference to an object
(A) formal parameters of the current class type is required 'this' can be
used it can also differentiate between instance
(B) actual parameters
variables and local variables.
(C) arguments
Q. 13. Which of the following is a collection of
(D) All of these
statements that are grouped together to perform
Ans. Option (A) is correct an operation?
Q. 8. Function signature is: (A) Object
(A) function call (B) Method
(B) function definition (C) Class
(C) number and types of arguments (D) Inheritance
(D) function prototype Ans. Option (B) is correct
Ans. Option (C) is correct Explanation: A method is a collection of statements
that are grouped together to perform an operation.
Q. 9. Which of the following data types can be passed Methods are declared inside the body of the class
as reference? but immediately after the declaration of instance
(A) Integer (B) All primitive data types variables. Collectively, the methods and variables
(C) String (D) None of these defined within a class are called members of a
class.

yf SUBJECTIVE TYPE QUESTIONS


Very Short Answer Type Answer Type
Questions I - (1 marks)
<®> \ Short
Questions-I (2 marks)
Q. 1. Give one reason, why iteration is better than Q. 1. State one advantage and one disadvantage of
recursion. using recursion over iteration. [ISC 2016]
Ans. Because recursive algorithms have an overhead for Ans. Advantage: Recursion makes the complex
procedure calls and iterative algorithms don't have programs simpler and easy to understand by
that overhead. making the code reduced than Iteration.
I Disadvantage: Recursion occupies more memory
PROGRAMMING IN JAVA 109
finite recursion, i.e., Controlled recursion is called
and is a slow process than iteration. finite recursion.
[ISC Marking Scheme, 2016] Infinite Recursion When recursive procedure
does not contain any valid test case to terminate
recursion then it is called infinite recursion, i.e.,
Examiner's Comment uncontrolled recursion is called infinite recursion.
Q . 5 . Mention two points which distinguish a static
w Various answers were given by the candidates data member from an ordinary data member in a
for this part of the question. A few candidates class. [ISC 2008]
explained with the help of examples. Some wrote Ans. The difference between static and ordinary data
definitions of both, without mentioning the member:
advantages and disadvantages, as required.
Static Data Member Ordinary Data Member
It can be accessed in all It can be accessed in non-
Answering Tip the methods of a class. static method of a class.
A single copy of static For each object in a
w The difference between recursion and iteration data is maintained for class a separate copy is
must be explained; more practice must be given all objects. maintain .
in solving programs by both methods. This will
Q. 6. Why recursive functions result into slower
enable students to understand the concept of
execution of the program? [ISC 2005]
recursion as compared to iteration.
Ans. Recursive procedure internally uses stack data
structure for maintaining the correct sequence of
Q . 2. State difference between iteration and recursion. method calls. For putting data into stack and take
[ISC 2013] it out from there, addition functions need to be
Ans. Difference between recursion and iteration: executed and because of this addition overhead
of executing extra functions, the execution time of
Recursion Iteration recursive procedure increases.
Recursive function Iterative instructions Q. 7. Differentiate between a constructor and a method
is a function that is are loop based of a class. [ISC 2017]
partially defined by repetitions of a
Ans . Constructor Method
itself . process.
Constructor is used to Method is used to
Recursion uses Iteration uses initialize the state of an expose behaviour of an
selection structure. repetition structure. object. object.
Infinite recursion An infinite loop occurs Constructor must not Method must have
occurs if the recursion with iteration if the have return type. return type.
step does not reduce loop condition test
the problem in a never become false.
Constructor is invoked Method is invoked
manner that it reaches implicitly. explicitly.
the base case. The java compiler Method is not provided
provides a default by compiler in any case.
Recursion terminates Iteration terminates
when a base case is when the loop- constructor if you don't
recognized. condition fails. have any constructor.

Recursion is usually Iteration does not use


Constructor name must Method name may or
slower than iteration stack so it is faster than be same as the class may not be same as class
due to overhead of recursion. name. name.
maintaining stack.
Q . 3. State any two disadvantages of recursion. Long Answer Type
<§) [ISC 2011]
Questions -I (5 marks)
Q . 4. Differentiate between infinite and a finite Q . 1. The following function check( ) is a part of some
recursion. [ISC 2010] class. What will the function check( ) return when
Ans. Finite Recursion When recursive procedure the value of (i ) n = 25 and ( ii) n = 10. Show the dry
contains a valid test case, so that recursion can run/ working.
terminate after finite number of steps is called
These questions are for practice and their solutions are available at the end of the chapter
110 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
int check (int n) ..
I
Q 3 A class Gcd has been defined to find the Greatest
{ if (n <= l) Common Divisor of two integer numbers Some .
of the members of the class are given below:
return 1; Class name : Gcd
if ( n % 2==0) Data member/instance variable:
return 1 + check (n/ 2) ; numl : integer to store the first
number
else
num2 : integer to store the second
return 1 + check (n/ 2 + 1) ; number
} Member functions/methods:
.
Ans (i) check( 25 ) Gcd( ) : default constructor
1+ check(12 + l) void accept( ) : to accept the numbers
1+ check(6 + l ) int gcd(int x,int y) : return the GCD of the
1+ check(3+ l ) two number x and y using
1+ check(2) recursive technique
1+ check(2) void display( ) : displays the result with an
appropriate message
1
Specify the class Gcd, giving details of the
(ii) check( lO )
Constructor, void accept( ), int gcd(int,int), and
1+ check( 5 ) void display( ). Define the main () function to
1+ check(2 + l ) create an object and call the functions accordingly
1+ check(l + l ) to enable the task. - -
[ISC Sem 2 Paper 2021 22]
1+ check(l) Ans. import java.io. ;
*

1 import java.util .*;


Final output: public class Gcd
(i) l + l + l + l + l + l = 6
(ii) l + l + l + l + l = 5 int numl ,num 2 ,gcd ;
..
Q 2 A class Fibo has been defined to generate the
GcdQ
Fibonacci series 0,1,1, 2, 3, 5, 8, 13, (Fibonacci
series are those in which the sum of the previous numl =0;
two terms is equal to the next term) . num 2 =0;
Some of the members of the class are given below: gcd =0;
Class name : Fibo
Data member/instance variable: void acceptQ
start : integer to store the start value
Scanner sc=new Scanner(System.in) ;
end : integer to store the end value
System.out.println(“ Enter first
Member functions/methods:
number ” ) ;
Fibo( ) : default constructor numl =sc.nextlnt ();
void read( ) : to accept the numbers System.out.println(“ Enter second
int fibo(int n) : return the nth term of number ” ) ;
a Fibonacci series using num 2 =sc.nextlnt ();
recursive technique
void display( ) : displays the Fibonacci series int gcd (int a , int b)
from start to end by invoking {
the function fibo()
while (b != 0)
Specify the class Fibo, giving details of the
Constructor, void read( ), int fibo(int), and void
if (a > b)
.
display( ) Define the main() function to create
an object and call the functions accordingly to
enable the task . a = a - b;
}
else
{
|f|) These questions are for practice and their solutions are available at the end of the chapter
I b = b - a;
PROGRAMMING IN JAVA
return (Magicfun (l)’10+0)
111

I
} return (Magicfun (0)’10+ l)
return a ; I
return (0)
void displayO Output -+ 0 * 10 + 1 = 1
1 MO + 0 = 10
gcd = gcd (numl , num 2) ;
10 MO + 1 = 101
System.out.println(“ Gcd of “ + numl
101 * 10 + 0 = 1010
+ “ and “ + num 2 + “ = “ + gcd) ;
Q. 5. The following function Check( ) is a part of some
public static void main (String[] args) class. What will the function Check( ) return
when the values of both 'm' and 'n' are equal to
{
5 ? Show the dry run/working , [ISC 2016]
Gcd ob=new Gcd () ;
ob.accept() ; int Check ( int m, int n)
ob.displayQ ; {
if (n = = 1)
} return - m -
Q. 4. The following function magicfun( ) is a part of else
some class. What will the function magicfun( )
return + + m + Check (m, - -n);
return, when the value of n = 7 and n = 10,
respectively? Show the dry run/working: Ans . Output: Check (5, 5)
[ISC 2017] 6 + Check (6, 4)
int magicfun (int n) 7 + Check (7, 3)
{ if ( n==0) 8 + Check (8, 2)
return 0; 9 + Check (9, 1)
Hence the output = - 9 + 9 + 8 + 7 + 6 = 21
else
[ISC Marking Scheme, 2016]
return magicfun (n/2) , *10 + (n % 2);

Ans. 7 = > 111 Examiner's Comments


10 = > 1010
w A number of candidates were able to answer this
Binary equivalent of N question satisfactorily. Common errors made by
Working: candidates were:
Magicfun (7) w Lack of clarity regarding the concept of recursion;
A
w Confusion with the postfix decrement operator in
retum (Magicfun)(3) *10+1)
A
the return statement of the base case (-m ) and
calculating the output as 22 instead of 21.

retum (Magicfun (l)*10+l) w Showing the intermediate outputs in memory
I blocks, without stating the final output.
return (Magicfun (0)’10+ l) w Mentioning the correct output without showing
I the dry-run as required.
retum (O)
Output -+ 0 * 10 + 1 = 1
1 * 10 + 0 = 11 Answering Tips
11 * 10 + 1 = 111
Magicfun (10) w Students must practice on solving programs using
recursive techniques. They must have sufficient
I knowledge about base case and recursive case in
return (Magicfun)(5) *10+0) recursive programs.
I w Students should learn how to create recursive
return (Magicfun (2)’10+ l) code for most iteration cases.
I
112 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 6. The following function is a part of some class.
I
Assume 'x' and 'y' are positive integers, greater Examiner's Comment
than 0. Answer the given questions along with
dry run/working. [ISC 2015] w Some candidates used examples to illustrate the
void someFun (int x, int y) answer. A number of candidates found it difficult
to provide an appropriate definition. A few
if (x > 1) candidates wrote 'k' instead of 'n' for complexity.
{ if (x%y=0)
{ System.out.print(y+“ ”) ;
someFun (x/y, y) ; Answering Tip
else w Students should show the working and explain
someFun (x , y+1) ;
with memory blocks. More practice must be done
in Recursive techniques.
}
(i) What will be returned bysomeFun(24, 2)?
Q. 7. The following function Recur( ) is a part of some
(ii) What will be returned bysomeFun(84, 2)? class. What will be the output of the function
(iii ) State in one line what does the function some Recur( ) when the value of n is equal to 10? Show
funQ do, apart from recursion? the dry run/ working. [ISC 2013]
void Recur (int n)
Ans. (i) someFun (24, 2)
24 >1 true 24% 2 = = 0 true output 2 if (n > 1)
someFun(24/2, 2) {
12 > ltrue 12% 2 = = 0 true output 2 System.out.println(n + “ ”) ;
someFun(12/2, 2) If (n %2! = 0)
6 >1 true 6 % 2 = = 0 true output 2 {
someFun(6/2, 2) n = 3 * n + 1;
3>1 true 3% 2 = = 0 falsecall someFun (3, 3) System.out.println(n + “ ”) ;
someFun(3, 3)
Recur (n/ 2) ;
3>1 true 3% 3= = 0 true output 3 }
someFun(3/3, 3) 1>1 false }
Output: 2 2 2 3 Ans. Iteration 1.10 > 1 (True)
(ii) someFrm (84, 2) Print '10'
84 > 1 true 84% 2 = = 0 true output 2 Output will be 10
someFun(84/2, 2) if (10%2 g 0) (False)
Recur (10/2) = Recur(5) Recur ( lO)
42 > 1 true 42 % 2 = = 0 true output 2
someFun (42/2, 2) Iteration 2. 5 > 1 (True)
Print '5'
21 > 1 true 21%2= = 0 false call someFun (21, 3)
Output will be 10 5
someFun (21, 3)
if (5% 2 g 0) (True) Recur (5)
21 > 1 true 21 % 3= = 0 true output 3
someFun (21/3, 3) n = 3 * 5 + 1; Recur ( lO )
7> ltrue 7%3= =0 false call someFun (7, 4) n = 16
someFrm (7, 4) Print '16'
7>1 true 7% 4 = = 0 falsecall someFun (7, 5) Output will be, 10 5 16
someFun(7, 5) Now, n = 16
7>1 true 7%5= = 0 false call someFun (7, 6) Recur (n/2) = Recur (8)
someFun(7, 6)
7> true 7% 6 = = 0 false call someFun (7, 7)
someFun(7, 7) Iteration 3. 8 > 1 (True)
7> 1 true 7% 7 = = 0 true output 7 Print '8'
someFun (7/7, 7)1>1 false Recur (8)
OUTPUT: 2 2 3 7 Output will be, 10 5 16 8
if (8% 2 g 0 ) (False) Recur ( 5)
(iii) Generating Prime Factors.
Now, Recur (8/2) Recur ( lO)
[ISC Marking Scheme, 2016]
= Recur(4)
I Iteration 4. 4 > 1 (True)
PROGRAMMING IN JAVA 113
Recursion will stop at this point and frames from
Print '4' stack will be popped out in LIFO sequence, i.e.,
Recur(4) mymethod(l ) frame will be popped out first and
Output will be, Recur(8) will complete its execution by printing 0, then
10 5 16 8 4 Recur(5) mymethod(2) will print 1 and mymethod(3) will
if (4% 2 g 0) (False) Recur(lO) print 2.
Recur (4/2) = Recur (2) Output is
Hello 3
Iteration 5. 2 > 1 (True) Hello 2
Print '2'
Recur(2)
Hello 1
Recur(4)
Output will be, 0
Recur(8)
10 5 16 8 4 2 1
Recur(5)
if (2%2 g 0) (False) Recur(lO) 2
Now, Q. 9. The following functions numbers(int) and
Recur(2/2) = Recur(l) .
numbersl (int) are a part of some class Answer
Iteration 6. 1 > 1 (False) the questions given below showing the dry run/
So, final output will be, working. 0
[ISC 2010]
10 5 16 8 4 2 public void number (int n)
.
Q. 8 The following is a part of some class. What will
be the output of function mymethod ( ) when
if (n > 0)
the value of counter is equal to 3? Show the run/
working. [ISC 2011]
void mymethod (int counter) System.out.println(n+ “ ”):
{ number(n - 2) ;
if (counter == 0) System.out.println (n+ “ ”) ;
System.out.printlnf ”) ;
else
}
System ,out.prin tin (“ Hello + counter) ;
® public String numbersl (int n)

mymethod ( counter) ;
system.out.printlnf ” +counter) ; if (n <= 0)

} return “
Ans. mymethod (3)
}
print Hello 3
else

mymethod(3)
print(2)
return numbersl (n - 1) +n + “ ”;
}

mymethod (2)
print Hello 2 (i) What will be the output of the function
mymethod(2) numbers (int n) when n = 5?
print(l )
mymethod (3) (ii) What will be the function numberl (int n)
print(2) return when n = 6?
(iii) State in one line what is the function
mymethod(l)
print(O) numbersl (int) doing apart from recursion?
mymethod (1)
print Hello 1 mymethod(2) Q. 10. The following function trial( ) and perform( ) are
print(l ) a part of some class. Answer the following parts
mymethod (0) mymethod(3) given below. Show the dry run/ working.
if (count = = 0) true print(2)
[ISC 2009]

|
|g These questions are for practice and their solutions are available at the end of the chapter
114 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
int trial (int n) is greater than 1 when the function is invoked. It
I
returns the value 1 when true otherwise it return
0. Show the dry run/working. [ISC 2008]
if (n== l)
void calling (int j)
return 2 ;
else if (n == 2)
int f = 2;
return 3;
show (n , f ) ;
else
}
return trial (n - 2) + trial (n - 1) ;
int show (int n , int f )

void perform (int p)


if (n ==f )
return 1;
int x ;
if (n %f == 0 || n== l)
for (int i = 1; i < = p ; i++)
return 0;
{
else
x = trial (i) ;
return show (n , f + 1) ;
System.out.print In (x+ “ ”) ;
}
(i) What will the function show( ) return when
the value of n is 11?
(i) What will the function trial( ) return when (ii) What will the function show( ) return when
the value of n is 4? the value of n is 27?
(ii) What will be the output of the function (iii) In one line state what the function show (...)
perform( ) when the value of p is 5? is doing.
(iii) In one line state what the function trial( ) is Ans. (i) When the value of n = 11,
doing, apart from recursion? method show (11, 2) // function called
Ans. (i) When the value of n is 4 the trial function will
The change of values during execution is as
return 8.
follows:
trail (4)
Action Value of n Value of f
trial (4)
13 + 5 = 8 Function call 11 2
return (trial (2) + trial (3)) After 1st call 11 3
I i2 + 3 = 5 After 2nd call 11 4
return (3) return (trial (1) + trial (2)) After 3rd call 11 5
I I After 4th call 11 6
return (2) return (3) After 5th call 11 7

Output > 8 After 6th call 11 8
(ii) When the value of p is 4 then the output is 2 3
After 7th call 11 9
5 813.
Perform (5) After 8th call 11 10
i =1 x = trial (1) After final call 11 11
The value returned is 1.
=2
=2 x = trial (2) = 3 (ii) When the value of n = 27,
= 3 x = trial (3) = 5 Show (27, 2) //function called
=4 x = trial (4) = 8 The change of value during function execution
are as follows:
=5 x = trial (5) = 13
Output 2 3 5 8 13 Action Value of n Value of f
(iii) This function is finding Fibonacci number at Function call 27 2
nth position starting from 2. After 1st and Final call 27 3
Q. 11. The following function show( ) and calling( ) are The value returned is 0.
a part of some class. Assume that the parameter n
I (iii) The function show is a recursive function and if (n == i)
PROGRAMMING IN JAVA 115

it is finding whether the number entered is


return - m -
PRIME or NOT.
else
Q. 12. In the following, function strange is a part of some
class. Assume that arguments x and y are greater
than 0 when the function is invoked. Show the
return + + m Check (m , —n ) ;
Ans. Output: Check (5, 5)
dry run/working. [ISC 2007]
6 + Check (6, 4)
int strange (int x , int y)
7 + Check (7, 3)
8 + Check (8, 2)
// Assuming x > =0 and y > 0
9 + Check (9, 1)
if (x > = y)
Hence the output = - 9 + 9 + 8 + 7 + 6 = 21
{
[ISC Marking Scheme 2016]
x = x-y
return strange (x , y) ;
Examiner's Comment
else
w A number of candidates were able to answer this
{ question satisfactorily. Common errors made by
return x ; candidates were:
(i) Lack of clarity regarding the concept of
recursion;
}
(ii) Confusion with the postfix decrement
(i) What will function strange (20,5) return? operator in the return statement of the base
(ii) What will function strange (15,6) return? case (- m~) and calculating the output as 22
instead of 21.
(iii) In one line state what the function strange
(...) is doing? (iii) Showing the intermediate outputs in memory
blocks, without stating the final output.
Ans. (i) initially x = 20, y = 5
(iv) Mentioning the correct output without
x >= y x y Return showing the dry-run as required.
true x = x-y = 15 5 strange (15, 5);
true x = x - y = 10 5 strange (10, 5); Answering Tips
true x = x-y = 5 5 strange (5, 5);
w More practice should be done to solve programs
true x = x-y = 0 strange (0, 5); using recursive techniques.
false 0 5 0 w* Recursion and its techniques, must be taught to
The function strange (20, 5) will return 0. students with examples.
(ii) Initially, x = 15, y = 6 w Students should have knowledge of base case and
recursive case for every program using recursive
x >= y x y Return technique.
true 9 6 strange (9, 6); w Students should learn to do systematic dry run in
true 3 6 strange (3, 6); tabular manner. More practice should be done in
the concepts of infix and postfix operators.
false 3 6 3
The function strange (15, 6) will return 3.
Q. 14. A class Adder has been defined to add any two
(iii) The function strange is determining the
accepted time. [ISC 2017]
remainder of x/y.
Q. 13. The following function Check( ) is a part of some
Example : Time A - 6 hours 35 minutes
class. What will the function Check( ) return Time B - 7 hours 45 minutes
when the values of both ' m' and ' n' are equal to Their sum is - 14 hours 20 minutes
5? Show the dry run/working. [ISC 2016]
int Check (int m , int n)
(where 60 minutes = 1 hour)
116 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
The details of the members of the class are given this.a [l] = minSum %60;
I
below :
Class name : Adder void disptimeO {
Data member/instance variable : System.out.println("hours = " + this.a [0]
+ minutes = " + this.a [l ] ;
11

a[ ] integer array to hold


two elements ( hours and
minutes) public static void main (String[ ] args)
throws IOException {
Member functions/methods :
Adder objl = new Adder 0 ;
Adder( ) Constructor to assign 0 to
Adder obj2 = new Adder 0 ;
the array elements
Adder sumObj = new Adder () ;
void readtime( ) to enter the elements of
the array
objl . readtime () ;
obj2. readtime () ;
void addtime ( adds the time of the two
parameterized objects sumObj.addtime (objl , obj 2) ;
Adder X,
X and Y and stores the sumObj.disptime() ;
Adder Y)
sum in the current calling
object
void disptime ( ) displays the array
elements with an Long Answer Type
appropriate message ( i e ,
hours = and minutes = )
.. QuestionsII - (10 marks)
Q. 1. Design a class Convert to find the date and the
Specify the class Adder giving details of month from a given day number for a particular
the constructor ), void readtime( ), void year.
addtime( Adder, Adder) and void disptime( ).
Example: If day number is 64 and the year is 2020,
Define the main( ) function to create objects and
then the corresponding date would be:
call the functions accordingly to enable the task.
Ans. import java .io. BufferedReader; March 4, 2020 i.e. (31 + 29 + 4 = 64)
impot java .io.IOException ; Some of the members of the class are given below:
import java .io.InputStreamReader; Classname : Convert
class Adder { Data members/instance variables:
int [ ] a ; n : integer to store the day
Adder ( ) { number
a = new int [2] ; d : integer to store the day of the
} month (date)
void readtime ( ) throws IOException { m : integer to store the month
InputStreamReader x = new y : integer to store the year
InputStreamReader(System.in); Methods/Member functions:
BufferedReader y = new Convert ( ) : constructor to initialize the
BufferedReader(x); data members with legal
System.out.println("Enter hour : initial values
this.a [0] = Integer. parseInt (y.readLine ()) ; void accept( ) : to accept the day number and
System.out.println("Enter minute : ") ; the year
this.a [l] = Integer. parseInt (y.readLine ()) ; _ _
voidday to date( ) : converts the day number to
} its corresponding date for a
.
void addtime (Adder X Adder Y) { particular year and stores the
date in 'd' and the month in 'm'
int hourl = X.a [0] ;
int mini = X.a [l ] ; void display! ) : displays the month name,
int hour 2 = Y.a [0] ; date and year
int min 2 = Y.a [l] ; Specify the class Convert giving details of the
constructor! )/Void accept( ), void day_to_date( )
int hourSum = hourl + hour 2 ;
and voiddisplay( ). Define a main( ) function to
int minSum = mini + min 2 ; create an object and call the functions accordingly
this.a [0] = hourSum + (minSum/60); to enable the task.
I
Q. 2. A special number is a number in which the sum
PROGRAMMING IN JAVA
return x* factorial (x - 1) ;
117

of the factorial or its digits is equal to the number. }


Example: 145 (1! + 4! + 5! = 145). Thus, 145 is a Boolean isSpecialQ
special number.
Design a class Special to check if the given int num = n , sum = 0;
number is a Special number or not. Some of the
members of the class are given below: while (num > 0)
[ISC Specimen Question Paper 2016]
int t = num %10;
Class name Special
int f = factorial (t) ;
Data member/instance variable: sum = sum + f ;
n : Integer to store number num = num/10;
Member functions:
Special ( ) default constructor if (n==sum)
void read ( ) to accept the number return True;
int factorial (int x) return the factorial of a else
number using recursion return False;
technique
Boolean isSpecial( ) : checks for the special void display Q
number by invoking
the function factorial Boolean res = isSpecial() ;
( ) and returns True if (res=-True)
if Special, otherwise System.out. println (“ Entered number
returns False is a special number.”);
void display!) : to show the result with else
an appropriate message System.out. printlnfEntered number
Specify the class Special, giving details of the is not a special number.”);
Constructor, void read ( ), int factorial (int ), }
Boolean is Special ( ) and void display( ) . Define public static void main (String args[]) throws
the main( ) function to create an object and call IOException
the member function according to enable the task.
Ans. import java.io.*; Spcial sp = New Special () ;
import static java.lang.Boolean .*. sp.read ( ) ;
public class Special sp.display ( ) ;
{
int n;
Special ( ) Q. 3. A class Merger concatenates two positive integers
that are greater than 0 and produces a new merged
n = 0; integer.
Example: If the first number is 23 and the second
void read ( ) throws IOException is 764, then the concatenated number will be
23764. [ISC 2015]
{
Buffered Reader br = new Buffered Ans. Some of the members of the class are given
Reader (new InputstreamReader(System. below:
in) Class name Merger
System.out.println(Enter any number ”) ; Data member/instance variables:
n = Integer. parseInt (br.readLine ( )) ; nl : long integer to store first
} number
int factorial (int x) n2 : long integer to store
second number
if (x==0) mergNum : long integer to store the
return 1; merged number
else
118 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class- XII

obj.JoinNum( );
I
Member functions:
obj.show();
Merger ( ) : constructor to initialize }
the data members }
void readNum ( ) : to accept the values of [ISC Marking Scheme, 2015]
the data members nl and
n2
voidJoinNum ( ) : to concatenate the numbers Examiner's Comment
nl and n2 and store it in
mergNum A number of candidates were able to attempt
void show ( ) : to display the original this part well. The joinnum () function was not
numbers and the merged done properly by some candidates. Various
number with appropriate methods/techniques were used to concatenate the
messages numbers. Some did it directly without converting
it to String type. Several candidates reversed the
Specify the class Merger, giving the details of the
constructor, void readNum ( ), void JoinNum( )
number using while loop and then added it to
the other number. In some cases 'int' was used
and void show ( ). Define the main ( ) function
instead of 'long' data type. Object creation in the
to create an object and c all the functions
main () function was not properly defined in some
accordingly to enable the task ,

cases. Constructor and the main () method was


import java , util.*;
answered properly by a few candidates.
public class Merger

long nl, n2, mergNum;


Merger( ) { } //Or Merger ( ){nl = n2 Answering Tip
= mergNum = 0;}
Void readNum( )
{ Scanner x = new Scanner(System.in);
w - More practice must be done in conversion from
numeric to string and string to numeric. That
System.out.println("Enter two concatenation of strings is possible but does not
numbers"); work on numeric data, must be understood.
nl = x.nextLong ();
n2 = x.nextLong ( );
Q. 4. An emirp number is a number which is prime
}
backwards and forwards . Example: 13 and 31
void JoinNum () are both prime numbers . Thus, 13 is an emirp
{ String s = Long.toString(nl); number. Design a Class Emirp to check if a given
String si = Long.toString(n2); number is Emirp number or not. | ||[ISC 2013]
String s2 = s + si;
Class name Emirp
mergNum = Long.valueOf(s2);
Data member/instance variable:
}
OR n store the number
void JoinNum () rev store the reverse of the number
{ int s = 1; long a = n2; f store the divisor
while(a! = 0) Member functions/methods
{ s = s*10;
a = a/10;
Emirp ( int nn ) to assign n = nn, rev = 0 and
f =2
mergeNum = (nl*s) + n2; int isprime ( int check if the number is prime
x) using the recursive technique
void show( ) and return 1 if prime otherwise
{ System.out.println("First Number = return 0 .
" + nl); void isEmirp reverse the given number and
System.out.println("Second Number ( ) check if both the original number
=" +n2); and the reverse number are
System.out.println("Merged Number ="
tmergNum);
prime, by invoking the function
}
isprime (int) and display the
static void main () result with an appropriate
{ Merger obj = new Merger ( ); message.

||
* These questions are for practice and their solutions are available at the end of the chapter
I Specify the class Emirp giving details of the
PROGRAMMING IN JAVA
Design a class Point with the following details:
119

constructor(int), int isprime(int) and void


isEmirp(). Define the main() function to create an Class name Happy
object and call the methods to check for Emirp Data member/instance variable:
number. x store the ^-coordinate
Q. 5. A Happy number is a number in which the y store the y-coordinate
eventual sum of the square of the digits of the Member functions
number is equal to 1. [ISC 2012] # Point ( ) constructor to initialize x
e.g., 28 = (2)2 + (8)2 = 4 + 64 = 68 = 0, y = 0
68 = (6)2 + (8)2 = 36 + 64 = 100 void readpoint ( ) accepts the coordinates x
100 = (l )2 + (0)2 + (0 )2 = 1 + 0 4- 0 = 1 and y of a point
Hence, 28 is a happy number. Point midpoint (Point calculates and returns
A, Point B ) -
the mid point of the two
e.g., 12 = (l )2 + (2)2 = 1 + 4 = 5
points A and B
Hence, 12 is not a happy number.
void displaypoint () displays the coordinates
Design a class Happy to check if a given number of a point
is a happy number.
Specify the class Point giving details of the
Some of the members of the class are given below:
constructor (), member functions void readpoint(),
Class name Happy Point midpoint (Point, Point) and void
displaypoint ( ) alongwith the main () function to
Data member/instance variable: create an object and call the functions accordingly
n store the numbers to calculate the midpoint between any two given
points. [ISC 2010]
Member functions
Ans. import Java io. ;* ,

Happy ( ) constructor to assign 0 to


class Point
n
void gentum (int tin ) to assign the parameter double x, y;
value to the number n =
Point ( )
nn
_ _
int sum sq digits (int returns the sum of the x = y = 0;
*) square of the digits of
}
the number x, using the
recursive technique.
void readpoint( ) throws IOException

void ishappy ( ) checks if the given


BufferedReader br = new BufferedReader
number is a happy number
by calling the function
(new InputStreamReader (System.in) ;
_ _
sum sq digits (int) and System.out.println (“ Enter coordinates ” ) ;
displays an appropriate x = Double.parseDouble(br.readline ( )) ;
message. y = Double.parseDouble(br.readline ()) ;
Specify the class Happy giving details of the }
constructor (). void getnum (int). int sum_sq _ Point midpoint (Point A, Point B)
digits(int) and void ishappy( ). Also define a
main ( ) function to create an object and call the Point C = new Point ( ) ;
methods to check for happy number.
C.x = (A.x + B.x) /2;
Q. 6. The coordinates of a point P on a two dimensional C.y = (A.y + B.y) /2;
plane can be represented by P(x, y ) with x as
the x-coordinate and y as the y-coordinate. The return C ;
coordinates of mid-point of two points P1( x1, yt )
and P2(*2, */2) can be calculated as P ( x, y ) where: void displaypoint( )

*= * 2* ,y = ±
1+ 2
1 J/l J/2
2 System.out.println(x+ +y) ;
}

These questions are for practice and their solutions are available at the end of the chapter
120 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
public static void main (String args[ ]) Ans. Palindrome Number
I
throws IOException import java .io.*;
public class Palin {
Point PI = new Point 0 ; int num ;
Point P2 = new PointO ; int revnum ;
Point P3 = new Point 0 ; Palin ( ) {
PI. readpoint( ) ; num = 0;
P2. readpoint ( ) ; }
P3 = P3.midpoint (PI , P2) ; void accept ( ) throws IOException {
P3.displaypoint ( ) ; InputStreamReader x = new
} InputStreamReader (System.in) ;
BufferedReader y = new
Q. 7. A magic number is a number in which the BufferedReader (x) ;
eventual sum of digits of the number is equal to System.out.printlnf 'Enter a number") ;
1. [ISC 2009] # num = Integer. parseInt (y. readLine ( )) ;
e.g., 172 = 1 + 7 + 2 = 10
10 = 1 + 0 = 1 int reverse (int y) {
then 172 is a magic number. int len = (y+"") .length ( ) ;
Design a class Magic to check if a given number if (len == 1) {
is a magic number. Some of the members of the return y ;
class are given below: } else {
Class name Magic return (((y % 10) * (int) Math . pow(10,
len - 1)) + reverse (y/10)) ;
Data member/instance variable: }
n store the number
void check ( ) {
Member functions
revnum = reverse (num);
Magic () constructor to assign 0 to if (num == revnum) {
n System.out.println("Yes, it's a
void getnum (int tin ) to assign the parameter
palindrome");
value of the number, n = } else {
nn System.out.println(" No, it's not a
palindrome'') ;
int Sum of returns the sum of the
}
digits(int) digits of a number
void ismagic ( ) checks if the given public static void main (String [] args)
number is a magic number throws IOException {
by calling the function Palin myPal.inObj = new Palin () ;
Sumofdigits(int ) and myPalinObj.accept ( );
displays appropriate
myPalinObj.check ( ) ;
message
}
Specify the class Magic giving the details of
the constructor, void getnum(int), int Sum_of_
digits(int) and void ismagic(). You need not to Q. 9. A ticket at a ticket selling booth at a fair is priced
write the main function. at ?2.50/-. The booth keeps track of the total
number of people who have visited the booth, the
Q. 8. Specify the class Palin giving the details of the number of people who have actually purchased
constructor] ), void accept] ), int reverse(int) and
a ticket and the total amount of money collected.
void check] ). Define the main] ) function to
Design a class called Ticbooth, which includes
create an object and call the functions accordingly
the following Members: [ISC 2006]
to enable the task. [ISC 2017]

|
|g These questions are for practice and their solutions are available at the end of the chapter
I Class Name Ticbooth
PROGRAMMING IN JAVA
System .out.println (“no. of people
121

visitied the booth” +no_people) ;


Data member
}
no_ people number of people who have void disp_ticket ( ) //method disp_ticket
visited the booth.
{
amount total amount of money System .out.println (“amount collected ”
collected + amount) ;
Member functions System .out.println ( total no. of tickets

void initial to assign initial values to sold” + amount/2.50) ;
( ) data members }
void notsold increment total number of
0 people only visiting the Q. 10. A class Telcall calculates the monthly phone bill
booth and not purchasing a of a consumer. Some of the members of the class
ticket. are given below:
void sold ( ) increment total number of Class Name Telcall
people purchasing a ticket
Data member/instance variables
and the amount collected
when a ticket is sold phno phone number
void disp_ to display the total number name name of constructor
totals () of people visiting the booth n number of calls made
(the total number of people
purchasing the ticket as well amt bill amount
as those not purchasing a
Member functions/methods
ticket ).
void disp_
Telcall ( ) parameterized constructor
to display the total number
to assign values to data
ticket ( ) of ticket sold and the amount
members.
collected.
void compute to calculate the phone bill
Specify the class Ticbooth giving details of the
( ) amount based on the slabs
functions void initial ) ), void sold )), void notsold ( ),
_ _
void disp totals () and void disp ticket(). The given below.
main () function need not to be written.
Number of Rate
Ans. class Ticbooth //class Tickbooth calls
{ 1-100 ? 500/- rental
int no_ people ; charge only
float amount ; 101- 200 ? 1.00/-per call
void initial ( ) //class initial rental charge

no_people = 0. -
201 300 ? 1.20/-per call
rental charge
amount = 0 ;
above 300 ? 1.50/-per call
rental charge.
void notsold ( ) // method notsold ( )
{ void dispdate to display the details in the
no_people++ ;
( ) specified format.
The calculations need to be done as per the slabs
void sold ( ) //method sold Specify the class Telcall, giving the details of the
{ constructor, void compute ) ) and void dispdata) ).
no_people++ ; In the main function, create an object of type
amount = (float)(amount + 2.50) ; Telcall and display the phone bill in the following
format:
void disp_totals ( ) //method disp_totalQ Phone Name Total Amount
{ Number Calls
XXXXXXX XXX xxxxx xxxx [ISC 2006]
122 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class-XII
Ans. class Telcall Some members of the class are given below:
I
{ [ISC 2006] 0
String phno, name ; Class Name Hifact
int n ; Data member/instance variables
double amt;
a, b, hcf, 1cm integers
Telcall (String ph , String na , int nc)
Member functions/methods
{
phno = ph ; Hifact ( ) constructor to assign initial
values to the data members
name = na ;
n = nc; void getdata ( ) to input values of a and b
amt = 0.00; void change ( ) to swap a and b if a > b
} int rechcf (int, int ) to find hcf using the recursive
void compute ( ) technique
{ _
int fn lcm (int, to find 1cm using a , b and hcf
if (n < = 100) int, int )
{ void result ( ) to invoke and rechcf ( ) and
amt = 500.00 ; _
fn lcm ( ) and to print 1cm, hcf
of the two numbers a and b
if (n > 100 && n < = 200) Specify the class Hifact giving the details of
constructor, void getdata (). void change ( ). int
{ rechcf () and int fn_lcm (). Write the main function
amt = (n - 100)*1 + 500 ; and find the hcf and 1cm of any two integers, a
and b.
if (n > 200 && n < = 300) Q. 12. A class quad contains the following data
{ members and member functions to find the roots
amt = (500 + 100*1 + (n - 200)*1.2) ; of quadratic equation:
if (n > 300) Class Name Quad
{
amt = (500 + 100*1 + 100*1.2 + (n
Data members a, b, c (float ), xv x2 (float )
Member functions/methods
- 300)*1.5) ;
} quad (float, float, constructor to assign values
float ) to the data members
void dispdata( ) float discriminate to return the discriminant [ b 2
{ 0 - 4rtC]
System.out.println (“ Phone Number\
_
void root equal () to display the root if both
tName\t\tTotal calls\tAmount”) roots are equal
System.out.println(phno+ \t “ + name” void imag( ) to display the roots, if roots
\t “ +n +” \t\t “ +amt) ; are imaginary
_
void roots real () to display the two real,
public static void main (String args[ ]) unequal roots
{ void roots ( ) to call other appropriate
Telcall t = new Telcall (“ 9897205588” , functions to find the solution
“Amit Sharma ” , 250) ; of the problem.
t.compute ( ); If ax2 + bx + c = 0 is the quadratic equation, then
t.discpdata ( ) ; if b2 - 4ac > 0 roots are real, unequal

-b +' Jb2 - 4ac b yjb2 4 ac


} where, x1 =
2a => *2 = - - la -
If b2 - 4ac = 0 roots are real, equal
Q. 11. A class Hifact has been defined to find the HCF of
two numbers using the recursive technique. This xx = x2 = - b/2a
HCF is used to find the LCM of the two numbers. if b2 - 4ac < 0 root are imaginary.

0 These questions are for practice and their solutions are available at the end of the chapter
)
I Specify the class quad giving the details of the
PROGRAMMING IN JAVA

Member functions/methods
123

functions.
sumseries ( ) constructor
quad (float , float , float)
int factorial (int calculates and return
float discriminate ( ) n) factorial of n (»!) where
_
void root equal 0 «! = 1 x 2 x 3 x ... x n
void root real 0 double term (int calculates and return the
p, int q) value of p/q\ by making use
void root ( ) of factorial (int)
You may assume that other functions are written void accept ( ) inputs the value of data
for you. You need not to write the main function. member x, n
Ans. class quad void displays the value of
{ displaysum ( ) member sum.
float a, b, c, xl, x2, d; double calsum calculate the sum of the given
quad (float x , float y, float z) 0 series using the appropriate
//constructor with argument data and other member
{ function.
a = x; b = y; c = z; (i ) Specify the class series giving details of
} constructor, int factorial (int), double term
float discriminate ( ) //method discriminant (int, int), void display sum ( );
{ You may assume other member functions are
return (b*b) - (4* a * c); written for you. You donot need to write the
} main function.
_
void root equal ( ) //method root equal _ (ii ) What care do you need to take while
{ designing double term (int, int)
xl = -b/(2* a); Ans. (i ) class sumeries
x2 = -b/(2*a);
System.out. println (xl + " " + x2); int x , n ;
} double sum ;
_
void root real () //method root real _ sumseries ( ) //constructor sumseries
{
x = 0;
xl = (float)((-b + Math.sqrt(d ))/2*a);
n = 0;
x2 = (float)((-b - Math.sqrt (d ))/2* a );
} sum = 0.0 ;
void root ( ) //method root
{ int factorial (int n )
d = discriminant(); {
if (d = = 0) if (n = = 1)
_
root equal (); return (n) ;
if (d > 0) else return (n * factorial (n - 1)) ;
_
root real ();
if (d < 0) double term (int p, int q)
System.out.println("Imaginary"); {
}
double d ;
}
double f ;
x2 -1
Q.13. Sum = 1 + 1— + — + — + ... + ” [ISC 2005] if (q = = 0)
!2 ! 3! n! {
A class sumseries has been defined to calculate system.out. println ("Division by
sum of the above series. Some of the members of zero");
the class are given below: return (0) ;
Class Name Sumseries }
Data members/instance variable else
{
variable x, n (integer), sum(double )
f = factorial (q);
124 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class- XII
d = p/f ; int a = num;
I
while(a!=0)
return (d) ; { a = a/10;
size ++; }
void displaysum ( )
int sumofDigits (int n, int p)
System . out. println ("Sum is" + sum) ; { return (n==0)? 0:
sumofDigits(n/10,p - 1)
+ (int) Math.pow(n%10, p);
(ii ) When we design double term (int, int ), care }
should be taken that a division operation void check ()
should not be done by zero.
{ if (num==sumofDigits (num,
Q . 14. A disarium number is a number in which the size))
sum of the digits to the power of their repective System.out.print("\n Disarium
position is equal to the number itself . Number");
Example: 135 = 11 + 32 + 53 else
Hence, 135 is a disarium number. System.out.print( w \n Not a
Disarium Number t t );
Design a class Disarium to check if a given
}
number is a disarium number or not. Some of the
member of the class are given below: static void main( )
{ System.out.println("Input a
Class : Disarium Number");
Data members/instance variables: int m = sc.nextlnt ();
int num : stores the number Disarium x = new Disarium (m);
x.countDigits( );
int size : stories the size of the number
x.check( );
Method/Member functions:
Disarium (int : parameterized constructor to } [ISC Marking Scheme, 2016]
nn ) initialize the data member n =
nn and size = 0
void count : counts the total number of Examiner's Comments
Digit() digits and assigns it to size
i n t : returns the sum of the digits of Most candidates answered this question correctly.
s u m o f D i g i t s the number (n ) to the power of Common errors made by the candidates were:
(int n, int p) their respective positions ( p) The concept of recursion was not clear to some
using recursive technique. candidates.
void check ( ) : checks whether the number
Some did not use the parameters in the function.
is a disarium number and
displays the result with an A few candidates wrote the function sum of Digits
appropriate message () without using the recursive technique.
Specify the class Disarium giving the details of Several candidates had problem in decrementing
the constructor(), void count Digit (), int sum of the power parameter in the recursive function.
Digits(int, int) and void check() . Define the main () The other function including the constructor was
function to create an object and call the functions well answered. Some candidates did not write the
accordingly to enable the task. [ISC, 2016] main () function.
Ans. import java.util.Scanner;
public class Disarium
{ int num, size;
Answering Tips
static Scanner sc = new Scanner(System.
in); w Students must practice on solving programs using
recursive techniques. They must have sufficient
Disarium (int nn)
knowledge about base case and recursive case in
{ num = nn; recursive programs.
size = 0; }
w Students should learn how to create recursive
void countDigit ( )
code for most iteration cases.
I
Q . 15. A class SeriesSum is designed to calculate the
PROGRAMMING IN JAVA

double findpower (int x, int y)


125

sum of the following series {


BufferedReader br = new
Sum = — H H [ISC 2014] BufferedReader (new
1! 3! 5! -
(n 1 )1 InputStreamReader(System.in);
//to return x raised to the power of y
Some of the members of the class are given below:
{
Class Name | SeriesSum if ( y==D
return x;
Data members/instance variables
else
x to store an integer number return(x*findpower(x, y -
n to store number of terms l ));
}
sum double variable to store the
public void calculate()
sum of the series //to calculate the sum
Member functions
sum = 0;
SeriesSum ( int xx, constructor to assign x = xx
for(int i = 2; i < n; i = i + 2)
int nn ) and n = nn
double findfact to return the factorial of m sum = sum + (findpower(x,
( int nn) using recursive technique i)/ findfact(i - 1));
}
double findpower to return x raised to the power
( int x, int y ) of y using recursive technique
void display()
void calculate ( ) to calculate the sum of the series // t o display the sum of series
by invoking the recursive {
functions respectively System.out.print In ("Sum of
series: "+sum);
void display ( ) to display the sum of the
}
series public static void main (String
Specify the class SeriesSum, giving details of the arg []) throwsIOException
constructor ( int, int), double findfact (int ), double System.out.println ("Enter the
findpower ( int, int ), void calculate() and void value of x:");
display () . Define the main() function to create an int x = integer.parselnt(br.
object and call the functions accordingly to enable readLine( ));
the task. System.out.println("Enter the
value of n:");
Ans. import Java.io.*; int n = Integer parsenlnt(br.
//class library of Java readLine( ));
class SeriesSum //class name SeriesSum SeriesSum ob = New SeriesSum
{ (x, n);
public int x, n; ob.calculate( );
//variable declaration ob.display( );
public double sum;
public SeriesSum (int xx, int nn) } [ISC Marking Scheme, 2014]
//parameterized constructor
{
x = xx;
n = nn; Examiner's Comment
}
public double findfact(int m)
//to return the factorial of m
-
r A number of candidates answered this part
correctly. Common errors made were: The concept
{ of recursion was not clear to some candidates;
if (m <= 1) some used the in built mathematical functions;
{ some wrote the function find fact () and find
return 1; power ( ) without using the recursive technique.
}
Several candidates did not invoke the functions
find if act ( ) and find power ( ) to calculate the
else
sum of the series. In some cases, 'return' statement
{
was missing. The other function including the
return(m*findfact(m - 1);
constructor was well answered. Some candidates
} did not write the main () function.
}
126 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Specify the class recursion, giving the details
I
Answering Tip of the constructor, int fib(int). void generate_
fibseries() . You may assume other functions are
w- More practice should be done in solving programs written for you and you need not write the main
function.
using recursive techniques. Students should have
knowledge of base case and recursive case for Ans. class recursion
every program using recursive technique. Practice
should be done in invoking function within
another function. int a , b, c, limit;
public recursion ( ) //constructor recursion
Q. 16. A class DeciOct has been defined to convert a
decimal number into its equivalent octal number. a=0
Some of the members of the class are given below:
b =1
[ISC 2011] # c =1
Class name DeciOct
Data members/instance variables
int fib (int n) //method fib
n stores the decimal number
oct stores the octal equivalent number
if (n== l)
Member functions
return 0 ;
DeciOct () constructor to intialise the data
member n = 0, oct = 0 else if (n == 2)
void getnum (int assign nn to n return 1;
mi) else
_
void deci oct ( ) calculate the octal equivalent of return (fib (n - 1) + fib (n - 2)) ;
and stores it in oct using the
recursive technique
void show ( ) displays the decimal number ' ri ,
_
void generate fibseries ( )
calls the function deci oct() and _ _
//method generate fibseries
displays its octal equivalent
Specify the class DeciOct, giving details of the int x = 1;
constructor(), void getnum (int), void deci_oct()
and void show(). Also define a main() function to while (x < = limit)
create an object and call the functions accordingly
to enable the task. c = fib (x) ;
Q. 17. A class recursion has been defined to find the System.out.println(c) ;
fibonacci series upto a limit. Some of the members
of the class are given below: [ISC 2005] x ++ ;
}
Class Name Recursion
Data members
a, b, c, limit all integers void input( )
Member functions/Methods
recursion () constructor to assign a, b, c Inputstreamreader x = new Input
with the appropriate values. stream Reader (system.in) ;
void input( ) to accept the limit of the BufferedReader y = new bufferedReader
series. M;
int fib (int n ) to return the nth Fibonacci System.out.println("Enter One number") ;
term using recursive tech - limit = Integer. parse Int (y. readLine 0) ;
nique.
void _
generate to generate Fibonacci series
fibseries( ) upto the given limit. }

These questions are for practice and their solutions are available at the end of the chapter
PROGRAMMING IN JAVA 127

Examiner's Comment Answering Tip


w Most of the candidates were able to attempt this
part correctly. Common errors made by candidates
-
w More practice should be done in solving programs
using recursive techniques. Much attention should
in this question were: the concept of recursion was be paid towards recursion and its techniques with
not clear to some candidates; several candidates did examples. Knowledge of base case and recursive
not use the parameters in the function; some took case should be done for every program using
extra variables while others did not initialize the recursive technique. Invoking function within
array in the constructor; a few candidates wrote the another function should be given more practice.
function binsearch () without using the recursive The students should create recursive code for
technique. The other function including the most iteration cases.
constructor was well answered. Some candidates
did not write the main () function and also ignored
the comments to be given in the program.

I TopiC- 3

Revision Notes
Arrays
Concepts covered: Arrays; Array implementation; Single and multi
dimensional arrays; calculating size and address of arrays.

> Arrays are the type of data structure which store a fixed-size sequential collection of elements of the same type.
An array is used to store a collection of data and also a collection of variables of the same type.
> -
One Dimensional Arrays
-
A one-dimensional array is, essentially, a list of like typed variables. To create an array, you must first create an
array variable of the desired type.
The general form of a one-dimensional array declaration is:
_
type var name[ ] ;
Here, type declares the base type of the array. The base type determines the data type of each element that
comprises the array. Thus, the base type for the array determines what type of data the array will hold.
For example, the following declares an array named month days with the type "array of int":
_
int month days[ ] ;
> Multidimensional Arrays
In Java, multidimensional arrays are actually arrays of arrays. There are a couple of subtitle differences. To
declare a multidimensional array variable, specify each additional index using another set of square brackets. For
example, the following declares a two-dimensional array variable called twoD.
int twoD[][] = new int[4] [5] ;
This allocates a 4 x 5 array and assigns it to twoD. Internally this matrix is implemented as an array of arrays of
int. The following program numbers each element in the array from left to right, top to bottom, and then displays
these values:
// Demonstrate a two-dimensional array,
class TWoDArray {
public static void main (String args[]) {
int twoD[][] = new int [4][5] ;
int i, j, k = 0;
for (i=0; i<4; i++)
for ( j =0; j<5; j++) {
twoD[i][j] = k ;
k ++;
}
for (i=0; i<4; i++) {
for ( j =0; j<5; j++)
128 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
System.out.print(twoD[i] [j] + " ");
I
System.out.printlnO ;

This program generates the following output:


01234
56789
10 11 12 13 14
15 16 17 18 19

|Key Terms
> An array is a group of like-typed variables that are referred to by a common name. Arrays of any type can be
created and may have one or more dimensions. A specific element in an array is accessed by its index. Arrays
offer a convenient means of grouping related information.
> An array of objects is created like an array of primitive type data items.

OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. The conditional statement to check for the (ii) What is the method test() performing?
diagonal elements in a double dimensional array (A) Counting the odd numbers
of 'M' number of rows and 'M' number of columns (B ) Checking for the maximum element
having the row index represented by 'r' and the (C) Checking the perfect numbers
column index represented by 'c' will be: (D) Counting the prime numbers
[ISC Sem-1 Paper 2021-22] Ans. (i) Option (A ) is correct
(A) (r = = c && r + c = = M)
Explanation: Loop i will repeat 6 times which
(B ) (r = = c 11 r + c = = M-l )
is the length of the array arr[]. And the loop
(C) (r = = c && r + c = = M-l )
j will be for count the number of factors of
(D) (r = = c 11 r = = M-l || c = = M-l) each number. If it is equal to 2 that means the
Ans. Option (B) is correct number is prime. Because only prime number
Explanation: If the size of a square matrix = 5, has two factors. In this array only 3 prime
then the indexes of the diagonal will be (0,0), numbers are there (2, 13, 29).
(1.1),(2,2),(3,3,) and (4,4). Other one is (0,4), (1,3), (ii) Option (D) is correct
(2.2), (3,1) and (4,0). That means when row = Explanation: This program will count number
column or row + column = size -1. of prime number present in the array.
Q. 2. With reference to the following program code, Q. 3. The following program code converts a decimal
answer the questions that follow: integer number 'num' to its equivalent value in
[ISC Sem-1 Paper 2021-22] any given base ' b' . There are some places in the
void test (int arr []) code marked as ?1?, ?2?, ?3?, ?4? and ?5? which
{ int c=0,s=0 ; are to be replaced by a statement/expression so
that the code works properly.
for (int i=0 ;i< arr.length ;i++) [ISC Sem-1 Paper 2021-22]
{ for (int j=l;j<= arr [i] ; j++) void convertnum (int num , int b)
{ if (arr[i]% j ==0) C ++; { int A[] =new int[20] ;
int x= ? l ? ;
if (c== 2) s++;c=0; while (num !=0)
{ A[x++] = ? 2 ? ;
System.out.println(s); num /=b;
} }
(i) What will be the output of the method test() when
the value of arr[]= {2,9,13,18,21,29}? —
for (int i= ? 3? ;i>=0 ;i )
(A) 3 (B ) 4 { if ( ? 4 ?)
C
( ) 0 (D ) 1 System.out.print(A[i]) ;
I else {
PROGRAMMING IN JAVA
?4? = M[j][k]
129

System ,out.print((char)( ? 5 ?)) ; M[ j ] [ k ] = ? 5 ?


MD + i] [k]=t

Answer the following questions:


}
(i) The statement or expression at ?1? is:
(A) 1 (B ) 0 Answer the following questions:
(C) -1 (D) 10 i
() The statement or expression at ?1? is:
(ii) The statement or expression at 121 is: (A) M.length (B ) M[0].length
(A) num*num (B ) num/b (C) M.lengthQ (D) M[l ].length()
(C) num % b (D) num (ii) The statement or expression at ?2? is:
(iii) The statement of expression at 131 is: (A) k < = r (B ) k < = c
(A) x-1 (B ) x (C) k < r (D ) k < c
(C) x-2 (D ) 0 (iii) The statement or expression at 131 is:
(iv) The statement or expression at ?4? is: (A) M[ j] < M[ j + l ]
(A) i < num (B ) A[i] > num (B ) M[k][ j] <M[k][j +l]
(C) A[i] >10 (D) A[i] <10 (C) M[ j][k] < M[ j + l ][k]
(D) M[i][k] < M[i + l ][k]
(v) The statement or expression at 151 is:
(A) A[i] (B ) A[i] + 55 (iv) The statement or expression at 141 is:
(C) A[i] + 65 (D) A[i]*10 (A) t (B ) M[ j + l][k]
Ans. (i) Option (B) is correct (C) r (D ) c
Explanation: Initialize the value of x with 0. (v) The statement or expression at ?5? is:
(ii) Option (C) is correct (A) M[i + l][k] (B ) M[k][ j +1]
Explanation: Store the remainder into the (C) M[ j][k] (D) M[ j + l ][k]
array Ans. (i) Option (A ) is correct
(iii) Option (A) is correct Explanation: Find number of column of the
Explanation: Start the loop from x-1, because array.
after complete the previous loop x will (ii) Option (D) is correct
increase by 1. Explanation: Loop will continue c times.
(iv) Option (D) is correct (iii) Option (C) is correct
Explanation: All digit (i.e. from 0 to 9) will Explanation: Checking for descending order.
print. (iv) Option (A) is correct
(v) Option (B) is correct Explanation: It is a temporary variable for
Explanation: From 10 it will represented by swapping values.
letter. 10 = A, 11 = B, 12 = C etc. To achieve (v) Option (D) is correct
this we use ASCII value of capital letters which
Explanation: Interchange the value of M[ j][k]
is from 65 to 90. with M[j + l ][k]
Q. 4. The following program code sorts the columns of Q. 5. What is Base 'type of an array?
a double dimensional array in descending order (A) It's length
using Bubble Sort technique. There are some (B ) It's last index number
places in the code marked as ?1?, 121, 131, 141 (C) The data type of array elements
and 151 which are to be replaced by a statement/
(D) None of these
expression so that the code works properly.
[ISC Sem-1 Paper 2021-22] Ans. Option (C) is correct
Explanation: All the values in an array must be of
void sortcol (int M [] []) the same type, this is called the base type of the
{ int r= M .length ; array.
int c= ? l ? ; Q. 6. Find the correct way to declare a single dimension
int t; array.
(A) double x[];
for (int k =0; P 2 P ; k ++) x = new double[s]
for (int i=0 ;i< r-l;i++) (B ) double x[] = new double[s];
for (int j=0;j<r-l-i; j++) (C) double x[s] = new[];
{ if ( ? 3?) (D) both (A) and (B)
Ans. Option (D) is correct
130 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 7. When an array is declared: (choose correct Q. 12. Elements of a 2-D array are stored in memory
I
statement/statements) after
(i) A special object is created. (A) contiguous
(B ) linearization
(ii) The object contains a group of contiguous
(C) row major
memory locations all having the same name
and data type. (D) column major
Ans. Option (B) is correct
(iii) The object has a reference to the beginning
address of the array elements. Explanation: While storing the element of 2D-array
in memory, these are allocated contiguous memory
(iv) The object has a separate instance variable locations, therefore 2D-array must be linearlized so
containing the number of elements in the as to enable this storage.
array. Q. 13. In a 2-D array char section [20][5] what will be the
(v) It is initialized automatically. address of the [4, 5]th element if base address is
100. Array is stored as row major.
(A) All are true
(A) 104 (B ) 109
(B ) None is true
(C) 119 (D) 150
(C) All except (v) are true
Ans. Option (D) is correct
(D) All except (v) are false
Q. 14. If the reference of an array A is assigned to
Ans. Option (C) is correct another array B, then
Q. 8. Which of the following is not a valid type of array (A) the elements of A are copied to B
in Java? (B ) Reference of array B is changed
(A) Single dimensional array (C) both (A) and (B)
(B ) Multi-dimensional array (D) None of these
(C) Double dimensional array Ans. Option (B) is correct
(D) None of these. Q. 15. The method which transverses the array
Ans. Option () is correct sequentially to locate the given time, is called
(A) binary search (B ) linear search
Explanation: There are two types of array in Java (C) sequential search (D) both (B) and (C)
i.e.
Ans. Option (D) is correct
• Single dimensional array in Java
Explanation: The method which transverses the
• Multi-dimensional array in Java array sequentially to locate the given time is called
Q. 9. In an array array2[5][4]: linear search or sequential search. In linear search,
(A) Number of rows is 5 each element of array is compared with the each
value of the list, one at a time and in sequence,
Number of columns is 4
unit the desired one is found.
(B ) Number of rows is 4
Q. 16. A square matrix A[m][m] is stored in the memory
Number of columns is 5
Row Major wise with each element requiring 2
(C) It depends on how 'for' loop is used to take bytes of storage. If the base address at A[1][0] is
the input. 1020 and the address at A[4][3] is 1056, then the
(D) It depends on JVM. order of the matrix A[m][m] will be:
Ans. Option (A ) is correct (A) [6][6] (B) [4][4]
(C) [5][5] (D) [3][3]
Q. 10. A two dimensional array marks [10][5] can store a
maximum of elements. Ans. Option (C) is correct
(A) 10 (B ) 5 Explanation: In Row Major for calculate the
address of a cell of a matrix is
(C) 15 (D) 50
Address of A[I][J] = B + W ( N(I-Ro) + (J-C0))
Ans. Option (D) is correct
B = Base address
Q. 11. How many bytes will be required by an array W = Width of the cell of matrix
declared as follows double darray [7][6]
N = Number of column
(A) 42 bytes
I = Row subscript of the element.
(B ) 13 bytes
(C) 336 bytes
J = Column subscript of the element.
(D) 168 bytes Ro = Lower range of the row.
C0 = Lower range of the column.
Ans. Option (C) is correct
Using the above formula output will be 5.
I PROGRAMMING IN JAVA 131

SUBJECTIVE TYPE QUESTIONS


Q. 4. Each element of an array arr[15][20] requires 'W'
Short Answer Type bytes of storage. If the address of arr[6][8] is 4440
<©> Questions (2 marks) and the Base Address at arr[l][l] is 4000, find the
width 'W' of each cell in the array arr[ ][ ] when
Q. 1. A matrix B[10][20] is stored in the memory with the array is stored as Column Major Wise.
each element requiring 2 bytes of storage. If the [ISC Specimen Question Paper 2016]
base address at B[2][l] is 2140, find the address
Ans. Given, i = 6, j = 8, B = 4000, m = 15, Lc = 1, Lr =
of B[5][4] when the matrix is stored in Column
1, W = ?
Major Wise.
Add[i][j] = 4440
Ans. Column Major Wise:
Column wise,
B[i][j] = BA + W [ 0 - 1c)* row + (i - lr)] Add[i][j] = B + W[m( j - Lc) + (i - Lr)]
Putting the values: 4440 = 4000 + W[15(8 - 1) + (6 - 1)]
= 2140 + 2[ (4-1) * 10 + (5-2)] 4440 - 4000 = W (15 x 7 + 5)
= 2140 + 2[ 33 ] = 2140 + 66 440 = W (105 + 5)
= 2206 440 = W (110)
Q. 2. A matrix P[15][10] is stored with each element 440
requiring 8 bytes of storage. If the base address W = —
no
at P[0][0] is 1400, determine the address at P[10][7]
when the matrix is stored in Row Major Wise. W = 4 bytes
igl [isc 2017] -
Q 5. The array D[-2 ... 10][3 ... 8] contains double
Q. 3. A matrix A[m][n] is stored with each element
type elements. If the based address is 4110, find
the address of D[4][5], when the array is stored in
requiring 4 bytes of storage. If the base address at
Column Major Wise. [ISC 2015]
A[l][l] is 1500 and the address at A[4][5] is 1608,
determine the number of rows of the matrix when Ans. The given values are:
the matrix is stored in Column Major Wise. B = 4110, W = 8 bytes or 64 bits for double type,
[ISC 2016] I = 4, J = 5, Lr = -2, Lc = 3,
M = (10 - (- 2) + 1 = 10 + 2 + 1 = 13
Ans. Column Major Wise: Address of A[I] Q]
A[i][j] = BA + W[( j - lc)* rows + (i - lr)] = B + W*[(I - Lr) + M*(J - Lc)]
Putting the values: = 4110 + 8*[(4 - (-2)) + 13 * (5 - 3)]
1608 = 1500 + 4[(5 - l )*rows + (4 - 1)] = 4110 + 8*[6 + 13*2]
1608 = 1500 + 16*rows + 12 = 4110 + 8*[6 + 26]
-16*rows = - 96 = 4110 + 8*[32] = 4110 + 256
Rows = 6
= 4366
[ISC Marking Scheme 2016]
OR = 4110 + 64* [32] = 4110 + 2048
= 6158
[ISC Marking Scheme 2015]

Examiner's Comment
Examiner's Comment
r
- Some candidates wrote the answer directly
without sharing the working. A few candidates
w A number of candidates were confused with the
made mistakes in Calculation while others wrongly
width of the cell and assumed different values.
determined Row Major instead of Column Major.
Some wrote the answer directly without sharing
the working or mentioning the formula.
-YiY- Answering Tip
Answering Tip
r
- More practice should be alone in calculating
addresses using both Row major and column
w Size of various data types must be explained as it
major wise. The different terms used in address is necessary in such types of questions. Formula
calculation must be learnt.
and working should also be shown.

These questions are for practice and their solutions are available at the end of the chapter
132 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class-XII
Q. 6. An array AR[- 4...6, - 2...12] stores elements in
I
1144 = 1098 + 2[(m(5 - 1) + (4 - 1))]
row major wise, with the address AR[2][3] as
4142. If each elements requires 2 bytes of storage,
=> 1144 - 1098 = 2[(m(4) + (3))]
46
find the base address. [ISC 2014] => 2
= 4m + 3
Ans . Given array, AR ]- .. .6, -2 . ... 12]
Row wise order,
^ => 23 - 3 = 4m
20
Add[2][3] = B + W[n(I - Lr) + ( j - Lc)] => 4
=m
B=? => m=5
Given 1 = 2, J = 3, W = 2 bytes Q. 10. A character array B[7][6] has a address 1046 at 0,
Add [i][ j ] = 4142 0. Calculate the address at B[2][3] if the array is
To find n, stored column major wise. Each character requires
n = Uc - Lc + 1 = (12 - (-2) + 1 two bytes of storage. [ISC 2010]
= 12 + 2 + 1 = 15 Ans. Given, Add [2][3]
n = 15 i = 2, j = 3, Lr = 0, B = 1046, Lc = 0, W = 2, n = 7
Now, Column Wise,
4142 = B + 2[15(2 - (- 4)) + (3 - (-2)) ] B[2][3] = B + W[(i - Lc) + n(j - Lr)]
4142 = B + 2[15(2 + 4) + 3(3 + 2) ] = 1046 + 2[(2 - 0) + 7(3 - 0)]
4142 = B + 2[90 + 15] = 1046 + 2 (2 + 21) = 1046 + 46
4142 = B + 190 B[2][3] = 1092
B = 4142 - 190 = 3952
Q. 11. Each element of an array A[20][10] requires two
[ISC Marking Scheme 2014] bytes of storage. If the address of A[6][8] is 4000,
Q. 7. A square matrix M[ ][ ] of size 10 is stored in the find the base address at A[0][0] when the array is
memory with each element requiring 4 bytes of stored as row major wise. [ISC 2009]
storage. If the base address at M[0][0] is 1840, Ans. Given, Address of A[6][8] = 4000
determine the address at M[4][8] when the matrix
n = Uc - Lc + 1 = 1 0 - 0 + 1 = 11
is stored in row major wise. | <f [ISC 2013] W = 2, i = 6, j = 8, Lr = Lc = 0
Q. 8. A matrix B[10][7] is stored in the memory with The base address of A[0][0] row major wise is
each element requiring 2 bytes of storage. If the calculated as follows:
base address at B[x][l] is 1012 and the address at
A[6, 8] = B + W[n(i - Lr) + (j - Lc)]
B[7][3] is 1060, determine the value 'x' where the
matrix is stored in column major wise. [ISC 2012] => 4000 = B + 2[11(6 - 0) + (8 - 0)]
Ans. i = 7, j = 3, W = 2, B = 1012, m = 10 = > 4000 = B + 2[11 x 6 + 8]
Add[i][j] = 1060 => 4000 = B + 148
Column wise, => B = 4000 - 148 = 3852
Add[i][j] = B + W[m(J - Lc) + (I - Lr)] Q. 12. A two dimensional array defined as X[3 ... 6, -2
>= 1060 = 1012 + [(3 - 1)*10 + (7 - x)] x 2 ... 2] requires 2 bytes of storage space for each
element If the array is stored in row-major order,
>= 1060 = 1012 + [20 + (7 - x)] x 2
determine the address of X[5, 1] given the base
1060-1012 = 40 + 14 - 2x
addresses as 1200. [ISC 2008]
48 - 40-14 = - 2x
Ans. According to row-major,
8 - 14 = - 2x
2x = 6
B + W[n(p - Lr) + (i - Lc)]
x =3 Given, B = 1200, W = 2 byte, i = 5, j = 1, Ur = 6,
Q. 9. A square matrix A[m x m] is stored in the
Uc = 2, Lr = 3, Lc = -2
n(number of columns)
memory with each element requiring 2 bytes of
storage. If the base address A[l][l] is 1098 and the = Uc - Lc + 1
address at A[4][5] is 1144, determine the order of n = 2 - (-2) + 1 = 5
the matrix A[m x m] when the matrix is stored Address of X[5][l]
column major wise. [ISC 2011] = 1200 + 2[5(5 - 3) + (1 - (-2))]
Ans. Given, i = 4, j = 5, B = 1098, Lr = 1, Lc = 1, W = = 1200 + 2[5(2) + 3]
2, m = ? = 1200 + 2 x (10 + 3)
Add[4][5] = 1144 = 1200 + 2 x 13
Column wise, = 1200 + 26
Add[4][5] = BA + [m(j - Lc) + (i - Lr)] Add[5][l] = 1226

||
* These questions are for practice and their solutions are available at the end of the chapter
I
Q. 13. Each element of an array X[-15 ... 10, 15 ... 40]
PROGRAMMING IN JAVA
may be replaced by a statement/ expression so
133

requires one bytes of storage. If the array is that the function works properly.
stored in column major order with the beginning void select sort (int [ ] a)
location 1500, determine the location of [5, 20].
[ISC 2007]
int i, j, t , min , minpos ;
Ans. Given, Base Address (B) = 1500
for (i = 0; i < ?1? ; i ++)
Element Size (W) = 1, Lr = - 15, Lc = 15, Ur = 10
Number of Rows (m)
min = a [i];
= Ur - Lr + l minpos = i;
= 10 - (-15) + 1 = 26 for ( j = ? 2 ? \ j < a .length ; j++)
Therefore, the address of X[15, 20] in column major
order {
if (min > a [ j])
= B + W[m(j - Lc) + (i - Lr)]
{
= 1500 + 1[26 (20 - 15) + (5 - (-15))]
? 3 ? = j;
= 1500 + 1(130 + 20)
min = ? 4 ? ;
= 1500 + 130 + 20
X[5][20] = 1650
Q. 14. In an array of real numbers ARR[25][25], ARR[1]
[1] is stored is location 1000. Find the address of t = a [minpos];
ARR[12][12] when the array is stored row major a [minpos] = a [i] ;
wise. Assume each real number requires 4 bytes. a [i] = ? 5 ?
[ISC 2006] }
Ans. Given, Arr[25][25] for (int k = 0 ; k > a.length ; k ++)
i = 12, j = 12, W = 4, B = 1000 System.out.println(a [k]) ;
Row wise,
Arr[12][12] = B + W[n(I - Lr) + (j - Lc)] (i) What is the expression or statement at ?1?
= 1000 + 4[25(12-1) + (12-1)] (ii) What is the expression or statement at ?2?
= 1000 + 4 [25 x 11 + 11] (iii) What is the expression or statement at ?3?
= 1000 + 4 [275 + 11] (iv) What is the expression or statement at ?4?
= 1000 + 1144 (v) What is the expression or statement at ?5?
Arr[12][12] = 2144 Ans. (i) ?1? = a.length - 1
Q. 15. An Array ARR[10][15] is stored in memory with (ii) ?2? = i + 1
each element requiring 2 bytes of storage. If the (iii) ?3? = minpos
first element ARR[0][0] is stored at the location
(iv) ?4? = a[j]
1250, calculate the location of ARR[5][3] when the
array is stored row major wise. [ISC 2005] (v) ?5? = t
Ans. Row major wise Q. 2. The following function is a part of some class.
ARR[i][j] = B + [n(i - Lr) + (j - Lc)] It sorts the array a[ ] in ascending order using
insertion sort technique. There are some places in
Given, B = 1250, W = 2 bytes, i = 5, j = 3, Lr = 0, the code marked by ?1?, 72?, 737, 747, 75? which
Lc = 0, Ur = 9, Uc = 4, must be replaced by expression/statement so that
n = Uc - Lc + 1 the function works correctly, [ISC 2010]
= 15 - 0 + 1 = 16 void insertosort (int a [ ])
ARR[5][3] = 1250 + 2[16(5 - 0) + (3 - 0)]
= 1250 + 2 (80 + 3) int m = ?1? ;
= 1250 + 2 x 83 int b, i , t;
= 1250 + 166 = 1416 for (i = ? 2 ? ; i < m ; i++)
Long Answer Type {
<©> Questions (5 marks) t = a [i] ;
b = i - 1;
Q. 1. The following is a function of some class which while ( ? 3? > = 0 && t < a [b])
sorts an integer array a[ ] in ascending order using
selection sort technique. There are some places in
the code marked by 717, 727, 737, 747, 75? which a [b + 1] = a [b]
134 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
?4? {
I
n = nn;
? 5 ? = t; }
void fillarrayO
{ arr = new int[n];
}
System.out.println("Enter " + n +
(i) What is the expression or statement at ?1? "elements");
(ii) What is the expression or statement at ?2? for(inti = 0;i < n;i + + )
(iii) What is the expression or statement at ?3? arr[i] = x.nextlnt();
(iv) What is the expression or statement at ?4? }
(v) What is the expression or statement at ?5? void sort()
Ans. (i) int m = a.length; {
int t;
(ii) i=1
for(int i = 0;i < n-l;i + + )
(iii) b> = 0
for(int j = 0;j < n-l-i;j + + )
(iv) b ;— { if (arr[ j] > arr[ j + l ])
(v) a[b] { t = arr[ j];
arr[j] = arr[ j + l];
Very Long Answer Type
arr[j + l ] = t;
Questions (10 marks) }
Q. 1. Design a class BinSearch to search for a particular }
value in an array. }
Some of the members of the class are given below: _
int bin search(int l,int u, int v )
{
Classname : BinSearch
int m = (l + u)/2;
Data members/instance variables:
if (arr[m] = = v)
arr[ ] : to store integer elements
return m;
n : integer to store the size of the else if (l > u)
array return -1;
Member functions/methods: else if (arr[m] > v)
BinSearch ( int nn) : parameterized constructor to _
return bin search(l,m-l,v);
initialize n = nn else
void fillarray( ) : to enter elements in the array _
return bin search(m + l,u,v);
void sort( ) : sorts the array elements in }
ascending order using any static void main()
standard sorting technique {
_
int bin search(int l,int u,int v) BinSearch obj = new BinSearch(5);
: searches for the value V obj.fillarrayO;
using binary search and obj.sort();
recursive technique and System.out.printlnf location: " +
returns its location if found _
obj.bin search(0,4,20) );
otherwise returns -1 }
Define the class BinSearch giving details of the }
constructor ), void fillarray( ), void sort( ) and Q. 2. A class Admission contains the admission numbers
int bin_search(int,int,int). Define the main( ) of 100 students. Some of the data members/member
function to create an object and call the functions functions are given below: @1 [ISC 2015]
accordingly to enable the task.
Ans. import java.util.*; Class : Admission
class BinSearch Data member/instance variable:
{ Adno[] : integar array to store
int arr[]; admission numbers
int n; Member functions/methods:
static Scanner x = new Scanner(System.in); Admission ( ) constructor to initialize the
BinSearch(int nn) array elements

These questions are for practice and their solutions are available at the end of the chapter
I void fill Array : to accept the elements of the { m = mm;
PROGRAMMING IN JAVA 135

0 array in ascending order n = nn;


mat = new int[m][n];
int : to search for a particular
}
binSearch ( int 1, admission number ( v ) using
void input ()
int u, int v ) binary search and recursive
S y s t e m .o u t .p r i n t l n ("E n t e r
technique and returns 1 if elements");
found otherwise returns - 1 for (int i = 0; i < m;
Specify the class Admission giving details of i++)
the constructor, void fillArray ( ) and int bin for(int j = 0; j < n; j++)
Search ( int, int, int) . Define the main() function to mat[i][j]=sc.nextlnt();
create an object and call the functions accordingly }
to enable the task . void display( )
Q. 3. A class Shift contains a two dimensional integer
array of order (m x n) where the maximum values for(int i = 0; i < m; i++)
of both m and n is 5 . Design the class Shift to { System.out.println();
shuffle the matrix (i.e., the first row becomes the for(int j = 0; j < n; j++)
last, the second row becomes the first and so on ) . System.out.print(mat[i][j]
The details of the member of the class are given + "\t");
below: [ISC 2016]
}
Class Name : Shift
void cyclic (Shift P)
Data member/instance variable: { for(int i = 0; i < m; i++)
mat [][] : stores the array element for(int j = 0; j < n; j++)
m : integer to store the number { if(i! = 0)
of rows mat[i 1][j] = P.mat[i]
[j];
n : integer to store the number
else
of columns
mat[m 1][j] = P.mat[0]
Member functions/methods: [j];
Shift( int mm, : parameterized constructor }
int nn ) to initialize the data }
member m = mm and n = static void main ()
nn { Shift x = new Shift (3, 4);
void input ( ) : enters the elements of the Shift y = new Shift (3, 4);
array x.input( );
void cyclic : enables the matrix of the y.cyclic(x);
( Shift P ) project (P ) to shift each row x.display();
upwards in a cyclic manner y.display();
and store the resultant }
matrix in the current object }

void display : display the matrix [ISC Marking Scheme 2016]


o elements
Specify the class Shift giving details of the Examiner's Comment
constructor(), void input(), void cyclic( Shit) and
void display() . Define the main() function to Most candidates answered this question correctly.
create an object and call the methods accordingly The cyclic () function was not done properly by
to enable the task of shifting the array elements . some candidates. Various methods/techniques
Ans . import java.util.Scanner; were used to shift the rows in the matrix. Several
public class Shift candidates did it directly without using the
{ static Scanner sc = new Scanner parameterized object. Some had problems with
(System.in); the passing of object. Some had problems with
int mat[ ][ ]; the passing of object to the function. Constructor
and the main () method was answered properly by
int m, n;
candidates.
Shift(int mm, int nn)
136 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class-XII
I
Mixer (int nn) constructor to assign n = nn
Answering Tip void accept ( ) to accept the elements of
the array in ascending order
w More practice must be done in passing of objects without any duplicates
to a function through parameters.
Mixer mix to merge the current object
w Working on double dimensional arrays (matrix) (Mixer A) array elements with the
must be learnt with various examples.
parameterized array and
return the resultant object
Q. 4. A class Composite contains two dimensional void display( ) to display the elements of
array of order [m x n]. The maximum values the array
possible for both 'm' and 'n' are 20. Design a class
Composite to fill the array with the first (m x n) Specify the class Mixer giving details of the
constructor(int), void accept(), Mixer mix(Mixer)
composite numbers in column wise. The details
and void display(). Define the main() function to
of the members of the class are given below:
create an object and call the function accordingly
J
||[ISC Specimen Question Paper 2016] to enable the task.
Class Name : Composite Ans. import java.util.*;
Data member/instance variable: class Mixer
{ int arr[ ];
arr[][] : stores the composite
int n;
numbers column wise static Scanner sc=new Scanner
m : integer to store the number (System.in);
of rows Mixer (int nn)
n : integer to store the number { n = nn;
of columns arr=new int[n];
Member functions: }
void accept ()
Composite (int : to initialise the size of the
{ System.out.println("Enter "+n+"
mm, int nn ) matrix m = mm and n = nn
elements in ascending order");
int isComposite : returns 1 if number is
for(int i = 0; i < n; i++)
(int p ) composite otherwise returns
arr[i] = sc.nextlnt() ;
0
void fill ( ) : to fill the elements of the
Mixer mix (Mixer A) OR
array with the first ( m x
Mixer mix (Mixer A)
n ) composite numbers in
{ Mixer B = new Mixer(n+A.N);
column wise
{ Mixer B = new Mixer(n+A.N);
void display ( ) : display the array in a
int x=0, y=0, z=0; int x=0;
matrix form
while(x < n && y < A.n)
Specify the class Composite giving details of for(int i=0 ; i<n; i++)
the constructor (int, int ), int is Composite (int ),
{ if ( arr[x] > A.arr [y])
void fill( ) and void display )). Define a main ( )
B.arr[x++]=arr[i];
function to create an object and call the function
{ B.arr[z]=A.arr[y];
accordingly to enable the task.
for(int j =0;j<A.n;j++)
.
Q 5. A class Mixer has been defined to merge two y++;
sorted integer arrays in ascending order. Some of
B.arr[x++]=A.arr[j];
the members of the class are given below:
[ISC 2014] I return B;
else
Class Name Mixer B.arr[y] = arr[x];
Data member/instance variable: x++;
int arr[] to stores the elements of an 1
array z++;
int n to store the size of the array
Member functions

These questions are for practice and their solutions are available at the end of the chapter
I PROGRAMMING IN JAVA
The details of the members of the class are given
137

while (x<n) below:


B.arr[z++] = arr[x++]; Class Name Matrix
while (y<A.n)
Data members/instance variables
B.arr[z++] =A.arr[y++];
arr[][] stores the matrix element
return B;
i m integer to store the number
void display!) of rows
{ for(int i = 0;i<n; i++) n integer to store the number
System.out.println(arr[ i]); of columns
} Member functions
static void main() Matrix (int mm, to initialise the size of the
{ Mixer P=new Mixer(4); int nn) matrix m = mm and n = nn
Mixer Q=new Mixer(3); void fillarray () to enter the elements of the
Mixer R=new Mixer(7); matrix
P.accept(); Matrix SubMat subtracts the current
( Matrix A) object from the matrix of
Q.accept();
parameterized object and
R = P.mix (Q);
return the resulting object
R . display ()
void display () display the matrix elements
! Specify the class Composite giving details of
[ISC Marking Scheme 2014] the constructor (int, int), void fillarray( ). Matrix
SubmMat(Matrix) and void display(). Define a
main( ) function to create an object and call the
Examiner's Comments function accordingly to enable the task.
Ans. import java.io.*;
w Common errors made by candidates in answering
this question were as follows: (i) wrong declaration class Matrix //class name
of array; (ii) significance of data members were {
not clear; (iii) passing objects to the function and int arr[] [] ;
accessing its members by the dot operator; (iv) int m , n ;
creating a new local object and returning the object.
Matrix (int mm , int nn) //constructor
Some candidates sorted the array in accept ( ).
{
w In some cases, 3 different arrays were created
m = mm ;
instead of creating objects. A few candidates
used the same object to store the answer without n = nn ;
creating a local object. Some were confused with arr = new int [m] [n] ;
merging or mixing the two arrays. }
void fillarray ( ) throws IOException
//method
Answering Tip {
BufferedReader br = new BufferedReader
w Detail knowledge of handling/passing objects to
(new Input StreamReader (System.in)) ;
functions must be there. It must be emphasized
that only the mentioned technique should be System.out.println(“ Enter the elements
written. More practice should be done in writing of the matrix ”) ;
the main function with each and every program. for (int i = 0; i < m ; i++)
Practice should be done in both single and double {
dimension programs. for (int j = 0; j < n ; j++)
{
Q. 6. A class Matrix contain a two-dimensional integer arr [i] D ] = Integer. parselnt (br.
array of order [m x n]. The maximum value readLineQ) ;
possible for both 'm' and 'n' is 25. Design a class
Matrix to find the difference of the two matrics.
}
138 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Class Name Combine


I
Matrix SubMat (Matrix A)
Data members/instance variables
com[] integer array
Matrix B = new Matrix (m , n);
for (int i = 0 ; i < m ; i++) size size of the array
{ Member functions/methods
for int j = 0; j < n ; j++) Combine(intnn ) parameterized constructor
to assign size = nn
B.arr[i] [j] = arr[i] [ j] - A.arr[i] [j]; void inputarray () to accept the array elements
void sort () sorts the elements of
combined array in ascending
return B ; order using the selection
} sort technique
void display ( ) void mix combines the parameterized
(Combine A, object arrays and stores the
System.out.println(“The difference of Combine B ) result in the current object
both two matrices is ”) ; array along with duplicate
for (int i = 0 ; i < m ; i++) elements, if any
{ void display () display the array elements
for (int j = 0; j < n ; j++) Specify the class Combine giving details of the
constructor(int). void inputarray(). void sort().
System.out.print(arr[i][j] + “\t”) ; void mix(Combine) and void display(). Also
define the main() function to create an object and
call the methods accordingly ot enable the task.
System.out.printlnO ;
Ans. import java.io.*;
}
class Combine //class name Combine
}
public static void main (String[] args)
int com[] , size;
throws IOException
Combine ()
int m = 0, n = 0;
BufferedReader br = new BufferedReader
Combine (int nn) //constructor
(new InputStreamReader(System.in)) ;
System.out.println(“ Enter number of
rows and column: (Maximum limit = size = nn ;
25) ”) ; com = new int [nn] ;
m = Integer. parseInt (br. readLine ());
n = Integer. parseInt (br.readLine ()) ; void inputarray ( ) throws IOException
Matrix M = new Matrix (m , n) ;
M .fillarray ( ) ; //calling method BufferedReader br = new BufferedReader
Matrix K = new Matrix (m , n) ; (new InputStreamRader(System.in)) ;
K.fillarray ( ) ; //calling method //BufferedReader used to input the value
Matrix p = new Matrix (m , n); //InputStreamReader reads bytes and
P = M.SubMat (K) ; decodes them into
P.display 0 ; //calling method //character
} for (int i = 0 ; i < com.length ; i++)
}
Q. 7. A class Combine contains an array of integers com[i] =Integer. parseInt (br.readLine ( )) ;
which combines two arrays in a single array
including the duplicate elements, if any, and sorts
the combine array. Some of the members of the void sort ( )
class are given below: [ISC 2012]
I for (int i = 0; i < com .length ; i++)
PROGRAMMING IN JAVA
if ( j < len 2)
139

for (int j = i + 1; j < com.length ; j++) while ( j < len 2)


{
if (com [i] > com [j]) com [k ++] = B.com[j] ;
{ j++;
int temp = com[i]; }
com [i] = com[j] ;
com[j] = temp ;
public static void main (String [] args]
throws IOException
}
} Combine obj = new Combine (2) ;
void display ( ) //creating object
Combine objl = new Combine (3) ;
for (int i = 0; i <com.length ; i++) Combine obje2 = new combine ( ) ;
System.out.println(“ Enter First Array”) ;
System.out.println(com [i]) ; obj.inputarray ( ); //calling method
System .out.printlnfEnter Second Array”) ;
} objl .inputarray ( ) ;
void mix (Combine A, Combine B) obj.sortO ;
objl .sortO ;
int lenl , len 2; System.out.println(“ Display Array 1 is:”):
lenl = A.com.length ; obj.display ();
len 2 = B.com.length ; System.out.println(“ Display Array 2 is:”);
com = new intjlen 1 + len 2] ; objl .display ( ) ;
int i, j, k ; obj2.mix (obj, objl) ;
i = 0; j = 0; k = 0; System.out.println(“ Sorted Array is:”);
while (i < lenl && j < len 2) obj2.display () ;
{ }
if (A.com [i] < B.com [j]) }
Q. 8. Class Binary contains an array of n integers (n
com [k] = A.comji]; < = 100) that are already arranged in ascending
i ++; order. The subscripts of the array elements vary
from 0 to n - 1. The data member and member
function of the class Binary are given below:
else [ISC 2009]

com [k] = B.com[j] ; Class Name Binary


j++; Data members/instance variables
a[] integer array of 100
elements
k++;
n size of the array
if (i < lenl) 1 location of the lower bound
{ u location of the upper bound
while (i < lenl) Member functions
Binary (int nn) constructor to initialise in
com [k++] = A.comji] ; size n = nn and the other
instance variables
i++ ;
void readdata ( ) to fill the elements of the
array in ascending order
140 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class-XII
int binary _ returns the location of the
I
search (int v) value (v) to be searched in else if (a [m ] < v)
the list by binary search {
method using the Recursive
technique. 1 = m + 1;
The function returns - 1 if
the number is not present _
m = binary search (v) ;
in the given list.
else
(i) Specify the class Binary giving the details
{
of the constructor, void readdata() and int
_ .
binary search (int) You need not to write the return (m) ;
main function .
_
(ii) State the Best Case in the recursive function
binary search() . else return (-1) ;
.
Ans (i) import java.io.*; }
class Binary //class name Binary }
{ (ii) The best case in the function binary search _
int a [ ] is the condition if (1 < u) when condition
is evaluated to be false, then function will
int n , 1, u ;
not call itself and return statement will be
Binary (int nn) executed .
{ ..
Q 9 A transpose of an array is obtained by
a = new int [100] ; interchanging the elements of the rows and
n = nn ; columns .
for (int i = 0; i < n ; i++) A class Transarray contains a two dimensional -
{ integer array of order [m x n]. The maximum
a [i] = 0; value possible for both 'm' and 'n' is 20. Design
} a class Transarray to find the transpose of a given
matrix. The details of the members of the class are
1 = 0; given below: [ISC 2009]
u = n - 1;
Class Name Transarray
void readdata ( ) throws IOException Data members/instance variables
{ arr[ ][ ] stores the matrix elements
BufferedReader br = new m integer to store the number
BufferedReader of rows
(new InputstreamReader (System.in)) ; n location of the lower bound
//to input the value of array
Member functions
System.out.println(“ Enter the value
in ascending order ”) ; Transarray ( ) default constructor
for (int i = 0 i < n ; i++)
; Transarray (int to initialise the size of the
{ mm, int nn ) matrix, m = mm, n = nn
a [i] = integer.parsentlnt void fillarray ( ) to enter the elements of the
(br.readLineO) ; matrix
} void transpose to find the transpose of a
(Transarray A ) given matrix
_
int binary search (int v) void disparray display the array in a
{ matrix form
int m = - 1; Specify the class Transarray giving the details of
if (1 < u) the constructors, void fillarray(), void transpose
{ (Transarray) and void disparray (). You need not
to write the main function.
m = (1 + u) / 2 ;
Ans. import java.io.*;
if (a [m] > v)
class Transarray //classname Transarray
{
{
u = m - 1;
I int arr [ ][ ];
PROGRAMMING IN JAVA 141

int m , n ; //declare array int i, j;


Transarray ( ) //constructor System.out.println(“The transported
value of array”) ;
arr = new int [ 20] [20]; //initialise array for (i = 0; i < m ; i++)
m = 20;
n = 20; for ( j = 0; j < n ; j++)
{
Transarray (int mm , int nn) // method System.out.print(“\t” +arr[i][j]) ;
}
int i, j; System.out.print( ) ;
m = mm ;
n = nn ;
arr = new int [mm] [nn] ;
for (i = 0; i < m ; i++) Q. 10. A class PrimeFac contains an array of 50 integers.
Some of the members of the class are given below:
[ISC 2009]
for ( j = 0; j < n ; j++)
Class Name PrimeFac
arr [i][ j] = 0; Data members/instance variables
} num [ ] array to store integers
} freq [ ] array to store the frequency of
} prime factors of numbers
void fillarray ( ) throws IOException Member functions
Prime Fact () constructor to initialise array
int i, j; elements to 0
BufferedReader br = new BufferedReader void enter () to enter values into array
(new InputStreamReader(System.in) ; num[]
System.out.println(“ Enter the values ”) ; void frefac ( ) to determine the frequency of
for (i = 0; i < m ; i++) prime factors of the numbers
{ stores in num[ ] and assign it
for 0 = 0; j < n ; j++) to freq [ ]
arr [i] [ j] = Integer. parselnt (br. void disp( ) to display both the arrays
ReadLine 0 ) ;
Specify the class PrimeFac giving the details of
} constructor, void enter]), void frefac() and void
} disp(). You need not to write main function.
void transpose (Transarray A) Ans. import java .io.*;
clas PrimeFac
int i, j;
if (n ==A.m && m ==A.n) int num [ ] ;
{ int freq [ ] ;
for (i = 0; i < A.m ; i++) Prime Fac ( ) // constructor

for 0 = 0; j < A.n; j++) num = new int [50]


//declaration array dynamically
arr [i] [j] = A.arr[j] [i] ; freq = new int [50] ;
for (int i = 0; i < 50 ; i++)

} num [i] = 0;
} freq [i] = 0 ;
void disparray ( ) }
142 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 11. A class Collection contains as array of 100
I
void enter Q throws IOException integers. Using the following class description
create an array with common elements from two
integer arrays. Some of the members of the class
BufferedReader br = new BufferedReader
(new InputStreamReader(System .in)) ;
are given below: $
[ISC 2008]
int i; Class Name Collection
for (i = 0; i < 50; i++) Data members/instance variables
arr[ ] integer array
System.out.prin tin len length of the array
(“Enter the number ”) ;
Member functions
num [i] = Integer.parselnt
(br. readLine ( )) ; Collection ( ) default constructor
} Collection parameterized constructor to
} (int) assign the length of the array
void frefac( ) void inparr ( ) to accept the array elements
Collection returns a Collection
int i; common containing the common
for (i = 0; i < 50; i++) ( Collection ) elements of current Collection
object and the Collection
object passed as a parameter
freq [i] = 0;
void arrange () sort the array elements of the
for (int j = 2; j < num [i] ; j++)
object containing common
elements in ascending order
if (num [i] % j==0 && isprime( j) ==l) using sorting technique.
void display () displays the array elements
freq [i] += 1;
Specify the class Collection giving the details of
the constructors, void inparr() and void arrange (),
Collection common (Collection). You need not to
} write the main function.
} Q. 12. Design a class change to convert a decimal
int isprime (int n) //method number to its equivalent in base 16 and to convert
it back to its decimal form, e.g., [ISC 2007]
for (int i = 2; i < n ; i++) (i) The decimal number 35 is 23 in base 16.
(ii) The decimal number 107 is 6B in base 16.
if (n %i==0) Some of the members of the class are given below:
return 0 ;
Class Name Change
}
Data members/instance variables
return 1;
} a[ ] integer type array
void disp( ) //method n integer to be converted to base 16
Member functions
System.out.prin tin change ( ) constructor to assign 0 to
(“ Number\t frequency”) instance variables
for (int i = 0; i < 50 ; i++) void input accept integer to be converted to
0 base 16
System.out.prin tin void to convert decimal integer to
(num [i] + “\t” + frq[i]) ; hexadeci hexadecimal form
} (int )
void to convert hexadecimal number
decihexa () back to decimal form

These questions are for practice and their solutions are available at the end of the chapter
I Specify the class change giving the details of
PROGRAMMING IN JAVA
if (a [i] > 0)
143

the constructor and the functions void input(). break;


void hexadeci(int) and void decihexa(). The main
functions need to be written.
if (i < 10)
Ans. import java .io.*;
class change //class name
for (int k = i; k < = 9; k ++)
{
int a [ ] ;
s = s + a [k]*((int) Math.pow
int n ;
(16, 9 - k));
change ( ) //constructor
System.out.println(s);
a = new int [10] ;
}
n = 0;
}
for (int i = 0; i < = 9; i++)
public static void main (string args [])
a [i] = 0;
throws IOException
void input ( ) throws IOException
change c = new changeO ;
c.input( ) ;
BufferedReader br = new BufferedReader
c.hexadeci(c.n) ;
(new InputStreamReader(System .in)) ;
c.decihexa ( ) ;
System.out.println(“ Enter the integer
number to be converted to base 16 ”) ; }
n = Integer. parseInt (br.readLine ( )) ; }
} Q. 13. A class Rearrange has been defined to insert an
element and to delete an element from an array,
void hexadeci (int n) //method some of the members of the class are given below:
[ISC 2007]
int r, i = 9;
while (n > 16) Class Name Rearrange
Data members/instance variables
r = n %16; a[ ] integer type array
n = n/16;
n size of array (integer )
a [i ] = r;
} Post position of insertion (integer)
a [i] = n ; Pos2 position of deletion (integer )
for (int k = i; k < = 9; k ++) item item to be inserted (integer )
Member functions
if (a [k] > 9)
void enter( ) to enter size, array elements and
to display the entered elements
int t = a [k] - 10;
System.out.print ((char)(65 + t)) ; void insert )) to accept element (item ) to be
} inserted, position of insertion
else and insert he element (item) at
the position of insertion
system .out. print(a [k]) ;
void displQ to enter size, array after item
system .out. println( ); is inserted
} void disp2() to display array after item is
void decihexa ( ) //method deleted
void remove to accept the position of
int s = 0, i; 0 deletion and deletion element
for (i = 0; i < = 9; i++) (item) at the position of
deletion
144 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Specify the class Rearrange giving details of the
I
function void enter ( ). void insert ( ). void disp System.out.prin tin
(). void disp2 () and void remove ( ). The main (“ Invalid position ”) ;
function needs to be written
}
Ans. import java .io*;
else
class Rearrange
n ++;
int a [ ] , n , Posl , Pos 2 , item ;
for (int k = n ; k > Posl - 1; k- -)
void enter ( ) throws IOException
{
a [k] = a [k - 1] ;
InputStreamReaderin = new Inputstream
}
Reader (System.in) ;
BufferedReader br = new Buffered a [Posl - 1] = item ;
Reader (in) ; displQ ;
System.out.println(“ Enter size of array”) ;
n = Integer. parseInt (br.readLine ( )) ;
a = new int [n] ; void remove ( ) throws IOException
System.out.println
( “ Enter elements of array") ; Input StreamReader in = new
for (int i = 0; i < n ; i++) InputStream Reader (System.in) ;
a [i] = Integer. parselnt (br. readLine ()); BufferedReader br = new BufferedReader
System.out.println M;
( “ Element of array are") ; System.out.println
for (int i = 0 ; i < n ; i++) (“Enter position to delete item ”) ;
System.out.println(a [i]) ; if (Pos 2 < 0 || Pos2 > n)
}
void displ () System.out.println
(“ Invalid position ”) ;
System.out.println }
(“Aray after Insertion ”) ; else
for (int i = 0; i < n ; i++)
System.out.println(a [i]) ; n ; —
} for (int k = Pos 2 - 1; k < n ; k ++)
void disp 2 ( )
a [k] = a [k + 1] ;
System.out.println }
(“Array after Deletion ”) ; disp2 ( ) ;
for (int i = 0; i < n ; i++) }
System.out.println(a [i]) ; }
public static void main (String args [ ])
void insert ( ) throws IOException throws 10 Exception

InputStreamReader in = new Rearrange r = new Rearrange ( ) ;


InputStream Reader (System.in) ;
renter ( ) ;
BufferedReader br = new BufferedReader
r.insert ( ) ;
M; r. remove ( ) ;
System.out.println
(“Enter item to insert”) ;
item = Integer. parselnt (br.readLine ( ));
System.out.println (“ Enter position ”) ; Q. 14. A class Sort contains an array of 50 integers. Some
Posl = Integer. parselnt (br. readline ()) ; of the member functions/data members are given
below: [ISC 2006]
if (Posl > n)
I Class Name Sort
PROGRAMMING IN JAVA
i - -;
145

break;
Data members/instance variables
arr [ ] integers
}
item numbers to be searched in the
if (k ==0)
array
{
Member functions/methods
arr [i] = x ;
void indata ( ) input 50 integers (no
to
duplicate numbers are to be
entered)
void to sort the array in ascending
void bubsort ( ) // method
bubsort( ) order using the bubble sort
technique and to display the
sorted list int t , i;
void to input item and search for for (i = 0; i < 49; i++)
binsearch ( ) it using the binary search
technique, if found to print the for (int j = 0; j < 49 - i; j++)
item searched and its position
in the sorted list, otherwise to if (arr [ j] > arr [ j + 1])
print an appropriate message. { t = arr[ j] ;
Specify the class Sort giving the details of the arr [ j] = arr[j + l] ;
functions void inpdata(). boid bubsort() and void arr[j + 1] = t;
binsearch(). The main function need not to be
}
written.
}
Ans. import java .io.*;
class Sort //class name sort
System.out.println (“Sorted Array”)
for (i = 0; i < = 49; i++)
int item ;
int arr[ ] ;
System.out.pritln(arr [i]) ;
Sort ( ) //constructor
//printing the array
}
arr = new int [50]
}
//declare array size dynamically
void binsearch ( ) throw IOException
void inpdata ( ) throw IOException
InputStreamReader inp = new
InputstreamReader (System.in) ;
InputStreamReader inp = new Input
BufferedReader br = new BufferedRader
StreamReader (System.in) ;
(inp) ;
BufferedReader br = new BufferedReader
int b, e, m , pos = - 1;
(inp) ;
b = 0;
int x , k ;
e = arr.length - 1;
for (int i = 0; i < = 49 ; i++)
System.out.println(“ Enter Item to be
{
search ”) ;
k = 0;
item = Integer. parseInt (br. readLine ());
x = Integer. parseInt (br. readLine ()) ;
while (b <= e)
for (int m = 0; m < = i; m ++)
m = ( b + e) / 2 ;
if (arr[m] ==x)
if (arr[m] ==item)

System.out.println
pos = m + 1;
( “ Duplicate Item ’’) ;
break;
k = 1;
146 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
else Class Name IndexArray
I
Data members/instance variables
if (arr[m ] < item)
b = m + 1; ar [ ] integer
else Member functions/method
e = m - 1; indexarray ( ) to assign the code to 0
}
void sortarr ( ) to sort the array variable
using selection sort
if (pos== 1) — technique
System.out.println (“ Item Not Found”) ;
else int to search and return 1 if an
System.out.println(“ Item found at” binarysearch employee code is found in
+pos) ; (int[ ]. int) the array object otherwise
return 0
Specify the class indexed array giving details of
Q. 15. Class indexed array contains the employee code the constructor, void sortarr (), int binarysearch ().
of 100 employees. Some of the member function/ You may assume, other assumes, other functions
are written for you and you do not need to write
data members are given below: |§|[ISC 2005]
the main function.

Strings
Topic -4 Concepts covered: Strings (declaration and initialization; String class
methods and functions; String buffer

>
m Revision Notes
In java, string is basically an object that represents sequence of char values. An array of characters works same as
java string. For example:
char[] ch ={' j' , 'a ' , V / a ' / t' / p' / o' / i' / n' / t'};
String s=new String(ch);
is same as:
String s="javatpoint” ;
> Java String class provides a lot of methods to perform operations on string such as compare(), concat(), equals(),
split(), length(), replace(), compareTo(), intern(), substring() etc.
> The java.lang.String class implements Serializable, Comparable and CharSequence interfaces.
Serializable Comparable Charsequence
*

implements

String
> How to create String object?
There are two ways to create String object:
By string literal
By new keyword
(1) String Literal
Java String literal is created by using double quotes. For Example:
String s = "welcome";
Each time you create a string literal, the JVM checks the string constant pool first. If the string already exists
in the pool, a reference to the pooled instance is returned. If string doesn't exist in the pool, a new string
instance is created and placed in the pool. For example:

These questions are for practice and their solutions are available at the end of the chapter
I String sl ="Welcome";
PROGRAMMING IN JAVA 147

String s 2 ="Welcome";//will not create new instance


(2) By new keyword
String s =new Stringf Welcome"); //creates two objects and one reference variable
In such case, JVM will create a new string object in normal (non pool) heap memory and the literal "Welcome"
will be placed in the string constant pool. The variable s will refer to the object in heap (non pool).
Java String class methods
The java.lang.String class provides many useful methods to perform operations on sequence of char values.
No. Method Description
1. char charAt(int index) returns char value for the particular index
2. int lengthQ returns string length
3. static String format (String format, object... args) returns formatted string
4. static String format(Locale 1, String format, returns formatted string with given locale
Object... args)
5. String substring(int beginlndex) returns substring for given begin index
6. String substring(int beginlndex, int endlndex) returns substring for given begin index and end
index
7. Boolean contains(CharSequence s) returns true or false after matching the sequence
of char value
8. static String join(CharSequence delimiter, Char returns a joined string
Sequence... elements)
9. Static String join (CharSequence delimiter, returns a joined string
iterable < ? extends CharSequence > elements)
10. Boolean equals(Object another) checks the equality of string with object
11. Boolean is Empty() checks if string is empty
12. String concat(String str) concatenates specified string
13. String replace(char old, char new) replaces all occurrences of specified char value
14. String replace(CharSequence old, CharSequence replaces all occurrences of specified
new) CharSequence
15. static String equals!gnoreCase(String another ) compares another string. It doesn't check case.
16. String[] split(String regex) returns splitted string matching regex
17. String[] split(String regex, int limit) returns splitted string matching regex and limit
18. String intemQ returns interned string
19. int indexOf (int ch) returns specified char value index
20. int indexOf (int ch, int fromlndex) returns specified char value index starting with
given index
21. int indexOf (String substring) returns specified substring index
22. int indexOf (String substring, int fromlndex) returns specified substring index starting with
given index
23. String toLowerCaseQ returns string in lowercase.
24. String toLowerCase(Locale 1) returns string in lowercase using specified
locale.
25. String toUpperCaseQ returns string in uppercase.
26. String toUpperCase(Locale 1) returns string in uppercase using specified
locale.
27. String trim() removes beginning and ending spaces of this
string.
28. static String valueOf (int value) converts given type into string. It is overloaded.
148 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
|Key Terms
> String Buffer class is part of java.long package.
> String defines a sequence of characters. The String type is used to declare string variables. You can also declare
arrays of strings. A quoted string constant can be assigned to a String variable. A variable of type String can be
assigned to another variable of type String. You can use an object of type String as an argument to println( ).
> Java provides three classes as:
Character class can hold only single character.
String class can hold strings that cannot be changed.
String Buffer class can hold strings that can be changed or modified.
Substring( ), string concatenation as concat( ) and string length as length( ) etc. are the operations defined on
string.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. Which of the following class cannot be used for increases from its current capacity, it increases the
handling character data in Java? capacity by (oldcapacity *2) + 2.
(A) Character (B) String Q. 5. Which of the following statement(s) is/are true:
(C) StringBuffer (D) None of these (i) string is immutable
Ans. Option (D) is correct. (ii) StringBuffer object is mutable
Q. 2. Which of the following statements about (A) (i) is true
Java (B) (ii) is true
strings is true?
(C) both (i) and (ii) are true
(i) Java strings are objects. (D) none of (i) and (ii) are true
(ii) They cannot have literal values. Ans. Option (C) is correct.
(iii) They can be used in assignment statements. Explanation: String is immutable whereas
(iv) They are primitive data types. StringBuffer and StringBuilder are mutable classes.
(v) new keyboard is required to create a string. Q. 6. To join two strings strl & str2 (Such that str2
(B) (i) & (iii)
follows strl), select the statement you would write:
(A) All are true
(A) str = strl +str2;
(C) (i), (ii) & (iii) (D) (i), (ii) & (iv)
(B) str = strl.concat(str2);
Ans. Option (B) is correct.
(C) str = str2.concat(strl );
Q. 3. StringBuffer str= new StringBuffer (7) ; (D) both (A) and (B)
(A) invalid statement Ans. Option (D) is correct.
(B ) used to reserve memory for 7 characters with Explanation: Java String concatenation operator
the name str. ( + ) is used to add strings, and the String concat()
(C) used to create a string str which is initialized method concatenates the specified string to the
to 7. end of current string.
(D) None of these. Q. 7. StringO
Ans. Option (B) is correct. (A) initializes a string variable.
Q. 4. Capacity ( ) of StringBuffer (B) constructs a new string with the value" ".
(A) returns total number of characters in the (C) checks if a string is valid or not.
string. (D) all of these
(B ) returns total bytes of the string. Ans. Option (B) is correct.
(C) is same as length() Explanation: String is basically an object that
(D) returns the maximum number of characters represents sequence of char values. String ()
that can be inserted in the string. constructs the new string with value " ".
Ans. Option (D) is correct. Q. 8. When a new string is constructed using string(),
Explanation: The capacity() method of Java the value stored in the new string is:
StringBuffer class returns the current capacity of (A) Null
the string buffer. The capacity refers to the total (B) No characters but not null
amount of characters storage size in string buffer. (C) " "(blank space)
An empty StringBuffer class contains the default 16 (D) None of the above
character capacity. If the number of the character Ans. Option (B) is correct.
I
Q. 9. Instances or objects of can hold
PROGRAMMING IN JAVA
Ans. Option (A ) is correct.
149

immutable string. Explanation: The String objects are cached in the


(A) String class (B ) Character class String pool, and it makes the String immutable.
(C) StringBuffer class (D) string class

SUBJECTIVE TYPE QUESTIONS


Specify the class Check giving details of
Very Short Answer Type the constructor, void acceptword( ), Boolean
<©> Questions (1 marks) palindrome( ) and void display( ). Define the
main( ) function to create an object and call the
Q. 1. Write the statement in Java to extract the word functions accordingly to enable the task.
"MISS" from the word "SUBMISSION".
[ISC Sem-1 Paper 2021-22]
[ISC Sem-1 Paper 2021-22]
Ans. import java .util . ;
*
Ans. str.substring(3, 7);
class Check
Explanation: A part of String is called substring.
In other words, substring is a subset of another
String. Java String class provides the built-in String wrd ;
substring() method that extract a substring from int len ;
the given string by using the index values passed Check ()
as an argument.
Q. 2. What is the output of the statement given below? wrd =
System.out.print(“ FAN ” + (“AUTOMATIC ”. len = 0;
charAt (5) ) ) ; [ISC Sem-1 Paper 2021-22]
Ans. FANA void acceptword( )
Explanation: charAt() function extracts the element
& + is used for concatenation purpose. Scanner sc = new Scanner(System.in) ;
Long Answer Type System.out.println(“ Enter the word to
Questions (5 marks) check ”) ;
wrd = sc.nextLine ( ) ;
Q. 1. Design a class Check which checks whether a len = wrd .length ( ) ;
word is a palindrome or not. (Palindrome words
}
are those which spell the same from either ends).
Boolean palindrome] )
Example: MADAM, LEVEL etc.
The details of the members of the class are given String s = “ “ ;
below:
char ch ;
Class name : Check
for (int i=len-l ; i> =0 ; i- -)
Data members/instance variables:
wrd : stores a word ch = wrd .charAt (i);
len : to store the length of the s = s + ch;
word }
Methods/Member functions: if (s.equalsIgnoreCase (wrd))
Check] ) : default constructor return true ;
void acceptword] ) else
: to accept the word return false ;
Boolean palindrome ( ) }
void display] )
: checks and returns 'true' if
the word is a palindrome
otherwise returns 'false' acceptvoid( ) ;
void display] ) : displays the word along if (palindrome( ) == true)
with an appropriate System.out.println(wrd + “ is a
message palindrome word .”) ;
}
150 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
public static void main (String arr[]) }
I
void toggle ()
Check ob = new Check ( ) ;
ob.display ( ) ; for (int c=0;c<len ; c++)
}
} char k =str.charAt (c) ;
Q. 2. Design a class Toggle which toggles a word by if (Character.isUpperCase(k))
converting all upper case alphabets to lower case newstr+=Character.toLowerCase (k) ;
and vice versa. else if (Character.isLowerCase (k))
Example: The word "mOTivATe" becomes newstr+=Character.toUpperCase (k) ;
"MotIVatE"
else
The details of the members of the class are given
newstr+=k ;
below:
}
Class name : Toggle
}
Data members/instance variables:
void display ()
str stores a word
newstr stores the toggled word
System.out.print(newstr) ;
len to store the length of the
word
Methods/Member functions: public static void main (String[] args)
Toggle( ) default constructor
void readword( ) to accept the word Toggle ob=new Toggle 0 ;
void toggle ( ) converts the upper case ob. readword () ;
alphabets to lower case and ob.toggleO ;
all lower case alphabets to ob.displayQ ;
upper case and stores it in
newstr
void display( ) : displays the original word
Q. 3. A class SortWord has been defined with the
along with the toggled
word following details: [ISC 2009]
Specify the class Toggle giving details of the Class Name SortWord
constructor, void readword( ), void toggle( ) and Data members/instance variable
void display( ). Define the main( ) function to
create an object and call the functions accordingly txt stores the word
to enable the task. [ISC Sem-1 Paper 2021-22] len stores the length of the
Ans. import java .io. ;
* word
import java .util .*; Member functions
public class Toggle SortWord ( ) default constructor
void readTXt ( ) to accept the word in lower
String str, newstr; case
int len ; void sortTxt] ) to sort the word in
alphabetical order of
Toggle () character using bubble sort
technique and display it
str = ”” ; void changeTxt ( ) to change the case of vowels
newstr= in the word to UPPER case
(for e.g. school becomes
len =0; schOOl )
void disp ( ) to display the changed
void readwordO string
Specify the class SortWord giving the details of
Scanner sc=new Scanner(System.in) ; the functions constructor, void readTxt ( ). void
System.out.println(“ Enter a word ” ) ; sortTxt( ). void change Txt( ) and void disp( ). You
str =sc. nextLine () ; need not to write the main function.
len =str.length () ;
I.
Ans import java .io.*;
PROGRAMMING IN JAVA 151
case ‘o’: txt [i] = (char)(txt[i] - 32) ;
class SortWord //class name SortWord break ;
{ case ‘ u’: txt [i] = (char)(txt[i] - 32) ;
chartxt [ ] ; break ;
int len ;
SortWord 0
{ }
len = 0; }
} void disp
void readTxt ( ) throws IOExpception {
{ system .out. println (txt) ;
BufferedReader br = new }
Buffered Reader (new }
InputStreamReader(System .in);
System.out.println(“ Enter the word in ..
Q 4 A class Revstr defines a recursive function
lower case ”) ; to reverse a string and check whether it is a
t = br string readline 0 ; .
Palindrome The details of the class are given
len = t.length ( ); below: [ISC 2008] #
txt = new char [len] ; Class Name Revstr
for (int i = 0; i < len ; i++)
{ Data members/instance variable
txt [i] = t.chartAt (i) ; Str stores the sting
Revst stores the reverse sting
} Member functions/ Methods
void sortTxt ( )
void getstr () to accept the string
{
char a , b; void recReverse to reverse the string using
for (int i = 0; i < len ; i++) (int ) the recursive technique
{ void check ) ) to display the original
for (int j = 0; j < len - i - 1; j++) string, its reverse and
{ whether the string is a
a = txt[ j] ; Palindrome or not
b = txt[j + 1] ; Specify the class Revstr giving the details of the
if (a > b) functions void getStr( ), void recReverse (int) and
{ .
void check () The main function need not to be
char t = txt[ j] ; written .
txt [j] = txt[j + 1] ; ..
Q 5 A class Mystring has been defined for the
txt[ j + 1] = t; following methods/functions:

} Class Name Mystring


Data members/instance variable
} str[] stores the sting
void changeTxt ( )
{ len length of given string
for (int i = 0; i < len ; i++) Member functions/ Methods
{
Mystring( ) constructor
switch (txt [i] )
{ void readString( ) reads the given string
case ‘ a ’: txt [i] = (char)(txt [i] - 32); from the input
break ; int code (int index ) returns, ASCII code for
case ‘e’: txt[i] = (char)(txt[i] - 32); the character at position
break ; index
case ‘i’: txt[i] = (char)(txt [i] - 32); void word ( ) displays longest words in
break ; the string

These questions are for practice and their solutions are available at the end of the chapter
152 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Specify the class Mystring giving the details of else
I
the constructor and void readString(). int code(int s = s + c;
index), void word ( ) only. The main function
need not to be written.
System.out.println(“longest word is ” +s) ;
Ans. import java .io.*;
}
class Mystring //class name
}
Q. 6. Design a class Stringfun to perform various
String str;
operations on strings without using built in
int len ; functions for finding the length of the string.
Mystring ( ) Some of the member functions/data members are
given below:
str = Class Name Stringfun
len = 0;
Data members/instance variable
str to store the sting
void readString() throws IOException
Member functions/ methods
InputSreamRader in = new InputStream void input( ) to accept the string
Reader (System.in) ; void words( ) to find and display the
BufferedREader br = new Buffered number of words, number
of vowels and number of
Reader (in) :
uppercase characters in
System.out.println(“ Enter string”) ;
the string
str = br.readline ( );
void frequency! ) to display frequency of
len = str.length ( ); each character within the
string .
int code (int index)
Specify the class Stringfun giving the details of
the functions void input (). void words and void
if (index >= len) frequency! )• You do not need to write the main
{ function.
System.out.println(“ Invalid Index ”) ; Ans. import java , io.*;
return - 1; class Stringfun //class name

else String str;


return ((int)str.chartAt (index)) ; void input ( ) throws IOException
}
void word Q InputStreamReader in = new
InputStream Reader (System.in) ;
char c; //convert byte to character
String s, p; BufferedReader br = new Buffered
s = “ ”; Reader (in) ;
//Create default size of input
P=“
for (int i = 0; i < = len - 1; i++) str = br.readLine ( );
{ }
c = str.charAt (i) ; void words ( ) //method
if (c==‘ ’ || i==len - 1)
char c;
if (s.length ( ) > p.length ()) int i, w = 1, v = 0, u = 0;
for (i = 0; i < str.lengthQ ; i++)
p = s;
s = “ ”; c = str.chartAt (i) ;
} if (c=‘ ’)
} w ++ ;
I else
PROGRAMMING IN JAVA
Q. 7. A class stringop is designed to handle string
153

related to operations. Some members of the class


if (c=='a ' || c=='e' || c==T || are given below: #
[ISC 2005]
c=='o' || c== 'u' || c== 'A' || Data Members Stringio
c=='E ' || c==T || c=='0' || txt to store the given string
c== 'U') of maximum length
v++; 100.
if (c >= 'A' && c < = ' Z ') Member function
u ++ ; Stringio ( ) constructor
} void readstring To accept the string
char caseconvert (int) To convert the letter to
System.out.println (“ No of words” +w) ; other case
System.out.println(“ No of uppercase Specify the class giving the details of the char
letter ” +u) ; caseconvert (int) and void circulardecode ( ) only
System.out.println (“ No of vowels ” +v) ; you may assume that other functions are written
for you. You do not need to write the main ().

void frequency ( ) Very Long Answer Type


<©> Questions (10 marks)
int i; Q. 1. A class Mix has been defined to mix two words,
int c [ ] = new int [26]: character by character, in the following manner:
for (i = 0; i < 26; i++) The first character of the first word is followed by
c[i] =0; the first character of the second word and so on.
If the words are of different length, the remaining
for (i = 0; i < strlengthQ ; i++)
characters of the longer word are put at the end.
Example: If the First word is "JUMP" and the
char ch ; second word is "STROLL", then the required
ch= str. charAt (i) : word will be "JSUTMRPOLL"
for (int j = 0; j < str.length () ; j++) Some of the members of the class are given below:
Classname : Mix
if (ch ==str.chartAt ( j)) Data member/instance variable:
c [i] ++; wrd : to store a word
len : to store the length of the
word
for (i = 0; i < 26 ; i++) Member functions/methods:
Mix( ) : default constructor to
initialize the data members
char chi = (char)(65 + i) ;
with legal initial value
char ch 2 = (char) (97 + i);
void feedword( ) : to accept the word in
for (int j = 0; k <str.length ( ) ; j++) UPPER case
if (chl ==str.charAt( j) void mix_word(Mix P, Mix Q)
ch 2 ==str.charAt ( j)) : mixes the words of objects
P and Q as stated above
System.out.println(“ frequency of ’ and stores the resultant
word in the current object
+str.charArt ( j) + “is ” +c[j]) ;
void display] ) : displays the word
break;
} Specify the class Mix giving the details of the
constructor] ), void feedword] ), void mix_
word(Mix, Mix) and void display] ). Define the
} main] ) function to create objects and call the
functions accordingly to enable the task.
These questions are for practice and their solutions are available at the end of the chapter
154 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 2. A class SwapSort has been defined to perform
I
string related operations on a word input. Some void readword ( ) throws IOException {
of the members of the class are as follows:
[ISC 2017] InputStreamReader x = new
InputStreamReader (System.in) ;
Class Name : Swap Sort
BufferedReader y = new
Data members/instance variables: BufferedReader (x) ;
wrd : to store a word System.out.println( Enter word: ") ;
"
len : integer to store length this.wrd = yreadlineQ . toUpperCase () ;
of the word }
swapwrd : to store the swapped void swapwrd 0 {
word
String p = this.wrd ;
sortwrd : to store the sorted word this.swapwrd = p.charAt (p.length () - 1) +
p.substring , p.lengthO -1) + p.charAt (o) ;
Member functions/methods:
SwapSort] ) : default constructor to ^
initialize data members void sortwrd ] ) {
with legal initial String p = this.wrd ;
values.
char[] charArray = p.toCharArrayO ;
void readword] ) : to accept a word in
int length = charArray.length ;
UPPER CASE
for (int i = 0; i < length ; i++) {
void swapchar] ) : to interchange/swap
the first and last for (int j = i + 1; j < length ; j++) {
characters of the word if (charArray[j] < charArray[i]) {
in 'wrd' and stores the char temp = charArray[i] ;
new word in 'swapwrd' charArray[i] = charArrayjj] ;
void sortword] ) : sorts the characters of charArrayjj] = temp ;
the original word in
alphabetical order and
stores it in 'sortwrd' }
}
void display] ) : displays the original
word, swapped word for (char c: charArray) {
and the sorted word this.sortwrd = this.sortwrd + c;
Specify the class Swap Sort, giving the details
of the constructor]), void readword]), void
swapchar]), void sortword]) and void display]).
void display ( ) {
Define the main]) function to create an object and
call the functions accordingly to enable the task. System.out.println("Original word: "
Ans. import java .io. BufferedReader; + this.wrd) ;
import java .io.IOException ; System.out.println( Swapped word: ”
"
+ this.swapwrd) ;
import java .io.InputStreamReader;
System.out.println("Sorted word: "
import java .util .Arrays;
+ this.sortwrd) ;
public class SwapSort {
}
String wrd ;
public static void main (String[] args) throws
int len ; IOException {
String swapwrd ; SwapSort obj = new SwapSort ]) ;
String sortwrd ; obj. readword 0 ;
SwapSort ( ) { obj.swapwrd 0 ;
wrd = obj.sortwrd () ;
len = 0; obj.display ();
swapwrd =
sortwrd =
I
Q. 3. A class ConsChange has been defined with the {
PROGRAMMING IN JAVA

c = word.charAt(i);
155

following details: [ISC 2016] if (c = = 'a' || c== e' || c=='i' ||


c!=='o' || c=='u ’)
Class Name : ConsChange s += c;
Data members/instance variables: System.out.print("\n shifted Word
word : stores the word =" +s);
word = s;
len : stores the length of the }
word void changeword( )
Member functions/methods:
{ char c; String s = "
for (int i = 0; i < len; i++)
ConsChange () : default constructor c = word.chartAt(i);
void readwordQ accept the word in
: if(c!= 'a * && c! = 'i * && c! = 'o'
lowercase && c!= ’ u'&& c! = 'e ’ )
s += (char)(c - 32);
void shifticonsQ : shifts all the consonants
else
of the word at the
s += c;
beginning followed by
}
the vowels (e.g. spoon
becomes spnoo ) System.out.printIn("\n Changed
word ="+s);
void changeword ( ) : changes the case of all }
occurring consonants
void show ( )
of the shifted word
to uppercase, for System.out.print("\n Original ="
e.g., ( spnoo becomes +word);
SPNoo ) shiftcons( );
changeword ( );
void show ( ) : displays the original
}
word, shifted word and
the changed word static void main( )
Cons Change X = new ConsChange ( );
Specify the class ConsChange giving the details X.readword ( );
of the constructor (), void readword( ), void X.show ();
shifticons (), void changewordQ and show () . }
Define the main( ) function to create an object and
call the functions accordingly to enable the task. } [ISC Marking Scheme 2016]

Ans. import java.util.Scanner;


public class ConsChange
{ String word;
Examiner's Comment
int len;
static Scanner sc new w Most candidates were able to attempt this question
Scanner(System.in); well. Different methods/logic were used to shift
ConsChange () consonants in the shifticons() function and to
{ len = 0; word = " "; change case in the changeword () function. Some
} candidates included local variables in the functions
void readword ( ) and shared it with other functions. Some were not
{ System.out.println("Enter word in able to display the required output in the showQ
Lower case"); function. The mainQ function and constructor
word = sc.next( ); were not answered by a few candidates.
len = word.length ();
}
void shifticons ( )
Answering Tip
{ String s = " "; char c;
w' Students should practice on various methods/
for (int i = 0; i < len; i++) functions that are used consonants in the
c = word.charAt(i); shifticons( ), function and to change case in the
if (c! = 'a' && c!= ' e ' && c!='i' changeword ( ) function.
&& c!= ’ o'
& & c ! == ' u ' ) Q. 4. Design a class Sort which enables a word to be
s += c; arranged in alphabetical order. The details of the
} members of the class are given below:
for (int i=0; i < len; i++) [ISC Specimen Question Paper 2016]
156 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class-XII

Class Name : Sort for (int i = 0 ; i < len ; i++)


I
System.out.print(c[i]);
Data members/instance variables:
}
Str : stores a word void display ( )
len : to store the length of the {
word System.out.println (“Original Word:” +str) ;
Member functions: System.out.print(“ Sorted Word:”) ;
Sort ( ) : default constructor arrange ( ) ;
void : to accept the word
}
readword () public static void main (String args[])
throws IOException
void arrange ( ) : to arrange the word in
alphabetical order using any
{
standard sorting technique Sort s = new Sort () ;
void display : display the original word
s.radword ( ) ;
along with the sorted word s.display( );
0
}
Specify the class Sort giving details of the
}
constructor, void readword(), void arrange() and
void display(). Define the main() function to Q. 5. A class The String accepts a string of a maximum
create an object and call the function accordingly of 100 characters with only one blank space
to enable the task. between the words.
Ans. import java , io.*; Some of the members of the class are as follows;
public class Sort Class Name The String
{
Data member/instance variable:
String str;
int len ; str : to store a string
Sort ( ) len : integer to store the
{ length of the string
str = word count : integer to store the
} number of words
void readword ( jthrows IOException cons : integer to store the
{ number of constants
BufferedReader br = new BufferedReader Member functions/methods:
(new InputStreamReader(System.in)) ; constructor
TheString ( ) default
System.out.println(“ Enter a word ”) ; to initialize the data
str = br.readLine ( ); members
len = str.length ( ) ; The String : parameterized
} (String d s ) constructor to initialize
void arrange ( ) the data members
{
void countFreq () : to count the number of
char c[ ] = new char (len); words and the number
for (int i = 0 ; i < len ; i++) of consonants and store
{ them in word count and
c[i] = str.charAt (i) ; cons respectively
void Display () : to display the original
char t; string, along with the
for (int i = 0 ; i < len - 1; i++) number of words and the
for (int j = 0; i < len - 1 - i , j++) number of consonants
if (c[ j] > c\j + 1]) Specify the class The String giving the details
{ of the constructors, void count Freq() and void
t = cD ] ;
'
Display(). Define the main() function of create
c[j ] = c[ j + l]; an object and call the functions accordingly to
c[j + 1] = t; enable the task.

These questions are for practice and their solutions are available at the end of the chapter
PROGRAMMING IN JAVA 157

File Handling
Concepts covered: Types of files; Opening and reading and writing files;
File handling methods

Revision Notes
> File handling is an essential part of any programming language. Using files, a program can store data on a storage
device.
> To perform various actions on a file, such as read, write, and so on.
Why File Handling is Required?
> File Handling is an integral part of any programming language as file handling enables us to store the output of
any particular program in a file and allows us to perform certain operations on it.
> In simple words, file handling means reading and writing data to a file.
Streams in Java
> In Java, a sequence of data is known as a stream.
> This concept is used to perform I/O operations on a file.
> There are two types of streams :
1. Input Stream:
2. Output Stream:
• The input stream is used to read data from numerous input devices like the keyboard, network, etc.
InputStream is an abstract class, and because of this, it is not useful by itself. However, its subclasses are used
to read data.
Creating an InputStream
// Creating an InputStream
InputStream obj = new FileInputStream() ;
Here, an input stream is created using FilelnputStream.
• The output stream is used to write data to numerous output devices like the monitor, file, etc. OutputStream
is an abstract superclass that represents an output stream. OutputStream is an abstract class and because of
this, it is not useful by itself. However, its subclasses are used to write data.
Creating an OutputStream
// Creating an OutputStream
OutputStream obj = new FileOutputStream() ;
Here, an output stream is created using FileOutputStream.
> Methods for file handling:
S.No. Method Description
1. public void close() throws IO Exceptions{} This method closes the file output stream. Releases
any system resources associated with the file. Throws
an IO Exception.
2. public void finalizeQ throws IO Exception!} This method cleans up the connection to the file.
Ensures that the close method of this file output
stream is called when there are no more references to
this stream. Throws an IO Exception.
3. public void write(int w) throws IO Exception!} This method writes the specified byte to the output
stream.
4. public void write(byte[] w) Writes w.length bytes from the mentioned byte array
to the OutputStream
158 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
|Key Terms
> File handling in Java means to read from and write to file in Java. It provides the basic I/O package for reading
and writing streams.java.io package allows to do all input and output tasks in Java.
> Java.io package contains the inbuilt Java classes and predefined methods using which you can read from and
write data to file.
> Byte stream classes are as follows: InputStream, OutputStream, FilelnputStream, FileOutputStream,
ByteArraylnputStream, ByteArrayOutputStream, PrintStream, RandomAccessFile etc.
> Methods defined by InputStream: read /), read (byte[] r), available(), close/), etc.
> Methods defined by OutputStream: write(int w), write(byte[] w), finalize /), close/), etc.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. A type of file that contains letters, numbers, Ans. Option (B) is correct.
symbols etc. is called. Q. 6. FilelnputStream class reads bits
(A) Datafile (B) Text file characters.
C
( ) Binary file (D) None of these (A ) 4 (B) 16
Ans. Option (B) is correct. (C) 32 (D ) 8
Explanation: A text file is a computer file that is a Ans. Option (D) is correct.
kind of non-executable, digital file and has only Explanation: Java FilelnputStream class obtains
text. It can have numbers, letters, symbols, and/ input bytes from a file. It is used for reading
or a combination but does not contain special byte-oriented data (streams of raw bytes) such as
formatting such as italic text, bold text, underline image data, audio, video etc, and it is reads 8 bits
text, pictures, etc. A text file identifies with the .txt characters.
file extension in Microsoft Windows computer.
Q. 7. If an already existing file is opened for writing:
Q. 2. The File Class belongs to package. (A) It is not opened
(A) java.io.* (B) java.lang (B) An error is raised
(C) java.math (D) None of these (C) A copy of it is opened
Ans. Option (A ) is correct. (D) It is recreated and already existing data is
Explanation: Java uses the concept of a stream erased.
to make I/O operation fast. The java.io package Ans. Option (D) is correct.
contains all the classes required for input and
Explanation: If a file is in writing mode, then a
output operations. new file is created if a file doesn't exist at all. If
Q. 3. To open a file for writing, stream used is: a file is already present on a system, then all the
(A) FileOutputStream data inside the file is truncated, and it is opened
(B) FileWriteStream for writing purposes.
(C) FilelnputStream Q. 8. The end of file is reached if read() returns
(D) FileReadStream (A) -1 (B) null
Ans. Option (A ) is correct. (C) eof (D) Both (A) and (B).
Explanation: FileOutputStream is an outputstream Ans. Option (A ) is correct.
for writing data/streams of raw bytes to file or
Explanation: The read () method of the input stream
storing data to file. FileOutputStream is a subclass classes reads the contents of the given file byte by
of Outputstream.
byte and returns the ASCII value of the read byte
Q. 4. To open a file is required. in integer form. While reading the file if it reaches
(A) file name (B) file stream the end of the file this method returns -1.
(C) file object (D) None of these Q. 9. To open an existing file for appending
Ans. Option (C) is correct. keyword is used along with filename in write().
Q. 5. To write 16 bits characters class is (A) append (B) add
used. C
( ) true (D) false
(A) FileOutputStream (B) FileWriter Ans. Option (C) is correct.
(C) FilelnputStream (D) All of these.
I PROGRAMMING IN JAVA 159

SUBJECTIVE TYPE QUESTIONS


Here, a object of FileWriter is created and true
Short Answer Type
<©> Questions (2 marks)
means that the new text will be appended to file
and old data will be retained.

..
Q 1 What are Java stream classes? ..
Q 3 What do you mean by String Tokenizer? Also
.
Ans In java, I/O facility is based on stream. Stream is a
write the syntax .
continuous flow of data. The InputStream is used .
Ans The java.util.StringTokenizer class allows an
to read data from a source and the OutputStream application to break a string into tokens. The
is used for writing data to a destination. processing of text often consists of parsing a
formatted input string. Parsing is the division of
The java.io package contains a large number
text into a set of discrete parts or token.
of stream classes that provide capabilities for
processing all types of data. Java stream classes Syntax
may be categorized into two groups based on the StringTokenizer (String str) ;
data type on which they operate: or
(i) Byte Stream Classes that provide support for StringTokenizer (String str, String delim);
handling I/O operations on bytes. Q. 4. Write a Java program using nextToken( ) method.
(ii) Character Stream Classes that provide support
for managing I/O operations on characters. ..
Q 5 Name the interfaces used inside the package of
..
Q 2 Define appending to text file with example . awt print.
.
Ans Appending to text file means, retaining the old Ans. The java.awt.print consists of the following
contents and append the new contents. interface:
Syntax (i) Pageable represent a set of pages to be printed.
FileWrite cObject name> = new FileWrite (ii) Printable implement a page painter.
(<filename> , true) ; (iii) Printer Graphics provides the getPrinterJob( )
method to obtain the printer job.

I Topic- 6
Exception Handling S JVM
Concepts covered: Exceptions and their types, functions for exception
handling, JVM . JDK

m
>
Revision Notes
An exception is an abnormal condition that arises in a code sequence at run time. In other words, an exception
is a run-time error. In computer languages that do not support exception handling, errors must be checked and

handled manually typically through the use of error codes, and so on. This approach is as cumbersome as
it is troublesome. Java's exception handling avoids these problems and, in the process, brings run-time error
management into the object oriented world.
> Exception Handling: A Java exception is an object that describes an exceptional (that is, error) condition that
has occurred in a piece of code. When an exceptional condition arises, an object representing that exception is
created and thrown in the method that caused the error. That method may choose to handle the exception itself,
or pass it on. Either way, at some point, the exception is caught and processed. Exceptions can be generated
by the Java run-time system, or they can be manually generated by your code. Exceptions thrown by Java
relate to fundamental errors that violate the rules of the Java language or the constraints of the Java execution
environment. Manually generated exceptions are typically used to report some error condition to the caller of a
method.
> Java exception handling is managed via five keywords: try, catch, throw, throws, and finally.
Program statements that you want to monitor for exceptions are contained within a try block.
If an exception occurs within the try block, it is thrown. Your code can catch this exception (using catch) and
handle it in some rational manner.
System-generated exceptions are automatically thrown by the Java run-time system. To manually throw an
exception, use the keyword throw. A throw is followed by an instance variable.
These questions are for practice and their solutions are available at the end of the chapter
160 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
Any exception that is thrown out of a method must be specified as such by a throws clause, throws is followed
by exception class names
Any code that absolutely must be executed after a try block completes is put in a finally block.
> Two types of exceptions are:
(i) Checked exception
(ii) Unchecked exception
> General form of an exception-handling block:
try {
// block of code to monitor for errors
}
catch (Exceptioniypel exOb) {
// exception handler for Exceptioniypel

catch (Exception'iype2 exOb) {


// exception handler for Exceptioniype2
}
II ...
finally {
// block of code to be executed after try block ends

> Java Virtual Machine (JVM)


A JVM is an abstract computation machine that enables a computer to run a Java program. There are three
notions of the JVM as specification, implementation and instance.
The specification is a document that describes what is required of a JVM implementation. A JVM
implementation is a computer program that meets the requirements of the JVM specification. An instance is
an implementation running in a process that executes a computer program compiled into Java bytecode.
Java development Kit (JDK) is a superset of a Java Runtime Error (JRE) and contains tools for Java programmers,
e.g. a javac compiler.
Java-in-time Compiler (JIT) is the part of the JVM that is used to speed up the execution time. JIT interpret
parts of the bytecode that have similar functionality at the same time, and hence reduce the amount of time
needed for full interpretation.

|Key Terms
> Way of handling anomalies situations in a program-run is known as exception-handling
> Exception handling has three keywords: try, throw and catch
> Program statements that you want to monitor for exceptions are contained within a try block.
> If an exception occurs within the try block, it is thrown. Your code can catch this exception ( using catch) and
handle it in some rational manner.
> System-generated exceptions are automatically thrown by the Java run-time system. To manually throw an
exception, use the keyword throw. A throw is followed by an instance variable.
> A JVM is an abstract computation machine that enables a computer to run a Java program. There are three
notions of the JVM as specification, implementation and instance.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. Events occurring at the runtime of a program that Explanation: Java Exception Handling is a
disrupt the overall execution of the program mechanism to handle runtime errors such
(A) Exceptions (B) Logical errors as ClassNotFoundException, IOException,
(C) Syntax errors (D) Invalid inputs SQLException, RemoteException, etc.
Ans. Option (A ) is correct.
I
Q. 2. Code that might throw an exception is enclosed Q 5..
PROGRAMMING IN JAVA 161
are libraries of compiled code that can
within: be used in our programs.
(A ) { } (B ) tryblock (A) Byte code (B ) Packages
(C) catch block (D) " "(double quotes) (C) Java APIs (D) None of these
Ans. Option (B ) is correct. Ans. Option (C) is correct.
Explanation: Java try block is used to enclose the Q. 6. reads the byte code and translates it
code that might throw an exception. It must be into the native language of the host machine.
used within the method. If an exception occurs (A) Interpreter (B ) Compiles
at the particular statement in the try block, the (C) Translator (D) None of these.
rest of the block code will not execute. So, it is
Ans. Option (A ) is correct.
recommended not to keep the code in try block
that will not throw an exception. Q. 7. JVM is an machine.
Q. 3. The error handling code is (A) electronic (B ) digital
(A) main()block (B ) tryblock (C) Mechanical (D) abstract
(C) catch block (D) none of these Ans. Option (D) is correct.
Ans. Option (C) is correct. Explanation: The Java Virtual Machine, or JVM,
Explanation: The catch block contains code that is an abstract computer that runs compiled Java
is executed if and when the exception handler is programs.
invoked. Q. 8. compiles bytecode into executable
Q. 4. is a machine instruction for Java code in real time.
processor chip. (A) JVM (B) JIT
(A) JVM (B ) Interpreter (C) Interpreter (D) Compiler
(C) Compiler (D) Bytecode Ans. Option (B ) is correct.
Ans. Option (D) is correct.
Explanation: A Java bytecode is a machine Q. 9. Java platform is a combination of JVM and
instruction for a Java processor chip. The
architecture of this processor has been very (A) editor (B ) compiler
carefully described by the designers of Java and is (C) interpreter (D) Java API
freely available to anyone. To run a Java program Ans. Option (D) is correct.
on the Java processor chip, the souce program (the
text file) must be translated into bytecodes.

SUBJECTIVE TYPE QUESTIONS


Q. 2. What is an exception? [ISC 2011]
Short Answer Type
<©> Questions (2 marks)
Ans. An exception is a condition that is caused by a
run-time error in the program, e.g. when the Java
interpreter encounters an error such as dividing an
Q. 1. Differentiate between throw and throws with
integer by zero.
respect to exception handling. [ISC 2013]
Ans. Difference between throw and throws keywords: Q. 3. State the use of exceptional handling. Name two
types of exceptions. [ISC 2010]
S.
Throw Keyword Throws Keyword Q. 4. With a suitable example state the difference
No.
(i) throw keyword is throws clause is -
between run time error and syntax error.
used to throw an used to declare an [ISC 2005]
exception explicitly. exception. Ans. Difference between run-time and syntax error:
(ii) throw is followed by throws is followed S. Syntax Error -
Run Time Error
an instance variable. by exception class No.
names. (i) Syntax errors are A run-time error is
(iii) The keyword throw throws clause is used error when we violate an error that causes
is used inside method in method declaration any grammatical at normal program
body to invoke an (signature)
exception . rule in programming termination during
(iv) By using throw Using throws, you language. execution.
keyword in Java you can declare multiple
cannot throw more exception
than one exception.

These questions are for practice and their solutions are available at the end of the chapter
162
(ii)
Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Syntax error can Run-time error can be


I
be found during found only when you while (isComposite(num) == 0) ;
compilation. are trying to execute
your program. }
(hi) Syntax errors are those Run-time errors are t }
which are caused hose which are caused
public void display ( )
by incorrect usage by incorrect usage of
of the programming programming logic.
language. for (int i = 0; i < m ; i++)
e.g. print "Gee golly" e.g. print (greeting)
public void fill ( ) for (int j = 0; j < n ; j++)
System.out.print(arr[i][j] + “\t”) ;
int i, j; System.out.println( ) ;
int num = 1; }
int count = 0 ; }
for (i = 0; i < n ; i++) public static void main (String args[] )
throwsIOException
for ( j = 0; j < m ;)
Buffered Reader br = new BufferedReader
do (new Input StreamReader (System.in) ;
System.out.println(“ Enter the number
if (isComposite(num) == 1) of rows and columns below or equal to
20”) ;
{
int mm = Integer. parseInt (br. readLine ( ));
arr ( j)(i) = num ;
int nn = Integer. parseInt (br.readLine ( ));
count ++;
Composite obj = new Composite (mm , nn) ;
num ++;
obj . fill ( ) ;
j++;
obj.display ( ) ;
break;
}
num++ ;
I PROGRAMMING IN JAVA

Solutions for Practice Questions


TOPIC-1 int fibo (int n)
2 Marks Questions {
2. Output of the function test ( ) = Bye 4 if (n>0)
Bye 3
Bye 2 int term = start + end ;
Bye 1 start = end;
0
end = term;
System .out.print (“ “ +term) ;
1
fibo(n - l ) ;
2
3 return 0;
Bye 4
I— test ( 3 )
void display()
I — Bye 3
I— test ( 2 ) int n=10 ;
I — 2Bye 2
I— test (1) System .out.printlnfFibonacci
Series:”) ;
fByel
1
System .out.print (start+ ” “+end) ;//
— test ( 0 ) printing 0 and 1
0
fibo(n - 2) ;
}
TOPIC-2 public static void main (String[] args)
2 Marks Questions {
3. The underwritten points could be regard as short Fibo f = new FiboO ;
comings of recursion: f. readO ;
(i) It requires extra storage space. The recursive f. displayQ ;
calls and automatic variables are stored on }
the stack. For every recursive call, separate
memory is allocated to automatic variables 9. (i) When n = 5 then
with the same name. back to function
(ii) If the programmer forgets to specify the number(5 ) Output-^5 Output-^ 5
exit condition in the recursive function, the back to function
program will execute out of memory. In such number( 3) Output- 3 -* 1 Output- - 3
*
a situation, user has to press Ctrl + break to Call
I , , , „ back to function
pause or stop the function. number( l ) Output-^ 1
Call
5 Marks Questions
2. /*We considered first term and second term for
number(-l ) Output-^ nothing
Call
Fibonacci series as start value and end value
Final output is 5 3 1 1 35
respectively */
import java . util . Scanner; (ii) When n = 6 then
back to function
public class Fibo numberl (6) *-—i retum _ . 1 2 3 4 5 6
,
- *
int start , end ; . 1 back to function
numberl (5 ) 1 return- 1 2 3 4 5
^
FiboQ Call
, I back to function
numberl (4) retum -^12 34
start=0;
end=0;
Call | back to function
numberl (3] •*— retuin - 12 3
Call | ^
void readQ I back
— numberlpH—1 return-^12
to function

Scanner scanner = newScanner


Call I
H
L— numberl ( l ) *
back to function
* —return -*- 1
|
(System . in) ;
System . out.printlnfEnter starting
number: ”) ;
(

I—: 11
numberl (O) Output-^

start = scanner. nextlntO ; The final output will be 1 2 3 4 5 6


System . out.printlnfEnter ending (iii) Apart from recursion the function numberl
number: ”) ; (int) is performing the concatenation of
end = scanner. nextlntQ ; numbers.
}
164 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
int n = Integer.parselnt (br. readLine ()) ;
10 Marks Questions
4. Import Java .io.*; Emirp e = new Emirp (n) ;
class Emirp //class Emirp e.isEmirp ();

int n , rev, f ;
Emirp(int nn) //constructor Emirp .
5 Import java .io.*;
class Happy
n = nn ;
rev = 0; int n ;
f = 2; Happy ( ) //constructor
}
int isprime(int x) n = 0;
{
if (f = = X) void getnum (int nn) //method

return 1; n = nn ;
}
}
else if (x % f = = 0) _ _
int sum sq digits (int x) //method
{
return 0 ;
if (x > = 0 && x <= 9)
return x*x;
else
else
_ _
return (sum sq digits (x%10) + sum _
f ++; _
sq digits(x/10) ;
return (is prime(x)) ;
void ishappy ( ) // method
}
void isEmirp Q // method
int a = 0, num = 0;
{
int C = n ; rev = 0; int R;
_ _
a = sum sq digits (n) ;
while (a > 9)
while (C! = 0)
{
R = C %10; num = sum_sq_digits (a) ;
rev = rev * 10 + R; a = num ;
C = C/10;
if (num== l)
int a = insprime(n); System.out.println (“ Happy no.”) ;
int b = isprime(rev) ; else
if (a == l && b== l) System.out.printlnfnot Happy no.”) ;
System .out.println(n + “number is
Emirp”) ; public static void main (String args []) throws
else IOException
System .out.println(n + “ number is
not Emirp”) ; System.out.printlnfEnter a number”) ;
} BufferedReaderbr = new BufferedReader
public static void main (String args []) (new InputStreamReader(System .in) :
throws IOException int n = Integer.parselnt (br. readLine ()) ;
Happy ob = new Happy () ;
System .out.printlnfEnter value of n ”) ; //object creation
BufferedReaderbr = new BufferedReader ob.getnum (n) ;
(new InputStreamReader(System.in)) ; ob.ishappy ( ) ;
I b = 0;
PROGRAMMING IN JAVA 165

hcf = 0;
.
7 class Magic lcm = 0;

int n ; void getdata ( ) throws IOException


Magic ( ) //Constructor
InputSteamReader in = new Input
n = 0; SteamReader (System.in) ;
BufferedReader br new
void getnum (int nn) //Method getnum BufferedReader (in) ;
System.out. println(“ Enter any two
n = nn ; numbers ”);
a = Integer. parseInt (br. readLine ( )) ;
_ _
int Sum of digits (int x) b = Integer. parseInt (br.readLine ( ));
_ _
//Method sum of digits
void change ( )
int s = 0; {
while (x! = 0) int t;
if (a > b)
s = s + x%10;
x = x/10 t = a;
a = b;
return s ; b = t;
}
void ismagic () //Method ismagic }
int rechcf (int a , int b)
while (n > 9) {
if (b! = 0)
_ _
int sum = Sum of digits(n) ; return rechcf (b, a %b) ;
n = sum ; else
return a ;
if (n == l) }
_
int fn lcm (int a , int b, int h)
System.out.println(“The number is {
Magic Number ”) ; int 1;
1 = (a*b)/ h ;
else return 1;

System.out.println(“The number is void result ( )


not Magic number ”) ; {
hcf = rechcf (a , b) ;
_
lcm = fn lcm (a , b, hcf ) ;
System.out. println(“ HCF of these
11. import java , io.*; numbers is” +hcf ) ;
class Hifact System.out. println (“ LCM of these
numbers is ” +lcm) ;
int a , b, hcf , lcm ;
HifactQ public static void main (String args [ ])
throws IOException
a = 0;
166 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class- XII

Hifact hf = new Hifact ( );


I
N : is the total number of
hf.get data ( ) ; columns in the array.
hf. change ( ) ; J : is the row number of the
hf. result ( ) ; element.
} K : is the column number of
} the element.
16. class DeciOct In the given problem, Address of P[10] [ 7] is asked.
1400 base address, N = 10, w = S bytes.
{
int n , oct; Address of A[10][7] = 1400 + 8[10(10) + (7) ]
public DeciOct ( ) = 1400 + 8(100 + 7)
{ = 1400 + 8 x 107
n = oct = 0; = 2256
} 7. Given, W = 4 bytes, i = 4, j = 8
void getnum (int nn) Add[i] [ j] = ?
{ B = 1840
n = nn ; n = 10 [ V Lr = Lc = 0]
} So, Row wise address
_
void deci oct () Add[i] [ j] = B + W[ n (i - Lr ) + ( j - Lc)]
{ M[4] [8] = 1840 + 4[10(4 - 0) + (8 - 0) ]
int x = n ; M[4] [8] = 1840 + 4(10 x 4 + 8)
if (n > 8)
= 1840 + 4(48) = 1840 + 192
{ M[4] [8] = 2032
n = n/8 ;
_ 10 Marks Questions
deci oct ( ) ;
2. Import java.util,*;
public class Admission
oct = oct * 10 + x%8 ; { static Scanner x = new Scanner
(System.in);
void show ( ) int Adno [ ] = new int [100];
Admission ( ) { }
System .out. println ( “ Number” + n) ; Void fill Array ( )
_
deci out ( ) ;
System.out.println("Enter 1 0 0
System . out . println( “ Its octal
elements in ascending order ");
equivalent ” +oct) ;
for (int i = 0; i < 100; i++)
Adno[i] = x.nextlnt();
public static void main (String args [ ] ) }
int binSearch(int 1, int u, int v)
DeciOct dl = new DeciOct ( ) ; { int m =(1 + u)/2;
dl . getnum ( 25) ; if (Adno[m]==v)
return l;OR return m;
dl . show( ) ;
else if (1 > u)
return 1;
else if (Ando[m] > v)
TOPIC- 3 return binSearch(1 , m - 1, v);
2 Marks Questions else
return binSearch(m + 1, u, v);
2. LOC (A[J, K]) = Base (A) + w[ N (J ) + (K ) ]
}
LOC (A [J, K]) : is the location of the OR
element in the Jeth row u = m 1
and Kth column . else
Base (A) : is the base address of the 1 = m + 1
array A. return binSearch(1, u, v)
w : is the number of bytes
static void main ( )
required to store single
element of the array A. Admission obj = newAdmission();
obj.fillArray ( );
I }
PROGRAMMING IN JAVA 167

System.out.print!n ("Enter
value to be searched"); void display ( )
int v = x.nextlr.t ( );
int p = obj.binSearch (C, int i, j;
obj . Adno.length 1, v ); - for (i=0 ; i<m ; i++)
if (p==-l )
System.out .println
("No. not found"); for ( j =0; j<n ; j++)
else {
System.out.println System.out. print (arr [i] [j ] +" ") ;
("No. is present");
}
System.out. println( ) ;
} [ISC Marking Scheme, 2015]
4. import java.io.*;
class Composite

11. import java .io.*;


int arr [] [] ;
int m ; class Collection //class name
int n ; {
public Composite (int mm , int nn) int arr [] ;
int len ;
m = mm ; Collection ( ) //constructor
n = nn ;
arr = new int [m] [n] ; arr = new int [100] ;
//initialization of arr
len = 100;
public int isComposite(int p)
Collection (int x)//constructor
int f = 0;
{
for (int i = 1; i < = p; i++)
len = x ;
if (p%i ==0)
arr = new int [len ] ;
f ++;
}
if (f > 2)
void arrange ( ) //method
return 1;
else
for (int i = 0 ; i < len ; i++)
return 0 ;
for (int j = i + 1; j < len ; j++)
void fill ( )
{
if (arr[i] > arr [j ])
int i, j, k = 4;
{
for (i=0 ;i<n ;i++)
int t = arr[i] ;
arr [i] = arr[ j];
for ( j=0;j<m ;j++)
arr [ j ] = t;
while (iscomposite (k) ==0)
}
}
k ++;
}
void display ( [//method
arr[j] [i] = k ;
k ++;
for (int i = 0 ; i < len ; i++)

System.out. println(arr [i]);


168 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

} }
I
} void sortarr ( )
void inparr ( ) throws IOException
int N = ar.length
InputstreamReader ip = int i, j, pos.temp;
new Inputstream Reader (System.in) ; for (i = 0; i < N - 1; i++)
//convert byte to char
BufferedReader br = new Buffered pos = i;
Reader(ip) ; for ( j = i + 1; j < N ; j++)
//create default input size {
System.out.println (“ Enter the ” + len + if (ar[j] < ar[pos])
“elements ”) ;
for (int i = 0; i < len ; i++)
Pos = j;
arr [i] = Integer. parselnt (br.
readLineQ) ;
temp = ar[i] ;
ar [i] = ar[pos] ;
ar [pos] = temp;
Collection common (Collection a)
}
// method

Collection b = new Collection (len) ; int binarysearch (int ar[ ] , int c)


//creating object
int num , k = 0; int beg, end , pos = - 1, mid ;
for (int i = 0; i < a.len ; i++) beg = 0;
{ end = 99;
num = a .arrji]; while (beg <= end)
for (int j = 0; j < len ; j++)
mid = (beg + end)/2;
if (num ==arr[j ]) if (ar[mid] ==c)

b.arr[k] = num ; pos = mid + 1;


k ++; break;
break ; }
} else if (ar [mid ] < c)
beg = mid + 1;
else
b.len = k ; end = mid - 1;
return b;
} —
if (pos== 1)
} return 0 ;
15. class indexarray //class name indexed array
else
{ return 1;
int ar [ ] ; }
indexed array ( ) //constructor
TOPIC-4
5 Marks Questions
int i;
4. import java , io.*;
ar = new int [100] ;
for (i = 0; i <= 99 ; i++)
class Revstr //class name
ar [i] = 0;
String Str ;
I String Revst;
PROGRAMMING IN JAVA

if (a > = ‘A’ && a < = ‘Z’)


169

int i, len ; return (char)(a + 32) ;


Revstr ( ) if (a > = ‘a ’ && a < =‘ z ’)
return (char)(a - 32) ;
i = 0; return 0 ;
len = 0;
Str = void circulardecode ( )
Revst =
} String K = “ ”;
void getstr ( ) throws IOException char c;
{ int 1 = txt.lengthO;
BufferedREader br new for (int i = 0; i < 1; i++)
BufferedReader
(new InputStreamReader(System.in)) ; c = caseconvert (txt.charAt (i)) ;
//default input size if (c > = A && c < = ‘Y’)
System .out .print (“Enter the c = (char) (c + 1) ;
sentence:”) ; else if (c==‘ z ’) ' z')
//print c = A;
Str = br. readline ( ) ; else if (c==‘ z ’)
len = Str. length ( ) ; c = ‘a ’ ;
else if (c > = ‘a’ && c < = y )
void check ( ) // method c = (char) (c + 1) ;
K = K + c;
System.out.printlnfOrignial String is:” }
+Str) ; System.out.println(“ String is” + K) ;
System.out.printlnfReverse String is:” }
+Revstr) ; }
if (Str.equals (Revst)) 10 Marks Questions
System.out.printlnfThe String is .
5 public class The string
Palindrome ”) ;
else String str;
System.out.printlnfThe String is int len , word count, cons ;
not
The StringQ
Palindrome") ;

void recReverse (int len) //method OR The String ( )


{
if (len > 0)
str =
{
word count = 0;
Revst = Revst + Str.chartAt (len - 1) ;
}
len- -;
The String(String ds)
recReverse (len) ;
str = ds ;
}
len = str.length ( ) ;
}
7. class stringop
void count Freq ( )
{
String txt;
char c;
char caseconvert (int a)
str = str.toLowerCase ( ) ;
for (int i = 0 ; i < len ; i++)
170 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
{ TOPIC-5
I
c = str.charAt (i); 2 Marks Questions
if (c==32) 4. import java.util.*;
word count++ ; public class String Tokenizer Demo
if (c! = ' a ' && c! = ’e ' && c! = T && {
c! = 'o’ && c! = ’u’) public static void main (String[ ] args)
cons ++; {
} StringTokenizer st = new StringTokenizer
cons = cons - word count; ("come to learn");
++word count ; //creating string tokenizer
} System.out.println("Next token is: "
void Display ( ) + st.next Token( ));
//checking next token
System.out.printlnfNumber of words }
}
+ word count) ; TOPIC-6
System.out.printlnfNumber of 2 Marks Questions
consonants = ” + cons) ; .
3 If the exception object is not caught and
} handled properly, the interpreter will display an
static void main ( ) error message and will terminate the program
abnormally. If we want the program to continue
with the execution of the remaining code, then
The String x = new The Stringflndia is
we should try to catch the exception object
my country ”) ;
thrown by the error condition and then display
x.count Freq ( ) ; an appropriate message for taking corrective
x. Display Q ; actions. This task is known as exception handling.
The purpose of exception handling mechanism
is to provide a means to detect and report an
"exception circumstance" so that appropriate
action can be taken.
Two types of exceptions are:
(i) Checked exception
(ii) Unchecked exception
SELF ASSESSMENT PAPER - 3
Maximum Marks: 25 Timing: 1 Hour
.
1 How does using = = & equals method for comparing two strings differ? [1]
2. What is fall through condition? [1]
3. Find the output of the following recessive functions when a = 5 and b = 7. [1]
static Int fun (int a , int b)
{ if (a == 0)
return b;
else
return fun (a - 1, a + b);
.
4 Each element of an carry Arr [-10, ...10, 10...25] is stored in one byte. If the storage begins at location 500 in
column major, determine the location of A[012] [2]
.
5 Define Recursive case and Base case. [2]
6. Differentiate between actual and formal parameters. [2]
7. Write a short note on class as a data type and class as an application. [2]
8. Write a program in Javen to accept a string from the user and print every alternate character. It then prints every
alternate character beginning from the last letter, [4]
e.g. Input -> computer
output cmue
rtpo
.
9 Write a program to read articles manufactured by 5 machine in 12 month and to print total articles manufactured
by each machine. [4]
.
10 Define a class Revno which reverses an integer number as given below:
Class name Revno
Data member / instance variable
num to store the integer number
rev to store reverse of the integer number
Member functions / methods:
Revno ( ) default constructor
void input num to accept the number
void revers returns the reverse of a numbers without using ( % ) modulus
void display ( ) Displays the numbers and its revers.
Specify the class Revno, giving details of the constructor, voidinputnum ( ), int reverse (int) and void display ( ).
Define the main ( ) function to create an object and call the functions accordingly to enable the task. [6]
nn
OSWAAL LEARNING TOOLS
For Solutions of the above Self Assessment Paper, follow the link

Visit: https:// bit.ly/ 3Qai4W2 Or Scan the Code


Section C

CHAPTER INHERITANCE,
INTERFACES,

4 POLYMORPHISM,
DATA
STRUCTURES
(a ) Inheritance; super and derived classes; member access in derived classes;
redefinition of variables and methods in subclasses, abstract classes, class
object, protected visibility. Subclass polymorphism and dynamic binding.
| (b ) Interfaces in Java, Implementing interfaces through a class; interfaces for user defined implementation
j of behaviour.
*Note- These Concepts are only for your reference. Questions from these parts will not be asked in the Final Examination.

I Tonic -1
^
Inheritance
Concepts covered: Inheritance: Super
class: Sub class; Visibility Mode: Method
overriding: Super keyword
Topic- 1
Inheritance

Topic-2
Interfaces
.
Page No 172

.
Page No 190

Revision Notes

> Inheritance is a mechanism in which one object acquires all the properties and behaviours of a parent object.

> Inheritance is an important part of OOPs (Object Oriented Programming System).

> Derivation: It is the relationship between a base class and derived class. It is also known as inheritance hierarchy.

> Inheritance graph: A derivation from multiple base classes is known as inheritance graph.

> Subclass: It is the derived class and its declaration must include name of its base class.

> Base class: It is the base class or the class from which the sub class is derived.

> Class object: It is a class defined in java.lang package and every class that we define is a subclass of this class.

> Only single inheritance, hierarchial and multi level inheritance can be implemented in Java.
> Every class in Java has only one immediate or direct superclass.
> Inheritance relation is transitive, i.e., every class inherits states and behaviour from all superclasses which are
higher in class hierarchy.
I INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES 173

>
ts
x
2 -3 ^>
N

i 14 1
I III
J J J
EHEHZI

Potflam ssep aseq J°A

ctotSupel class
Sub- class-

structor of a base class


is
* at theti of
'

Constructors
asscann°t inherit
c
°nstruCtor
°f a Base class
Objects of subclass can Use
Base - abstract methods

Over loading I
s1
NJ
(
^ tetirne )

/pe<
V «A0 $ > >
3g
up
174
>
Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE Class-XII
Forms o£ inheritance
. I
Single inheritance: When a subclass inherits from only one base class, and there are only 2 classes in this
relationship, then it is known as single inheritance.
Base class

Sub class (Derived class)


Single inheritance

Multilevel inheritance: When a subclass inherits from a class that itself inherits from another class, it is known
as multilevel inheritance.
Base class of Y

Sub class of X
Base class of Z
Sub class of Y
Multilevel inheritance

Multiple inheritance: When a subclass inherits from multiple base classes it is known as multiple inheritance.
Java does not support multiple inheritance.

Sub class

Multiple inheritance

Hierarchical inheritance: When many subclasses inherit from a single base class it is known as hierarchical
inheritance.

Hierarchical inheritance

> Hybrid Inheritance: When a subclass inherits from multiple base classes and all of its base classes inherit from a
single base class it is hybrid inheritance.

> -
Variables in superclass having the same names as variables of sub class are hidden.
> Methods in superclass with same name as that of member methods of subclass are overridden.
> To refer to hidden data members and overridden methods of superclass 'super' keyword is used.
> Overriding the inherited method: If two method of the base and the derived class have the same signature then
the subclass method hides or overshadows the base class method. This is called overriding the inherited member.
I> INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES
Constructor of super class are not inherited by sub classes.
175

> Default constructor of the super class is automatically invoked before any statements within the constructors are
executed.
> Polymorphism is Java is a concept by which we can perform a single action in different way.
> Polymorphism means many forms.
> There are two types of polymorphism in Java:
Compile Time polymorphism
RunTime Polymorphism
> Two ways to implement polymorphism in Java are:
(a) Method Overloading
(b) Method Overriding
> Method overloading is one of the ways through which java supports polymorphism. Method overloading can be
done by changing number of arguments or by changing the data type of arguments. If two or more method have
same name and parameter list but differs in return type they are not overloaded method
> Method Overriding: If subclass (child class) has the same method as declared in the parent class, it is known as
method overriding in Java.
> It is used to provide the specific implementation of a method which is already provided by its superclass, and it
is used for runtime polymorphism.

|Key Terms
> Inheritance: One object acquires the properties of another object
> Polymorphism: Ability to take more than one form
Constructor chaining - phenomena of calling one constructor from another constructor of same class.
> Inline functions: The compiler replaces the function statement with the function code itself (expansion) and then
compiles the entire code.
> Concrete superclass: It is the class whose objects can be declared and created.
> Abstract class: It is the one that represents a concept only. It's objects can't be created.
> Keyword abstract is used to create an abstract class.
> Abstract methods: The methods have no method statements and are declared using abstract keyword.
> Extends is the keyword used to inherit the properties of a class
> The implements keyword is used with classes to inherit the properties of an interface.
> This keyword is used to refer to current object.
> Super keyword is used to refer to immediate parent class of a class.
> Overriding: To override the functionality of an existing method.

OBJECTIVE TYPE QUESTIONS (1 mark each)


..
Q 1 Keyword used to implement inheritance is: ..
Q 3 To prevent a superclass method from being
-
[ISC Sem 2 Paper 2021 22] - overridden use:
(A) abstract (B) inherit (A) abstract (B) final
(C) extends (B) final (C) super (D) this
.
Ans Option (C) is correct . .
Ans Option (B) is correct .
Q. 2. super() will Explanation: When a class is made final, a subclass
refer to an overridden method of subclass
(A) of it cannot be created. A final class cannot be
refer to an overridden method of super class
( B) subclassed.
refer to a hidden data member
(C) ..
Q 4 If Java class hierarchy is represented graphically
execute a superclass constructor
(D) as a tree then .
will be at its root
.
Ans Option (D) is correct . (A) Super class
Explanation: The super() in Java is a reference (B) Java.lang
variable that is used to refer parent class
(C) Object
constructors, super can be used to call parent class
variables and methods. (D) None of these
.
Ans Option (C) is correct .
176 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 5. Representation of Java class hierarchy graphically Q. 8. Members that are declared without any access
I
is know as: specifier are:
(A) Inheritance graph (A) default (B) private
(B) Derivation (C) protected (D) none of these
(C) Inheritance hierarchy Ans. Option (A ) is correct.
(D) Hierarchical inheritance Explanation: If you don't use any modifier, it is
Ans. Option (A ) is correct. treated as default by default. The default modifier
Q. 6. Which of thefollowingisnotaneedforinheritance? is accessible only within package. It cannot be
(A) To ensure the closeness with the real world accessed from outside the package. It provides
models. more accessibility than private. But, it is more
(B) Addition of additional features to an existing restrictive than protected, and public.
class without modifying it Q. 9. Type of inheritance not available in Java is:
(C) Transitive nature of inheritance (A) single (B) hybrid
(D) None of these (C) multilevel (D) hierarchical
Ans. Option (D) is correct. Ans. Option (B) is correct.
Explanation: The idea behind inheritance in Java is Explanation: Java supports only single, multilevel,
that you can create new classes that are built upon and hierarchical type of inheritance using classes.
existing classes. When you inherit from an existing
class, you can reuse methods and fields of the Java does not support multiple and hybrid
inheritance with classes.
parent class. Moreover, you can add new methods
and fields in your current class also. Q. 10. Every class in Java has immediate
superclass but several
Q. 7. Members that are accessible inside their own
class as well as in all subclass of their class, (A) one, subclass (B) multiple, superclass
regardless of whether subclass exist in the same (C) two, superclass (D) none of these
package or any other package are defined with Ans. Option (A ) is correct.
access specifier Q. 11. The ability of an object to take many forms is
(A) private (B) public known as: [ISC Sem-2 Paper 2021-22]
(C) protected (D) default (A) inheritance (B) data abstraction
Ans. Option (C) is correct. (C) overriding (D) polymorphism
Explanation: The protected access modifier is Ans. Option (D) is correct
accessible within package and outside the package
Explanation: It is actually the ability for a message
but through inheritance only. The protected access
modifier can be applied on the data member, / data to be processed in more than one form. The
word polymorphism indicates many-forms. So, if a
method and constructor. It can't be applied on
the class. It provides more accessibility than the single entity takes more than one form, it is known
default modifier.
as polymorphism.

SUBJECTIVE TYPE QUESTIONS


Answer Type -k
<&\ Short
Questions-I (2 marks) Answering Tip
Q. 1. Differentiate between this keyword and super w Java Keywords must be learnt and practiced in
keyword. [ISC 2015] programs for better understanding.
Ans. IHJ±S ( ) is used to refer to the instance variables Q. 2. State two advantages of using the concept of
of the class. inheritance of Java. [ISC 2014]
super ( ) is used to invoke the super class's
Ans. (i) Reusability
constructor/ instance variable/methods.
(ii) Transitive nature. [ISC Marking Scheme 2014]
[ISC Marking Scheme 2015]

Examiner's Comment
Examiner's Comment
w A number of candidates were not aware of the
w Examples were used for a number of candidates advantages of inheritance. Some used examples
to show the difference. In some cases, only 'super' while others explained in their own words. A few
keyword was explained. candidates wrote the definition instead of the
advantages.
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES 177
In Java programming, inheritance used as:
Answering Tip (i) Similarities: Whenever there are similarities
between two more classes, apply inheritance.
w Advantages and need for inheritance should be ii
( ) Extraction: If a new class to be defined has
learned properly. certain features in addition to the features of
an existing class, use inheritance and code
only the additional features of this new class.
Detailed Answer: (iii) Combination: If a class is inherited from
Following are the advantages of inheritance: more than one class, it results in multiple
(i) Reuse the existing code and extend the inheritances. Multiple inheritance combine
functionally. features from more than one existing class.
(ii) Add new members to the derived class to Q. 6. What is meant by visibility mode in the definition
specialize the class. of derived classes in Inheritance? Explain any two
(iii) Replace the implementation of existing visibility modes available. [ISC 2007]
methods by overriding a method that already Ans. Visibility mode in case of derived classes modifies
exists in the base class. the accessibility of the superclass member in the
Q. 3. Define encapsulation and polymorphism. derived class. Two visibility modes available are
[ISC 2006] explained below:
Ans. Encapsulation: It is the mechanism that binds Protected Members are accessible inside their
own class as well as in all subclasses of their class,
together code and the data it manipulates.
Encapsulation is the wrapping up of data and regardless of whether subclasses exist in the same
methods into a single unit (called class). package or any other package.
Private Members are accessible only to the class in
which it is defined.
Class
Liquid
I Long Answer Type
Method Data Coffee Milk
Questions -I (5 marks)
Q. 1. A super class Product has been defined to store
Polymorphism
Encapsulation the details of a product sold by a wholesaler to a
retailer. Define a sub class Sales to compute the
Polymorphism: It means the ability to take more total amount paid by the retailer with or without
than one from, i.e., the same operation may behave fine along with service tax. [ISC 2017]
differently in different situations.
Class name : Product
Q. 4. How can we override a method in inheritance? Data member/instance variable:
[ISC 2011] name stores the name of the
Ans. Overriding: Overriding is the ability to define a product
behaviour specific to the subclass type which means code integer to store the
a subclass can implement a parent class method product code
based on its requirement. Overriding means to amount stores the total sale
override the functionality of an existing method .
amount of the product (in
Rules for Method Overriding decimals)
(i) The argument list should be exactly the same Member functions/methods:
as that of the overridden method. Product(String parameterized constructor
(ii) Instance method can be overridden only if n, to assign data member
they are inherited by the subclass. int c, double p ) name = n, code = c and
(iii) A method declared as final cannot be amount = p
overridden. void showQ displays the details of the
(iv) A method declared as static cannot be data members
overridden but can redeclared.
Class name : Sales
Q. 5. Define inheritance. How is it useful in Data member/instance variable:
programming? [ISC 2009]
day stores number of days taken
Ans. Inheritance: It is the ability to derive something
to pay the sale amount
from something generic. Inheritance aids in the
reuse of code, i.e., a class can inherit the features tax to store the service tax (in
of another class and add its own modification. The decimals)
parent class is known as the superclass or base totamt to store the total amount (in
class and the newly created child class is known as decimals)
the subclass or derived class.
178 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class-XII
I
Q. 2. A super class Bank has been defined to store the
Member functions/methods:
details of a customer. Define a sub-class Account
Sales ( ... ) : parameterized constructor that enables transactions for the customer with
to assign values to data the bank. The details of both the classes are given
members of both the below:
classes. Class Name : Bank
void : calculates the service tax Data member/instance variable:
compute( ) @ 12.4% of the actual sale name stores the name of the
amount customer
Calculates the fine @ 2.5% accno stores the account number
of the actual sale amount P : stores the principal
only if the amount paid amount in decimals
by the retailer to the Member functions/methods:
wholesaler exceeds 30 days Bank ( ... ) parameterized constructor
calculates the total amount to assign values to the
paid by the retailer as instance variables
(actual sale amount + void display () displays the details of the
service tax + fine ) customer

void show() : displays the data members Class Name : Account


of super class and the total
Data member/instance variable:
amount
amt : stores the transaction
Assume that the super class Product has been amount in decimals
defined. Using the concept of inheritance,
specify the class Sales giving the details of the Member functions/methods:
constructor ..), void compute() and void show(). Account( ... ) : parameterized constructor
^
The super class, main function and algorithm need to assign values to the
NOT be written. instance variables of both
Ans. import java .util.Scanner; the classes
public class Sales extends Product void deposit( ) : accepts the amount and
{ updates the principal as
static Scanner sc = new Scanner(System. p = p + amt
in) ;
void withdrawQ : accepts the amount and
int day;
Ploat tax; updates the principal as
double totamt; p = p - amt
Sales (int d , float t, double a , If the withdrawal amount
String name, int code, float aa) is more than the principal
{ amount, then display the
super ( name, code, aa) ; message "INSUFFICIENT
day = d ; BALANCE".
tax = t; If the principal amount
totamt = a ; after withdrawal is less
than 500, then a penalty
void compute ( ) is imposed by using the
{ float time = 0.0 ; formula p = p - (500 - p)/10
tax = a * 0.124;
if (day > 30)
void display( ) : displays the details of the
fine = a * 0.025;
totamt = a + tax + fine; customer
Assume that the super class Bank has been
void show ( ) defined. Using the concept of Inheritance,
{ specify the class Account giving details of the
super.show ( ) ; constructor(...), void deposit(), void withdraw()
System.out.println (totamt); and void display().
The super class and the main function need not
be written. [ISC 2016]
I.Ans import java.util.Scanner;
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES 179
w Learn different visibility modes and their accessing
public class Account extends Bank capability. Knowledge of calling the member
i static Scanner sc function from the super class to the derived class
= new Scanner(System.in); must be made clear.
double amt;
w Students should read the question properly (base
Account(String n, String a, double class not required) and answer accordingly.
PP)
{ super(n, a, pp); Q. 3. A super class Account contains employees details
amt = 0.0; and a sub class Simple calculates the employee's
}
simple interest. The details of the two classes are
void deposit( ) given below:
{ System.out.print("\n Enter
amount");
|
||[ISC Specimen Question Paper 2016]
amt = sc.nextDouble(); Class name § Account
p = p + amt; Data members:
} Name : stores the employee name
void withdraw ) ) Pan : stores the employee Pan
{ number
System.out.print("\n Enter Principal store the Principal amount
:
amount");
(in decimals )
amt = sc.nextDouble( );
if(amt > p)
_
acc no : stores the employee bank
System.out.Println account number
("INSUFFICIENT BALANCE"); Member functions/methods:
else Account ) ... ) : parameterized constructor
{ P = P amt; to assign value to data
if(p < 500) members
P = P (500 - p)/10; void display ) ) : to display the employee
} details
void display ( )
Class Name : Simple
super . display( ); Data members:
} time : store the time duration
[ ISC Marking Scheme 2016] rate : stores the rate of interest
interest : stores the simple interest
Member functions:
Examiner's Comment Simple ( ....) : parameterized constructor
to assign value to data
w The concept of inheritance was not clear to some members of both the
candidates. Constructor with inheritance was not
classes
answered correctly. Accessing the members of the
void calculate ) ) : calculate the simple
super class by the derived class was not clear to
interest as (Principal x
several candidates.
time x rate )/100
w A few candidates declared the base class also, void display ( ) : display the employee
which was not required. Data members were not details alongwith the rate,
declared properly by some students. The function time and interest
withdraw () in the derived class was not answered
Assume that the super class Account has been
properly. In some cases, algorithm was written
instead of a program. The rest of the function defined. Using the concept of inheritance, specify
were well answered by the candidates. the class simple giving details of constructor, void
calculate )) and void display (). The super class
and the main)) function need not be written.
Answering Tip Long
Very Answer Type
<& Questions (10 marks)
w Practice should be done on inheritance. Use of
constructor using the base class member must be Q. 1. A line on a plane can be represented by coordinate
made clear. of the two-endpoints pt and p2 as p Xj, yt ) and
p2(x2A y i )- ^
||
* These questions are for practice and their solutions are available at the end of the chapter
180 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class- XII
A super class Plane is defined to represent a line xl = nx;
I
and a sub class Circle to find the length of the yl = ny;
radius and the area of circle by using the required }
data members of super class. void Show ( )
Some of the members of both the classes are given
below: [ISC 2015] System.out.printIn

Class name : Plane


-
("x coordinate=" +xl);
System.out.printIn
Data member/instance variable: ("y-coordinate="+yl);
Xl : to store the x-coordinate of }
the first end point
Yi : to store the y-coordinate of public class Circle extends Plane
the first end point {
Member functions/methods: double x2, y2, radius, area;
Plane (int nx, : parameterized constructor Circle(double nx, double ny, double
int ny) to assign the data members a, double b)
xx = nx and yx = ny super(nx, ny);
void Show ( ) : to display the coordinates x2 = a;
y2 = b;
Class name : Circle }
Data member/instance variable: void findRadius( )
*2 : to store the x-coordinate of
the second end point radius = (Math.sqrt(Math.Pow
y2 : to store the y-coordinate of ((x2 - xl), 2) + Math.pow
the second end point ((y2 - yl), 2)))/2;
radius : to double variable to store }
the radius of the circle void findArea( )
area : double variable to store the
area of the circle area = 3.14*radius*radius;
}
Member functions/methods: void Show( )
Circle ( .. . ) : parameterized constructor
to assign values to data super.Show( );
members of both the classes System.out.printIn("Second
void find : to calculate the length of x-coordinate=" +x2);
Radius () radius using the formula: System.out.printIn("Second
y-coordinate=" +y2);
J x -x + y -y
( 2 1)
2 (
1
/2
1)
2
System.out.printIn("Length of
assuming that xv yv y2
xy radius =" +radius);
are the coordinates of the System . out . println(" A r ea = "
two ends of the diameter of a +area);
circle }
void find : to find the area of circle using [ISC Marking Scheme 2015]
Area() formula: nr1. The value of pie
( TT ) is 22/7 or 3.14
void Show () : to display both the Examiner's Comment
coordinates along with the
length of the radius and area The concept of inheritance was not clear to
of the circle . a number of candidates. Constructor with
Specify the class Plane giving details of the inheritance was not answered correctly. Accessing
constructor and void Show (). Using the concept the members of the super class by the derived
of inheritance, specify the class Circle giving class, Mathematical functions Math.pow () and
details of the constructor, void find Radius Math.sqrt () were not clear to several candidates.
( ), void find Area ( ) and void show ( ) . In some cases, double data members were not
The main function and algorithm need not be declared properly. Invoking the show () function
written. in the derived class was not answered properly
by a few candidates. In some cases, algorithm
Ans . public class Plane was written instead of a program. The rest of the
{ double xl, yl; function were well answered.
Plane(double nx, double ny)
I INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES 181
Specify the class Stock giving details of the
Answering Tip constructor and void display() . Using concept
of inheritance, specify the class Purchase giving
details of the constructor, void update() and void
w Practice should be done on inheritance. Use of
constructor using the base class member should
display(). The main() function and algorithm
need not be written.
be clear.
w Students should know the different visibility Ans . import java , io.*;
modes and their accessing capability. Knowledge class Stock
of calling the member function from the super
class to the derived class must be clear. The //starting of super class
keyword 'extends' and 'super ' must be given
public String item;
special attention while dealing with inheritance.
public double qty, rate, amt;
public Stock(String ite, double
Q . 2. A superclass Stock has been defined to store qt, double r)
the details of the stock of a retail store . Define
a subclass Purchase to store the details of the
items purchased with the new rate and updates item = ite;
the stock . Some of the members of the classes are qty = qt;
given below: [ISC 2014] rate = r;

Class name Stock amt = qty*rate;


}
Data member/instance variable:
public void display()
item to store the name of the item
qty to store the quantity of an
System.out.printIn("Item
item in stock
name:"+item);
rate to store the unit price of an
System.out.println("Quantity
item of item:" +qty);
amt to store the net value of the System.out.println("Unit price
item in stock of item:" Irate);
Member functions/methods: System.out.println("Net value
Stock ( . . . ) parameterized constructor of item:" +amt);
to assign values to the data }
members .
void display ( ) to display the stock details class purcahase extends Stock
{
Class name Purchase //starting of subclass
Data member/instance variable: public double pqty, prate;
pqty to store the purchased public Purchase (double pq, double
quantity pr, String ite, double qt,int r)
prate to store the unit price of the
purchased item super (ite, qt, r);
Member functions/methods: pqty = pq;
Purchase ( . . . ) parameterized constructor prate = pr
to assign values to the data }
members of both the classes public void update()
void update ( ) to update stock by adding
the previous quantity by qty = qty + pqty;
the purchased quantity if (rate! = prate)
( quantity*unit price )
rate = prate;
void display ( ) to display the purchase
details before and after
amt = rate*qty;
updation }
182 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class-XII

public void display( ) Class Name Perimeter


I
Data member/instance variable:
System . out. println ("Previous a to store the length in decimal
details:");
b to store the breadth in decimal
super.display();
Member functions:
update();
perimeter ( ...) parameterized constructor to
System .out.println("New assign values to data members
details:");
double calculate and return the
super.display( ); calculate () perimeter of a parallelogram
} as 2*(length + breadth )
[ISC Marking Scheme 2014] void show ( ) to display the data members
along the perimeter of the
parallelogram
Examiner's Comment
Class Name Area
w The concept of Inheritance was not clear to a
number of candidates. In several cases, the amount Data member/instance variable:
was not calculated, but passed as parameter/ h to store the height in decimal
argument. Constructor with inheritance was not
answered correctly by some candidates. Accessing area to store the area of the
the members of the super class by the derived parallelogram
class was not clear to- many candidates. Keywords
'extends' and 'Super ' were found to be missing in
Member functions:
some cases. Area (...) parameterized constructor to
w A number of candidates declared the base assign values to data members
class data members as private. Double data of the classes
members were not declared properly by some void doarea () compute the area as
students. Invoking the update () function in ( breadth ’’ height )
'

the display () function of the derived class was


not answered properly. In a few cases, the void show () display the data members of both
algorithm was written instead of a program. classes along with the area and
perimeter of the parallelogram
Specify the class Perimeter giving details of the
Answering Tip constructor, double calculate() and void show().
Using the concept of inheritance, specify the
w Students should read the question properly and class Area giving details of the constructor, void
answer accordingly. doarea() and void show().
w Use of constructor using the base class member The main() function and algorithm need not be
should be clear. written.
w The different visibility modes and their accessing Q. 4. A superclass detail has been defined to store
capability should be learnt. Calling member the details of a customer. Define a subclass Bill
function from the super class to derived class to compute the monthly telephone charge of the
must be clear. customer as per the chart given below: [ISC 2012]
w More practical based on inheritance, involving Number of Calls Rate
functions from super class must be done.
1-100 Only rental charge

Q. 3. A superclass Perimeter has been defined to 101-200 60 paisa per call + rental
calculate the perimeter of a parallelogram. charge
Define a subclass Area to compute the area of the 201-300 80 paisa per call + rental
parallelogram by using the required data members charge
of the superclass. The details are given below:
| above 300 1 rupee per call + rental
| [ISC 2013]
charge

These questions are for practice and their solutions are available at the end of the chapter
I Details of both the classes are given below:
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES
address = ad ;
183

telno = t;
Class Name Detail
rent = r ;
Data member/instance variable:
}
name to store the name of the void show()
customer
address to store the address of the System.out.println(“ Name of customer ”
customer + name) ;
telno to store the phone number of System.out.println(“Addres of customer”
the customer +addresses) ;
rent to store the monthly rental Systm.out. println(“Telephone no.”
charge +telno) ;
Member functions:
System.out.println(“ Rent” + rent) ;

Detail(...) parameterized constructor to


}
assign values to data members
class Bill extends Details
void show () to display the details of the
customer
int n ;
Class Name Bill
double amt;
Bill (String na , String a , int te, double re , int c)
Data member/instance variable:
n to store the number of calls super (na , a , te, re) ;
amt to store the amount to be paid n = c;
by the customer amt = 0.0;
Member functions: }
Bill (...) parameterized constructor to void cal ( )
assign values to data members
of both classes and to initialize if (n >= 1 && n < = 100)
amt = 0.0 amt = rent;
void cal() calculate the monthly else if (n > = 101 && n < = 200)
telephone charge as per the amt = rent + (0.60*(n - 100));
chart given above else if (n >= 201 && n < 300)
void show() display the details of the amt = rent + (0.60*100)
customer and amount to be + (0.80(n - 200)) ;
paid else
Specify the class detail giving details of the amt = rent + (0.60*100) + (0.80 * 100)
constructor and void show(). Using the concept of + (n - 300)*100;
inheritance, specify the class Bill giving details of }
the constructor, void cal() and void show(). void show()
The main() function and algorithm need not be
written.
super.show( );
Ans. class Detail
System.out.println(“Amount to be paid
{ =” +amt/100 + “ Rs ”) ;
protected String name, address;
protected int telno ;
protected double rent; Q. 5. A superclass Record has been defined to store
Details (String n , String ad , int t , double r) the names and ranks of 50 students. Defined a
{ subclass Rank to find the highest rank alongwith
name = n ; the name. The details of both classes are given
below: [ISC 2011]
184 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
BufferedReader b = new BufferedReader
I
Class Name Record
(new InputStreamReader(System.in)) ;
Data member/instance variable: System.out.println(“ Enter the name and
name [] to store the names of students rank of 50 students ”)
for (int i = 0; i < 50; i++)
mk [] to store the rank of students
Member functions: name [i] = b.readLine ();
mk [i] = Integer. parseInt (b.readLine ( )) ;
Record () constructor to initialize data
members }
}
void to store the names and ranks
void display ( )
readvalues ()
void display display the names and the system.out. printlnfName” + “\t” + “ Rank ”)
0 corresponding ranks for (int i = 0 ; i <= 49; i++)

Class Name Rank System.out.println(name[i] + “\t”


Data member/instance variable: + mk [i])

index integer to store the index of


the topmost rank
}
Member functions: class Rank extends Record
Rank () constructor to invoke the
base class constructor and to int index;
initialize index = 0 Rank ( )
void highest( ) finds the index/location of
the topmost rank and stores super ( ) ;
it in index without sorting the index = 0;
array }
void display ()
void highest ( )
display the names and ranks
alongwith the name having
the topmost rank int h = mk [0] ;
for (int i = 1; i < 50; i++)
Specify the class Record giving details of the
constructor, void readvalues() and void display().
Using the concept of inheritance, specify the class if (h > rnk [i])
Rank giving details of constructor, void highest()
and void display(). h = mk [i] ;
The main() function and algorithm need not be index = i;
written. }
Ans. Import java .io.*; }
class Record
void display ( )
{
String name [ ] ;
super.display ( ) ;
int mk [ ];
System.out.println(“The student having
Record ( ) the topmost Rank is ” +name[index]) ;
{
name = new String [50] ;
mk = new int [50]; Q. 6. A superclass Worker has been defined to store the
} details of a worker. Define a subclass Wages to
void readvaluesQ throws IOException compute the monthly wages for the worker. The
{
I details/specification of both the class are given
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES
Design a class Library and another class Compute
185

below: | §) [ISC 2010] to perform the task. The details of the two classes
are given below:
Class Name Worker
Class Name Library
Data member/instance variable:
Data member/instance variable:
Name to store the name of the worker
name to store name of the book
Basic to store the basic pay in
author to store author of the book
decimals
P to store price of the book in
Member functions:
decimals
worker ( ...) parameterized constructor to Member functions:
assign values to the instance
Library ( ...) parameterized constructor to
variables assign values to data members
void display () display the workers details of both the classes
void show ( ) displays the book details
Class Name Wages
Data member/instance variable: Class Name Compute
hrs store the hours worked Data member/instance variable:
rate stores rate per hour d number of days taken in
store the overall wage of the returning the book to store the
wage
fine
worker
Member functions:
Member functions:
Compute ( ...) parametrized constructor to
Wages ( ...) Parameterized constructor to
assign values to data members
assign values to the instance
of both the classes
variables of both the classes
void fine ( ) calculates the fine for the
double Calculate and returns
excess days
overtime ( ) the overtime amount a
( hours’’ rate )
' void display display the book details
void display Calculate the wage using the
0 alongwith the number of
days, fine and the total (0.2%
0 formula wage = overtime of price of book*total no. of
amount + Basic pay and days) + fine
display it along with the other
details Specify the class Library giving the details of the
constructor and void show( ). Using the concept
Specify the class Worker giving details of the of Inheritance, specify the class Compute giving
constructor and void display( ). Using the concept the details of constructor, void fine( ) and the
of inheritance, specify the class Wages giving void display( ) function. You need not to write the
details of constructor, double overtime( ) and void main( ) function.
display( ). The main( ) function need not to be .
Ans class Library
written.
{
..
Q 7 A library issues books on rental basis at a 2%
String name;
charge on the cost price of the book per day As . String author ;
per the rules of the library, a book can be retained
.
for 7 days without any fine If the book is returned float p;
after 7 days, a fine will also be charged for the Library (String n , String a , float amt)
excess days as per the chart given below: {
[ISC 2009]
name = n ;
author = a ;
Number of Excess Days
1 to 5
Fine per Day ( )
2.00
^ p = amt;
6 to 10 3.00 }
Above 10 days 5.00 void show ( )
{
||
* These questions are for practice and their solutions are available at the end of the chapter
186 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
System.out.println(“ Book Name = ” Q. 8. A class Employee contains employee details and
I
+ name) ; another class Salary calculate the employee's net
Sytem.out.Println ( Author Name = ”
“ salary. The details of the two classes are given
+author) ; below: [ISC 2008]
System.out.println(“ Print = ” + p) ; Class Name Employee
}
Data member/instance variable:
}
class Compute extends Library empNo to store the employee number
empName to store the employee name
int d ;
float f , total; empDesig to store the employee's
Compute (String n , String a , flaot amt, int designation
days) Member functions:
Employee ( ) default constructor
super (n , a , amt) ;
d = days; Employee ( ...) Parameterized constructor to
assign values to employee
f = 0;
number, name and designation
total = (float)((0.2*p)*d) ;
} void display display the employee details
void fine ( ) 0
Class Name Salary
if (d > 7)
Data member/instance variable:
d = d - 7; basic float variable to store the basic
if (d < = 5) pay
Member functions:
f = 2*d ;
Salary (...) parameterized constructor to
assign values to data members
else if (d <= 10)
void calculate () calculate the employee's net
salary according to following
f = 1 0 + ((d - 5)*3);
rules:
} DA = 10 % of basic
else HRA = 15% of basic
Salary = basic + DA + HRA
f = 10 + 15 + ((d - 10)*5); PF = 8% of Salary
Net salary = Salary - PF
Display the employee details
d = d + 7; and the Net salary.
total = total + f ; Specify the class Employee giving details of
} the constructors and member function void
display ( ). Using the concept of inheritance,
void display ( )
specify the class Salary giving details of
{ constructor and the member function void
show ( ) ; calculate( ). The main( ) function needs to be
System.out.println(“ Book taken for = ”+d written.
“ days ”) ; Ans. class Employee
System.out.println( Total fine = Rs. ” +f ) ;

System.out.println(“Total amount to be int empNo;
paid = Rs. ” +total) ; String empName ;
String empDesig;
Employee ( )
I INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES
register number, name of subject and marks
187

empNo = 0; obtained by the student. The details of both the


empName = “ ” classes are given below: #
[ISC 2007]
empDesig = “ ” Class Name Student
}
Data member/instance variable:
Employee (int n , String na , String ed)
{ name, sex array of characters (string )
empNo = n ; age integer variables
empName = na ; Member functions:
empDesig = ed ; void inpdetailsl to accept value for data
0 member
void display ( ) void showl () to display personal data of
{ student
System.out.println(“ Employee No: ”
+empNo) ; Class Name Marks
System.out.println(“ Employee Name: ” Data member/instance variable:
+empName) ; regnum, integer type variables
System.out.println( Employee
“ marks
Designation: ” +empDesig) ; subject array of character (string )
Member functions:
}
void inpdetails2( ) to accept values for data members
class Salary extends Employee
{ void show2 ( ) to display exam details
( regnum, marks, subject )
float basic, DA, HRA, PF, NS;
Salary (float b, int n , String na , String ed) (i) Specify the class Student giving details of the
{ function void inpdetailsl() and void showl().
super (n , na , ed); (ii) Using the concept of inheritance, specify the
basic = b ; class Marks giving the details of the functions
DA = 0; void inpdetails2() and void show2(). The
main() function need not to be written.
HRA = 0;
PF = 0 ; Q. 10. A class Iscscores defines the scores of a candidate
in six subjects and another class Bestfour defines
NS = 0;
the best four subjects. [ISC 2005]

void calculate ( ) The details of both the classes are given below:
Class Name Iscscores
DA = (float)(basic*(0.1)) ; Data member/instance variable:
HRA = (float)(basic*(0.15) ;
int number[6][2] to contain marks for six
float s = basic + DA + HRA; subjects and subject code
PF = (float)(s*(0.08)) ; [numeric]
NS = s - PF;
Member functions:
display ( ) ;
System.out.println(“ Net salary: ” + NS) ; Iscscores( ) Default constructor to accept
the marks
public static void main (String args [ ]) int point ( ) to return the point in each
{ subject according to the
Salary si = new Salary (5000, 101, following:
“Akash ” , “ Manager ”) ; -
Marks > = 90 1 point
sl.calculate ( ) ; -
80-89 2 point
-
70-79 3 point

} -
60-69 4 point

Q. 9. A class Student defines the personal data of a


-
50-59 5 point

student while another class Marks defines the


-
40-49 6 point

These questions are for practice and their solutions are available at the end of the chapter
188 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Class Name Bestfour


I
m = 3;
Member functions:
p=p+m
void Bestsubjects () to display the total point
}
and best four subject
codes using the concept of if ((number [i] [0] > = 60) &&
inheritance (number [i] [0] < = 69))
Specify the details of both the classes using the
concept of inheritance. Specify the details of the m = 4;
constructor Iscscores( ) and functions int point( ), p=p+m
void Best subjects( ). Other functions are written }
for you and you need not to write the main( ) if ((number[i] [0] >= 50) && (number[i]
function. [0] < = 59))
Ans. import java .io.*; {
class Iscscores m = 5;
{ p=p+m
int number [ ] [ ] ;
public Iscscores ( ) throws IOException if ((number[i] [0] > = 40) && (number[i]
[0] < = 49))
InputStreamReader in = New {
InputStream Reader (System.in) ; m = 6;
BufferedReader br = new Buffered p=p+m
Reader (in) ;
number = new int [6] [2] ; if ((number[i] [0] > = 30) && (numberji]
system.out. println(“Enter marks for 6 [0] < = 39))
subjects and subject code ”) ;
for (int i = 0; i < 6 ; i++) m = 7;
{ p=p+m
for (int j = 0; j < 2; j++) }
if ((number[i] [0] > = 20) && (numberji]
number [i][j] = Integer. parselnt(br. [0] < = 59))
readLine ( )) ;
m = 8;
} p=p+m
} }
int point ( ) if ((number[i] [0] > = 10) && (number[i]
{ [0] < = 19))
int p = 0, m ; {
for (int i = 0; i < 6 ; i++) m = 9;
p=p+m
if numberji] [0] >= 90)
if ((number[i] [0] > = 1) && (number[i]
m = 1; [0] <= 9))
p = p + m; {
} m = 10;
if ((number[i] [0] > = 80) && (number[i] p=p+m
[0] < = 89))

m = 2; return (p);
p=p+m }
}
if ((number[i] [0] > = 70) & & (number[i] Class Bestfour extends Isccores
[0] < = 79))
I INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES
Member functions/methods:
189

Bestfour ( ) throws IOException Godown ( ) :... parameterized constructor


to assign value to the data
Super ( ) ; members
} void display( ) : to display the stock details
void Best subjects ( ) Class name : Update
{ Data members/instance variables:
int t; _
pur qty : to store the purchase quantity
for (int i = 0; i < 6 ; i++) purrate to store the unit price of the
:
purchased item
for (int j = i + 1; j < 6 ; j++) Member functions / methods
Update(...) : parameterized constructor
if (number [i] [0] > number [j ] [0]) to assign values to the data
members of both the classes
t = number [i][0] ; void update( ) : to update the stock by adding
number [i] [0] = number[j] [0] ; the previous quantity by the
number [j] [0 ] = t; purchased quantity and replace
t = number [i][1]; the rate of the item if there is a
difference in the purchase rate.
number [i] [1] = number [j][l] ; Also update the current stock
number [j] [1] = t; value as: (quantity * unit price)
} void display( ) : to display the stock details
} before and after updating
} Assume that the super class Godown has been
t = 0; .
defined Using the concept of inheritance, specify
System.out.printlnfBest four subjects ”) ; the class Update giving details of the constructor,
System.out.println(“ Marks \t Subject void update ( ) and void display( ) .
Code ”) ; The super class, main function and algorithm
for (int i = 5; i > = 2; i - -) need NOT be written .
.
Ans import java .util .*;
System.out.println(number [i] [0] + “\t” class Godown
+ number [i] [l]) ;
} String item ;
t = super. point ( ) ; int qty, rate, amt;
System.out.println(“Total points are ” +t) ; Godown (String a , int b, int c)
}
item = a ;
. .
Q 11 A super class Godown has been defined to store qty = b ;
the details of the stock of a retail store Define a . rate = c;
subclass Update to store the details of the items amt = rate * qty ;
purchased with the new rate and update the }
.
stock Some of the members of both the classes
void display ( )
are given below: [4]
Class name : Godown
System.out.println (“item name= ” +
Data members/instance variables: item + “\n quantity = ” + qty + “\n rate = ”
item : to store the name of the item + rate + “ \n net amount = ” + amt) ;
qty : to store the quantity of an item }
in stock }
rate : to store the unit price of an class Update extends Godown
item
amt : to store the net value of the _ _
int pur qty, pur rate ;
item in stock Update (String a , int b, int c, int d , int e)
190 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
super (a , b, c) ; void display ( )
pur_qty = d ;
pur_rate = e ; System.out.println(“ previous details ”) ;
} super.display( ) ;
void update( ) update( ) ;
{ System.out.println(“ new details ”);
_
qty+ = pur qty ; super.displayO ;
_
if (rate!= pur rate)
_
rate = pur rate ;
amt = qty * rate ;

I Interfaces
Topic - 2 Concepts

Revision Notes
covered: Interface; Implementing Interface; Abstract class

> Interface: An interface in java is a blueprint of a class. It has static constants and abstract methods.
> Extending Interface: An interface can extend another interface in the same way that a class can extend another
class. The extends keyword is used to extend an interface.
> Marker Interface: An empty interface is known as tag or marker interface.
> Nested Interface: An interface which is declared inside another interface or class is called nested interface.
> Use of Java Interface: There are mainly three reasons to use interface:
• It is used to achieve abstraction.
• By interface, we can support the functionality of multiple inheritance.
• It can be used to achieve loose coupling.

|Key Terms
> Interface fields are public, static and final by default, and the methods are public and abstract.
• A class implements an interface, but one interface extends another interface.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


Q. 1. defines a protocol of behaviour. Ans. Option (B) is correct.
(A) Class (B) Abstract class Explanation: Interface is inherited by a class using
(C) Encapsulation (D) Interface implements.
Ans. Option (D) is correct.
Q. 4. Definition of interface begins with the word:
Explanation: Interface is inherited by a class using (A) class (B) public
implements.
(C) static (D) interface
Q. 2. can be implemented by any class
anywhere in the class hierarchy. Ans. Option (D) is correct.
(A) Encapsulation (B) Interface Explanation: interface keyword is used to declare
(C) Polymorphism (D) Inheritance an interface.
Ans. Option (B) is correct. Q. 5. Methods defined inside an interface are:
Q. 3. The keyword used by a class to acquire the (A) static (B) final
properties of an interface is: (C) abstract (D) override
(A) import (B) implements Ans. Option (C) is correct.
(C) extends (D) include
I
Q. 6. Data members of an interface are:
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES
hierarchy. Unrelated classes can implement the
191

(A) constants same interface.


(B) declared within public static final Q. 9. Statement-"A class can implement as many
(C) both (A) and (B) interfaces but can extend only one class" is:
(D) abstract (A) True
Ans. Option (C) is correct. (B) False
Q. 7. A class can implement interfaces. (C) True for first half only
(A) many (B) one (D) True for second half only
(C) two (D) none of these Ans. Option (A ) is correct.
Ans. Option (A ) is correct. Explanation: A class can extend only one class, but
Explanation: A class can implement more than one implement many interfaces.
interface at a time. Q. 10. Select the true statements among the following:
Q. 8. Which of the following is not true for an interface? (i) An interface can extend other interfaces
(A) No variable can be inherited from instances. (ii) A class can extend any number of classes
(B) Unrelated classes cannot implement the same (A) both (i) and (ii) (B) only (i)
interface
(C) only (ii) (C) none is true
(C) An interfaces cannot implement any methods.
(D) An interface cannot contain code. Ans. Option (B) is correct.
Explanation: An interface can extend another
Ans. Option (B) is correct.
interface in the same way that a class can extend
Explanation: An interface cannot implement any another class. The extends keyword is used to
methods, whereas an abstract class can. A class extend an interface, and the child interface inherits
can implement many interfaces but can have only the methods of the parent interface.
one superclass. An interface is not part of the class

SUBJECTIVE TYPE QUESTIONS


// declare methods that abstract
Short Answer Type
<@> Questions I - (2 marks) }
// by default.

Q. 1 What is an interface in Java? Q. 4 WAP to demonstrate the use of interface?


Ans An interface in java is a blueprint of a class. It has Ans. import java .io.*;
static constants and abstract methods. The interface interface ini
in Java is a mechanism to achieve abstraction.
There can be only abstract methods in the Java
{
interface, not method body. public static final int a = 10;
Q. 2 What is the use of interface?
void displayO ;
}
Ans There are mainly three reasons to use interface.
They are given below: class testClass implements ini
• It is used to achieve abstraction. {
• By interface, we can support the functionality of public void displayO
multiple inheritance. {
• can be used to achieve loose coupling.
It System.out.println(“ Hello ”) ;
Q.3 How do you declare an interface? }
Ans An interface is declared by using the interface
public static void main (String[] args)
keyword. It provides total abstraction, i.e. all the {
methods in an interface are declared with the testClass t = new testClass 0;
empty body, and all the fields are public, static t.display ();
and final by default. A class that implements an System.out.println(a) ;
interface must implement all the methods declared }
in the interface.
}
Syntax:
Output:
_
interface <interface name>{ Hello
// declare constant fields 10
192 Oswaal ISC Question Bank Chapterwise & TopLcwLse, COMPUTER SCIENCE, Class- XII
Q. 5 How is an interface similar to a class?
I
Ans. An interface is similar to a class in the following Answering Tip
ways —
• An interface is a blueprint of a class. w Java keyboards must be learnt and practiced in
programs for better understanding, especially in
• An interface can contain any number of methods.
• An interface is written in a file with a .java _
j
inheritance.

extension, with the name of the interface matching


Q. 9. Differentiate between the keywords extends and
the name of the file. implements. [ISC 2012]
• The byte code of an interface appears in a .class file. Ans. Difference between the keywords extends and
• Interfaces appear in packages, and their implements are as follows:
corresponding byte code file must be in a directory (i) When a class implements an interface, that
structure that matches the package name. class needs to implement all the methods
Q. 6 What are the properties of an interface ? declared in the interface but when a subclass
extends a superclass, it may not override the
Ans. Interfaces have the following properties — methods included in superclass.
• An interface is implicitly abstract. You do not need (ii) A class can implement multiple interfaces but
to use the abstract keyword while declaring an it can only extend from one superclass in Java.
interface. .
I Long Answer Type
• Each method in an interface is also implicitly
abstract, so the abstract keyword is not needed. |
<
& Questions (5 marks)
• Methods in an interface are implicitly public. Q. 1. An interface Data is defined with a data member
Q. 7. Define interface. How is it different from a class? and a method volume] ) which returns the
[ISC 2017] [ISC, Specimen Question Paper 2016] volume of the implementing shape. A super class
Base has been defined to contain the radius of
Ans. Interface Interfaces are basically a collection of
a geometrical shape. Define a sub class CalVol
methods which are public and abstract by default. which uses the properties of the interface Data
These interface do not have any method body. and the class Base and calculates the volume of a
Difference between interface and class are as cylinder.
follows: The details of the members of the interface and
Interface Class both the classes are given below:
Interface name : Data
It can only use the It can use various access
public access specifier. specifiers like public, Data member:
private or protected . double pi : initialize pi = 3.142
It cannot be used to It can be instantiated by Member functions/methods:
declare objects. It can declaring the objects. double volume] ) :
only be inherited by a Class name : Base
class. Data member/instance variable:
Q. 8. From the class declaration given below, state the rad : to store the radius in
nature of the identifiers A, B, C and D: decimal
Member functions/methods:
Class A extends B implements C, D [ISC 2016]
Base]... ) : parameterized constructor
Ans. A = Derived Class/Sub Class to initialize the data
B = Super Class/Base Class member
C = Interface void show] ) : displays the radius with an
appropriate message
D = Interface [ISC Marking Scheme 2016]
Class name : CalVol
Data member/instance variable:
Examiner's Comment ht : to store the height in
decimal
w Almost all the candidates answered this part Member functions/methods:
correctly. A few candidates were not able to CalVol]...) : parameterized constructor
identify the nature of C and D as interfaces. to initialize the data
members of both the classes
I double volume( )
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES

4. Abstract class can


193
Interface can't provide
: calculates the volume provide the the implementation of
of a sphere by using the implementation of abstract class.
formula (pi x radius2 x interface .
height) 5. The abstract The interface
void show( ) : displays the data members keyword is used keyword is used to
of both the classes and the to declare abstract declare interface.
class.
volume of the sphere with
appropriate message 6. An abstract class An interface can
can extend another extend another Java
Assume that the interface Data and the super
Java class and interface only.
class Base has been defined. Using the concept implement multiple
of inheritance, specify the class CalVol giving the Java interfaces.
details of the constructor)... ), double volume ) ) 7. An abstract class An interface class
and void show) ). can be extended can be implemented
The interface, super class, main function, and using keyword using keyword
algorithm need NOT be written. [ISC 2020] "extends". "implements".

Ans. class CalVol extends Base implements Data


8. A Java abstract Members of a Java
class can have interface are public by
{ double ht; class members like default.
CalVol(double r, double h) private, protected,
{ super (r); etc.
ht = h; 9. Example : Example :
public abstract class public interface
}
Shape ) Drawable)
public double volume)) public abstract void draw));
{ double x = pi * rad * rad * ht; void draw)); }
return x; }

} Q. 3. WAP in java to show the sound of animal with


the help of interface?
void show ))
Ans. interface Animal {
{ super.show ));
public void animalsound ));
System.out. println ("Height = " + ht);
// interface method (does not have a
System.out.println ("Volume = " body) public void sleep)) ;
+ volume)));
// interface method (does not have a
} body)
} [ISC Marking Scheme, 2020] }
Q. 2. Differentiate between an abstract class and an // Pig “implements ” the Animal
interface? interface class Pig implements
Animal
Ans.
{
Abstract class Interface public void animalsound ))
1. Abstract class Interface can have only {
can have abstract abstract methods. // The body of animalsound )) is
and non- Since Java 8, it can provided here
abstract methods. have default and static
System.out.println(“The pig says; wee
methods also.
wee ”) ;
2. Abstract class Interface supports
}
doesn' t support multiple inheritance.
public void sleep)) {
multiple
inheritance. // The body of sleep)) is provided
here
3. Abstract class can Interface has only
have final, non- static and final System.out.println(“ Zzz ”) ;
final, static and variables. }
non-static variables. }
194 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
class MyMainClass { Q. 7. What is the importance of interface?
I
public static void main (String[] args) { Ans. Following are the importance or benefits of
Pig myPig = new Pig() ; interface:
// Create a Pig object • Interface provides a contract for all the
myPig.animalSoundO ; implementation classes, so in terms of interface
it's good to code because implementation classes
myPig.sleepQ ;
cannot remove the methods we are using.

}
• Since a java class can implements multiple
interfaces at a time so it's better to use interfaces
Q. 4. WAP to demonstrate the use of multiple interface? as super class in most of the cases.
• The benefit of interface is it allows multiple
Q. 5. How an interface "extends" other interface? inheritance that thing is not possible with
Ans. interface Infl{ concrete classes and abstract classes.
public void method1() ; • With interfaces, implements keyword is to be
} used for implementing. Implements tells the
interface Inf 2 extends Infl { compiler that whatever classes are there after
public void method 2 () ; implementation, they are interfaces.
• An interface gives template structure of methods
public class Demo implements Inf 2{ from which new classes can be developed easily.
/‘Even though this class is only Very Long Answer Type
implementing the ®> Questions
<
(10 marks)
‘interface Inf 2, it has to implement all the
methods Q. 1 An interface Vehicle is defined with the methods
‘ Infl as well because the interface Inf 2
of changeGear(), speedup() and applyBrakes().
extends Infl Create the classes Bicycle and Bike which
7 implements the interface Vehicle.
public void method1(){
The details of the members of interface and both
System.out.println(“ methodl ”) ; the classes are given below:
public void method 2 (){ Interface Name Vehicle
System.out.println(“ method 2 ”) ; Member functions
}
public static void main (String args[]){ changeGear(int a)
Inf 2 obj = new Demo() ; speedupjint a)
obj. method 2 () ; applyBrakes(int a)
}
Class name Bicycle
Q. 6. What is the difference between a class and an Data members
interface in Java? Speed
Ans. Gear
Class Interface Member function
In class you can In an interface, you
, changeGear(int a) to change the gear of
instantiate variable and can't instantiate bicycle
create an object. variable and create an
object. speedup(int a) to increase the speed
of bicycle
Class can contain The interface cannot
concrete (with contain concrete(with applyBrakes(int a) to decrease the speed
implementation) implementation) of bicycle
methods methods Class name Bike
The access specifiers In Interface only one
used with classes are specifier is used- Public. Data members
private, protected and Speed
public. Gear

These questions are for practice and their solutions are available at the end of the chapter
I Member function
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES
// doing some operations
195

Bicycle bicycle = new Bicycle 0 ;


changeGear(int a) to change the gear of bicycle.changeGear (2) ;
bike bicycle.speedUp(3);
speedup(int a) to increase the speed bicycle.applyBrakes (1) ;
of bike System.out.println(“ Bicycle's present
applyBrakes(int a) to decrease the speed state
of bike bicycle. printStates();
Ans. import java .io.*; // creating instance of bike.
interface Vehicle { Bike bike = new Bike () ;
// all are the abstract methods. bike.changeGear (l);
void changeGear (int a) ; bike.speedUp(4) ;
void speedUp(int a) ; bike.applyBrakes(3) ;
void applyBrakes(int a) ; System.out.println(“ Bike 's present
state
}
class Bicycle implements Vehicle} bike.printStates() ;
int speed ; }
int gear ; }
Output:
public void changeGear(int newGear){
gear = newGear; Bicycle present state :
} speed : 2 gear: 2
public void speedup(int increment){ Bike present state :
speed = speed + increment; speed : 1 gear: 1
Q. 2 An interface Fly is defined with the methods
public void applyBrakes (int decrement)} goForward() and goDown().
speed = speed - decrement; Creates the classes Duck and Finch which
implements the interface Fly.
public void printStates() { The details of the members of interface and both
System.out.println(“speed: “ + speed the classes are given below:
+ "gear:" + gear) ;
Interface Name Fly
}
Member functions
class Bike implements Vehicle { goForward()
int speed ;
goDown()
int gear ;
public void changeGear(int newGear){ Class name Duck
gear = newGear; Member function
}
public void speedup(int increment){ goForward() prints the duck is flying
forward
speed = speed + increment;
goDownQ prints the duck is flying
public void applyBrakes (int decrement)} downward
speed = speed - decrement; Class name Finch
}
Member function
public void printStates() {
System.out.println(“speed: “ + speed goForward() prints the finch is flying
+ "gear:" + gear) ; forward
goDownQ prints the finch is flying
downward
class GFG { Create an interface and classes with their details
public static void main (String}] args) { given above. Design a main class which prints the
// creating an instance of Bicycle functionality of the classes.
196 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Solutions for Practice Questions


TOPIC-1 class Area extends Perimeter
5 Marks Questions
3. class Simple extends Account double h , area ;
Area (int aa , int bb, int hh)
Simple(String Name, int Pan , int Principal ,
_
int acc no, double time, float rate) super (aa , bb) ;
{ h = hh ;
_
super (Name, Pan , Principal , acc no) ; }
this.time = time ; public void doareaQ
this.rate = rate;
area = b*h;
interest = 0;
void showQ
void Calculate Q
{ super.show() ;
interest = (Principal*time*rate)/100; System.out.printlnfHeight” + h + “Area ”
} +area ) ;
public void display ( )
}
super.display ( ) ; 6. class Worker
System .out.printlnfRate: ” +rate) ;
System .out.printlnfTime:” +time) ; String Name ;
System , o u t . p r i n t i n g I n t e r e s t : ” float Basic;
+interest) ; Worker (String n , float b)

Name = n ;
10 Marks Questions Basic = b;
.
3 Class Perimeter
void display ( )
protected double a , b;
System.out.printlnfName is ”+ Name) ;
Perimeter (int aa , int bb)
System.out.printlnfBasic Salary is ”
+Basic) ;
a = aa ;
b = bb;
} class Wages extends Worker
double calculate ( )
int hrs, rate ;
double P; double wages;
P = 2*(a + b) ; Wages (int h , int r, String n , float b)
return P;
} super (n , b) ;
void show ( ) //using the constructor of base class
{ hrs = h ;
double P = calculate () ; rate = r;
System .out.printlnfperimeter of }
parallelogram with Length ” + a + “ and double overtime Q
Breadth ” + b + “is:” + P) ;
return hrs*rate;
}
I void display ( )
INHERITANCE, INTERFACES, POLYMORPHISM, DATA STRUCTURES

regnum = Integer.parselnt (br.


197

{ readLine ( )) ;
wage = overtime ( ) + Basic ; System.out.printlnfEnter subject”) ;
super.display( ); subject = br.readLine ( );
System .out.printlnfHours Worked = System.out.printlnfEnter marks ”);
” +hrs) marks = Integer.parselnt
System .out.printlnfRate per hour (br.readLine ( )) ;
=” + rate) }
System .out.printlnfTotal Wages= ” void show2 ( )
+wages)
} System.out.printlnfReg no. ” +
} regnum + “\nSubject” + subject
9. (i) import java.io.*; + “\nMarks ” + marks) ;
class Student
}
String name, sex; TOPIC-2
int age; 5 Marks Questions
void inpdetailsl( ) throws IOException 4. interface Firstlnterface {
{ public void myMethod () ;
InputSreamReader in = new Input // interface method
StreamReader (System .in) ;
interface Secondlnterface {
BufferedReader br= new Buffered
public void myOtherMethodQ ;
Reader(in) ;
// interface method
System out.printlnfEnter student
.
} // DemoClass “implements”
name ”) ;
Firstlnterface and Secondlnterface class
name = br.readLineO ; DemoClass implements Firstlnterface,
System .out.println (“ Enter sex”) ; Secondlnterface {
sex = br. readLine ( ) ; public void myMethod () {
System .out.printlnfEnter age ”) ; System.out.println(“ Some text..”) ;
age =Integer. parseInt (br.readLine ( )) ; }
public void myOtherMethod () {
void showl ( ) System.out.printlnfSome other
text...”) ;
System .out.printlnfName ” +name) ; }
System .out.printlnfSex” + sex +
“\nAge ” +age) ; class MyMainClass {
} public static void main (String[] args) {
} DemoClass myObj = new DemoClass() ;
(ii) class Marks extends Student myObj.myMethod ();
myObj.myOtherMethod () ;
int regnum ; }
int marks; }
String subject; 10 Marks Questions
void inpedetails2 ( ) throws IOException 2. interface Fly
{
InputStreamReader in = new void goForwardO ;
InputStream Reader (System .in) ; void goDownQ ;
BufferedReader br = new Buffered }
Reader (in) ; class Duck implements Fly
System .out.printlnfEnter reg. no”) ;
198 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

public void goForwardQ }


I
{ }
System .out.printlnfDuck going public class Bird {
forward ”) ; public static void main (String[] args) {
} Duck duck = new Duck ();
public void goDown () duck.goForwardO ;
duck.goDown () ;
System .out.printlnfDuck going Finch finch = new Finch () ;
down ”); finch.goForward ();
} finch.goDown () ;

public class Finch implements Fly {


public void goForwardQ { OUTPUT:
System .out.printlnfFinch is going Duck going forward
forward ”) ;
Duck going down
Finch is going forward
public void goDownQ {
Finch is going down
System .out.printlnfFinch is going
down ”) ;
SELF ASSESSMENT PAPER 4 -
Maximum Marks: 30 Timing: 1 Hour
1. What is inheritance hierarchy? [1]
2. What is the access control of protected members of a base class? [1]
3. How can a superclass constructor executed in subclass? [1]
4. What is interface? [2]
5. What is object in Java? [2]
6. What is an abstract class? How is it different from a concrete class? [2]
7. What is overriding of methods? Give example. [2]
8. Define two types of polymorphism in Java. [2]
9. Assume a class Derv derived from a base class Bare. Both classes contain a member function, func ( ) that takes
no arguments. Write the definition for a member function of Derv that calls furc ( ) from both the classes. [3]
10. Identify the errors in the following code:
public abstract class shapes
{
private double length ;
private double width ;
public void get dim ( )
{ Scanner sc = new Scanner (System.in) ;
System.out.println (“ Enter length ”);
length = sec. next Double ( ) ;
System.out.println . (“ Enter width ”) ;
width = sc. next Double ( ) ;
}
public void set dim double 1, double w)
{ length = 1;
width = w;

public abstract void area ( ) ;


public class Three D extends shapes
{
public Three D (double 1, double w)

length = 1;
width = w;
}
public void area (double 1, double w)

double vol = 1 * b * h ;
}
}

Also rectify these errors. [4]


200 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
.
11 Write a Java program to read and display information about employees and managers. Employee is a class
I
that contains employee number, name, address and department. Manager class contains all information of the
employee class and a list of all employees working under a manager. [5]
n
OSWAAL LEARNING TOOLS
For Solutions of the above Self Assessment Paper, follow the link

Visit: https:// bit.ly/ 3QtSV8u Or Scan the Code


CHAPTER

5 DATA
STRUCTURES
(a ) Basic data structures (stack, queue, dequeue ); implementation
directly through classes ; definition through an interface and multiple
implementations by implementing the interface. Conversion of Infix
to prefix and postfix rotations, ( b ) Single linked list ( Algorithm and programming), binary trees, tree
traversals (conceptual ).

I
Queues and Stacks Topic- 1
Conceptscovered: Queue; implementing
Queues using arrays; Insertion and
Queues and Stacks
.
Page No 201
Tonic -1 deletion in a queue; deque; Stacks;
^ Implementing Stacks as arrays; Push
and Pop in a stack; Conversion of an
Topic-2
Trees and Link list
algebraic expression from infix to prefix .
Page No 216
and postfix notation

m Revision Notes
QUEUE & DEQUEUE
> A Queue is a linear structure which follows a particular order in which the operations are performed.
> Queue obeys the FIFO (First In, First Out) manner. It indicates that elements are entered in the queue at the end
and eliminated from the front.
Queue
Insertion and Deletion
happen on different ends

Enqueue Dequeue
Enqueue Enqueue
> There are two different classes which are used to implement the Queue interface. These classes are:
• LinkedList
• PriorityQueue
> -
The Deque or (double ended queue) is also a type of queue that carries the inclusion and deletion of elements
from both ends.
> -
The deque is also considered thread safe.
> Enqueue: When an element is inserted in the queue, it is called enqueue.
> Dequeue: When an element is removed from the queue, this process is called dequeue.
202 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I

b(
.I
CD

—3
CD

Sit:
S «2 a
9.I

c
S

S
I
STACK
DATA STRUCTURES 203

> The stack is a linear data structure that is used to store the collection of objects.
-
> It is based on Last-In First-Out (LIFO).
> The stack data structure has the two most important operations that are push and pop.
> push(): When we insert an element in a stack then the operation is known as a push.
> If the stack is full then the overflow condition occurs.
> pop(): When we delete an element from the stack, the operation is known as a pop.
> If the stack is empty means that no element exists in the stack, this state is known as an underflow state.
Push

Last in, first out


Stack
Insertion and Deletion
happen on same end
Pop
Top
> Java collection framework provides many interfaces and classes to store the collection of objects.
Infix, Postfix, and Prefix
> Infix: The typical mathematical form of expression that we encounter generally is known as infix notation. In
infix form, an operator is written in between two operands.
For example, An expression in the form of A * ( B + C ) / D is in infix form.
> Prefix: In prefix expression, an operator is written before its operands. This notation is also known as "Polish
notation".
For example, The above expression can be written in the prefix form as / * A + B C D.
> Postfix: In postfix expression, an operator is written after its operands. This notation is also known as "Reverse
Polish notation".
For example, The above expression can be written in the postfix form as A B C + * D /.

|Key Terms
> Enqueue (qstore): adding an element to the queue at its rear
> Dequeue (qstore): deleting an element at the front of a queue.
> Empty: status of queue being Empty.
> Full: status of a queue being full.
> Front: Refers to the first element of the queue.
> Rear: Refers to the last element of the queue.

yf OBJECTIVE TYPE QUESTIONS (1 mark each)


..
Q 1 An overflow condition in a stack occurs when (C) circular queue (D) linked list
(A) both top and counter point to null. .
Ans Option (A) is correct .
(B) both top and counter point to 0 Q. 3. LIFO stands for:
(C) both top and counter point to same position Late In First Out
(A)
(D) top is equal to maximum capacity Linked Inversion For Output
( B)
.
Ans Option (D) is correct . Last In First Out
(C)
Explanation: When stack is completely full (i.e. First In Last Out
(D)
TOP = MaxSize-1) and we try to insert more .
Ans Option (C) is correct .
element onto stack then this condition is called
Explanation: LIFO is an abbreviation for last in,
overflow condition and no further element could
first out. It is a method for handling data structures
be inserted now until any element is deleted.
where the first element is processed last and the
..
Q 2 Nested method calls are implemented using: last element is processed first.
(A) stacks (B) queue
204 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 4. A Deque has: Q. 9. Consider the following queue
I
(A) both the ends open for insertion front ->• 12 37 45 68 rear
(B) both the ends open for deletion
What will be the structure of the queue after two
(C) both the ends open for both insertion and
pop operations and one push operation for value
deletion
79.
(D) One and open for insertion and other for both
(A) front ->• 45 ->• 68 ->• 79 rear
Ans. Option (C) is correct. (B) front ->• 12 ->• 37 -» 79 rear
Explanation: Deque is one of the data structures, (C) front ->• 79 ->• 45 ->• 68 rear
which is also called a double-ended queue in (D) front ->• 79 ->• 12 ->• 37 <- rear
which insertion and deletion operations can be
Ans. Option (A ) is correct.
performed from both the front of the end and rear
ends. Q. 10. Consider the following stack:
Q. 5. Which of the following is not an application of 89 <r- Top
stacks: 25
(A) Parenthesis matching 63
(B) Recursive function calls 47
(C) Solving maze problems The stack after two pops and one push with
(D) Round robing scheduling number 23.
Ans. Option (D) is correct. (A )
Q. 6. Which of the following is not an application of
queues?
(A) FCFS
(B) FIFO services (B )
(C) Round Robin Scheduling <- Top
(D) Infix to postfix conversion
Ans. Option (D) is correct.
(C)
Q. 7. A deque where insertion can be done at only one
end but deletion takes place at both ends is: <- Top
(A) open ended dequeue
(B) input restricted dequeue
(C) output restricted dequeue (D)
(D) restricted dequeue insertion <- Top
Ans. Option (B) is correct.
Q. 8. An underflow condition in a stack may occurs
Ans. Option (A ) is correct.
while operation.
(A) push (B) pop Explanation: In stack pop of an element from the
(C) peek (D) none of these Top only. So when two elements will be pop then
89, 25 will be removed. Then in stack, Pusp of an
Ans. Option (B) is correct. elements is also from the top, so element will be
Explanation: When a stack is empty (i.e. TOP = -1) add last after two elements of stack i.e. 47, 63 and
and we try to delete more element from it, then then 23 will be added.
this condition is called underflow condition.

SUBJECTIVE TYPE QUESTIONS

<&\ Very Short Answer Type


Questions (1 marks) <@> Short Answer Type
Questions-I (2 marks)
Q. 1. State the principle by which the stack data Q. 1. Convert the following infix notation to postfix
structure works. [ISC Sem-2 Paper 2021-22] notation:
Ans. Stacks are based on the LIFO principle, i.e., the A * (B + C / D J - E / F
element inserted at the last, is the first element to [ISC Sem-2 Paper 2021-22]
come out of the list.[ISC Marking Scheme, 2022] Ans. Given Infix String:
A * (B + C / D ) - E / F
I Current Postfix String
DATA STRUCTURES 205
Operator
token Stack Examiner's Comment
A A
w Most candidates were able to solve this problem
A correctly. Some candidates wrote correct answer
( *( A without showing the working. A few applied the
postfix correzctly, but could not derive the final
B *( AB answer.
+ *( + AB
Q . 5 . Differentiate between stack data structure and
C *( + ABC
Queue data structure.
/ * ( +/ ABC [ISC, Specimen Question Paper 2016]
D * ( +/ ABCD Ans . Differences between Stack data structure and
Queue data structure are as follows:
) ABCD/ +
Stack Data Structure Queue Data Structure
ABCD/ + *
In Stack, insertion and In Queue, insertion and
E ABCD/ + * E deletion operations are deletion operations
/ -/ ABCD/ + * E performed at the same are performed at the
end. different end .
F -/ ABCD/ + * EF
In Stack, an element In Queue, an element
ABCD/ +‘ EF/ which is inserted last which is inserted first
ABCD/ + * E F/- is first to delete. So it is is first to delete. So it is
called Last in First Out called First in First Out
The postfix notation is
(LIFO) (FIFO) .
ABCD/ + *E F/- In Stack, only one In Queue, two
Q . 2. Convert the following infix notation to prefix pointer I used called pointers are used
used form: TOP called FRONT and
REAR .
( X + Y) / ( Z * W / V ) In Stack, there is no In Queue, there is a
[ISC 2020] wastage of memory wastage of memory
space. space.
Ans. Infix to Prefix:
Q . 6. Convert the following infix Notation to postfix:
(X + Y) / (Z * W / V)
||
|[ISC, Specimen Question Paper 2016]
= + XY / ( * Z W / V ) A*(B/C)/E + F.
= + XY / /*ZWV Q . 7. Convert the following infix notation into postfix
= /+ XY/*ZWV form:
X + (Y - Z ) + ( (W + E ) * F) / J [ISC 2015]
= /+ XY/*ZWV
[ISC Marking Scheme, 2020] Ans . = X + ( Y - Z ) + ((W + E)* F) / J
Q . 3. Convert the following infix expression to postfix = X + YZ - + (WE + *F) / J
form: [ISC 2017] = X + YZ - + WE + F * J/
= XYZ - + WE + F * J / +
P * Q/R + ( S + T)
[ISC Marking Scheme 2015]
Ans. Infix to postfix: P* Q/R + (S + T)
= P*Q/R + ST +
= PQ7R + ST + Examiner's Comment
= PQ*R/ + ST +
w Most candidates were able to solve this problem
= PQ*R/ST + + correctly. Some candidates wrote the correct
[ISC Marking Scheme 2017] answer without sharing the working. Some
Q. 4. Convert the following infix expression to postfix applied the postfix correctly, but could not derive
form: the final answer.
A + B/C*(D/E*F) [ISC 2016]
Ans. A + B/C * (D/E *F) Answering Tip
= A + B/C*(DE/F*)
= A + BC/* (DE/F* ) w Examples need to be practiced with conversion of
= A + BC/DE/F** infix to postfix natation. The order of precedence;
= ABC/DE/F ** + [ISC Marking Scheme 2016] the polish stack method should be clear.

These questions are for practice and their solutions are available at the end of the chapter
206 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Q. 8. Convert the following infix expression into = A + (BC + ) + ((DE + ) * F)/G
I
postfix form. [ISC 2014] = A + (BC + ) + (DE + F*)/G
( A/B + C)*(D/E - F))
= ABC + + + (DE + F*)/G
Ans. In the above expression, = ABC + + DE + F* /G/+
= (A/B + C)(D/(E - F))* Q. 12. Convert the following infix expression to its
= (AB/ + C)(D/(EF-))* postix form. [ISC 2011]
= (AB/C + )(DEF -/)* a + b * c - d/e
After eliminating brackets, we get postfix form Ans. From above expression brackets will be eliminate
as per the operator precedence.
= AB/C + DEF-/* = a + b * c - (de/)
[ISC Marking Scheme 2014]
= a + (be*) - (de/)
Here + and - both have same precedence, so we
,
evaluate from left to right
Examiner's Comment
= (abc* + ) - (de/)
w Most candidates were able to solve this problem = (abc* + )(de/) -
correctly. Some candidates wrote the correct The postfix form is,
answer without sharing the working. Some = abc* + de/ -
applied the postfix correctly, but could not derive Q. 13. Convert the following infix notation to postfix
the final answer.
notation. 0
[ISC 2010]
(A + B)/C * (D + E)
Answering Tip Q. 14. Convert the following infix expression to its
postix form. [ISC 2009]
w The order of precedence was not clear and ((P * Q) / (R/S + T) + U)
placement of ' +' sign was improper in several Ans. From the above expression, eliminate the brackets
cases. as per operator precedence from left to right
associativity,
Q. 9. Convert the following infix notation to its postfix = ((PQ *) /(RS/ + T) ) + U
form. [ISC 2013] = (( PQ*) /( RS/T + )) + U
E*(F/(G-H)* I) + J = (PQ * RS/T +/) + U
Ans. First, we eliminate bracket content and them
convert it into postfix expression
= PQ * RS/T +/ U +
Q. 15. What do LIFO and FIFO stand for? Name a data
= E*( (FGH-/) *1) + J structure that follows LIFO principle and one that
= E* (FGH-/I*) + J follows FIFO principle. [ISC 2008]
= EFGH -/I** + J Ans. LIFO: Last In First Out
The postfix expression is FIFO: First In First Out
= EFGH -/I**J + The data structure that follows LIFO principle
Q. 10. Write the algorithm for push operation (to add is stack and the data structure that follow FIFO
elements) in an array based stack. [ISC 2013] principle is queue.
Ans. The algorithm for push operation to add elements Q. 16. Convert the following infix expression to its
in stack based on array, postfix form.
Step 1 if (t op = size - 1)
a/(b + c) + (d * (e - f )) [ISC 2008]
Step 2 return false //overflow error Ans. From the above expression eliminate the brackets
Step 3 else as per operator precedences from left to right
Step 4 top = top + 1 associativity,
Step 5 data [top] ((a/(b + c)) + (d * (e - f )))
Step 6 return true
= (a/(bc + )) + d * (ef -)
Q. 11. Convert the following infix notation to its postfix = (abc + /) + d* (ef - *)
form. [ISC 2012]
(A + (B + C) + (D + E) *F)/G = (abc +/) + (def - *)
Ans. First, we eliminate the inner brackets of the = (abc + /)(def -*) +
expression as per the operator precedence, The postfix expression is,
= A + (B+ C) + (D + E) * F/G = abc + / def - * +
These questions are for practice and their solutions are available at the end of the chapter
I
Q. 17. Convert the following infix expression to its
DATA STRUCTURES 207

postfix form.
Long Answer Type
(A + B*C)/(C - D*B )
[ISC 2007]
Questions -I (5 marks)
Ans. From the above expression eliminate the brackets Q. 1. A Queue is a linear data structure in which the
as per the operator precedence from left to right operations are performed based on FIFO (First In
associativity, First Out).
= (A + BC * ) / (C - DB * ) Define a class Queue with the following details:
= (ABC* + ) / (CDB*-) Class name : Queue
= ABC* + CDB*-/ Data member/instance variable:
The postfix expression is,
dat[ ] : array to hold the integer
= ABC* + CDB*-/ elements
Q. 18. Convert the following infix expression to its
cap : stores the maximum
postfix form. [ISC 2006]
capacity of the queue
A + [(B + C) + (D + E) * F] / G
Ans. In above expression eliminate brackets as per front : to point the index of the
operator precedence from left to right associativity, front
= A + [(B + C) + (D + E + )* F]/ G rear : to point the index of the
rear.
= A + [(BC + ) + (DE + ) * F] / G
= A + [(BC + ) + (DE + F*]/G Member functions/methods:
= A + [(BC + DE + F* + )/G Queue(int max) : constructor to initialize
the data member cap =
= A + [BC + DE + F* + G/]
max, front = rear = 0
= ABC + DE + F* + G/ + and create the integer
Q. 19. Define a queue. How is a dequeue different from array
a queue? [ISC 2006]
void add_dat(int v) : to add integers from the
Ans. Queue The queue can be formally defined as rear index if possible
ordered collection of elements that has two ends else display the
named as front and rear, from the front end one message("Queue full")
can delete the elements and from the rear one can
insert the elements. int pop_dat( ) : to remove and return
elements from front, if
A queue is a non-primitive linear data structure any, else returns -999
in which elements are inserted from one end and
deleted from another end and in dequeue both void display() : to display elements of
insertion and deletion operations can be performed the queue
at either end of the queue. Specify the class Queue giving the details of void
Q. 20. State the different applications of stack. add dat(int) and int pop_dat( ). Assume that the
[ISC 2005] other functions have been defined.
Ans. The different applications of stracks are: The main( ) function and algorithm need NOT be
(i) Parsing written.
(ii) Recursive function Ans. public class Queue
(iii) Nested function call
(iv) Expression conversion (infix to prefix, prefix _
void add dat (int v)
to infix, etc.)
(v ) Tower of Hanoi.
if (rear< cap)
Q. 21. Convert the following expression into postfix.
[ISC 2005]
(A + B/C) + B - C * D + C dat[rear] =v;
Ans. In above expression, eliminate the brackets as per rear=rear+l ;
operator precedence from left to right associativity. }
= (A + BC/) + B - CD* + C else
= (ABC/+ ) - (CD*) + C
= (ABC / + B + CD* - C + ) System.out.println(“ Queue full”) ;
The postfix expression is,
= ABC/ + B + CD *- C + }
208 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
_
int pop dat () Class Name : Book
I
Data member/instance variables:
if (front==rear) name [ ] : stores the names of the
{ books
System.out.println (“ UnderFlow”) ; point : stores the index of the
return -9999 ; topmost book
max : stores the maximum capacity
else of the bookshelf
Method/Member functions:
return dat [front++] ; Book (int : constructor to initialise the
cap) data members max = cap
} and point = -1
} void tell ( ) : displays the name of the
} book which we last entered
in the shelf. If there is
Q. 2. Queue is an entity which can hold a maximum of no book left in the shelf,
100 integers. The queue enables the user to add displays the message
integers from the rear and remove integers from "SHELF EMPTY"
the front. <§> [ISC 2017] void add : adds the name of the book
Define a class Queue with the following details: (String v) to the shelf if possible,
otherwise displays the
Class Name : Queue message "SHELF FULL"
Data member/instance variables: void display : display all the names of the
Que[ ] : array to hold the integer 0 books available in the shelf
elements Specify the class Book giving the details of Only
size : stores the size of the array the functions void tell ( ) and void add (String).
Assume that the other functions have been
rear : to point the index of the rear defined.
front : to point the index of the The main function need not be written.
front
Member functions: Ans. public class Book
{ String name [ ];
Queue (int : constructor to initialize the
mm) data size = mm, front = 0, int point, max;
rear = 0 Book (int cap)
max = cap;
void addele : to add integer from the rear
(int v ) if possible else display the point = -1;
massage "Overflow" name = new String [max] ;
int delele( ) : returns elements from
front if present, otherwise void tell ( )
displays the message { if (point < 0)
"Underflow" and return System out .print
,

-9999 (“\n SHELF EMPTY”) ;


void display : display the array elements else
0 System.out .print(“\n ” +name[i]) ;
Specify the class Queue giving details of ONLY
the functions void addele(int) and int delele(). void add (String v)
Assume that the other functions have been { if (point < max - 1)
defined. na me[+ + point] = %
The main function and algorithm need NOT be else
written. System.out .print
Q. 3. A bookshelf is designed to store the books in a ("\ n SHELF FULL”) ;
stack with LIFO(Last In First Out) operation.
Define a class Book with the following
void display ( ):
specifications: [ISC 2016]
These questions are for practice and their solutions are available at the end of the chapter
DATA STRUCTURES 209
{
System.out .print

for (int i = point; i >= 0; i- ) int popfront
0
: to remove the return
elements from front. If array
(“\n ” +name[i]) ; is empty then return-999
void : to add integers from the
[ISC Marking Scheme 2016] pushrear (int rear index if possible else
v) display the message ("full
from rear")
Examiner's Comments int poprear : to remove and return
0 elements from rear. If the
w The concept of stack was not clear to most of the array is empty then return
candidates. Common errors made by candidates
-999
were:
Specify the class DeQuque giving the details
w the condition/logic for underflow and overflow of ONLY the constructor (int), void pushfront
was not answered correctly.
(int) and int poprear (). Assume that the other
w the condition/logic for underflow and overflow functions have been defined.
was not answered correctly.
The main( ) function need not be written.
class DeQueue
Answering Tips
Ans. DeQueue (int max)
w Students should have the sufficient knowledge of
the following points while solving the problem of
data structure: cap = max;
w More practice on data structure programs like front = 0; rear = 0;
stack, queues, de queues, pointers, etc. ele = new int [cap];
w Continuous practice on functioning on each }
operation like LIFO and FIFO presented in the public void pushfront (int v)
given program of stack or queue.
if (front > 0)
Q. 4. A dequeue enables the user to add and remove
integers from both the ends, i.e., front and rear.
Define a class Dequeue with the following ele[- - front] = v;
details: [ISC, Specimen Question Paper 2016] }
Class Name : DeQueue else
Data members:
ele [ ] : array to hold the ineger
System.out.println(“ full from front”) ;
elements
cap : stores the maximum }
capacity of the array public int poprear ( )
front : to point the index of the
front if (rear - 1 < 0)
rear : to point the index of the rear
Member functions: return -999;
DeQueue (int : constructor to initialise the }
max) data member cap = max, else
front = rear = 0 and create
the integer array
return ele [rear - -] ;
void : to add integers from the
pushfront front index if possible else }
(int v) display the message ("full
front")
210 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class-XII
I
Very Long Answer Type
Questions (10 marks) char popChar( )

Q. 1. WordPile is an entity which can hold maximum if (top >= 0)


of 20 characters. The restriction is that a character return ch [top - -];
can be added or removed from one end only. else
[ISC 2015] return ‘\Y ;
Some of the members of class are given below:
Class Name : WordPile (b) Name of the Entity: Stack
Data members/instance variables: Application: UFO (Last In First Out)
Recursion
ch [ ] : character array to hold the
Undo
character elements
Infix to Postfix (anyone)
capacity : integer variable to store the [ISC Marking Scheme 2015]
maximum capacity
top : to point to the index of the
topmost element Examiner's Comment
Methods/Member Functions:
w The concept of stack was not clear to most of the
WordPile (int : constructor to initialise the candidates. Common errors made by candidates
cap) data member capacity = were: (i) the condition/logic for underflow
cap, top = -1 and create the and overflow was not answered correctly; (ii)
WordPile increment/decrement of top index was not done
v o i d : adds the character to the properly. The methods pushchar() and popchar()
pushChar top of WordPile if possible, were found to be difficult by some candidates.
Some were confused with the Character type array
(char v) otherwise output a message
and were not able to return properly. The class
"WordPile is full"
declaration and constructors was well answered.
char popChar : returns the deleted character
w Some candidates were unable to state the
0 from the top of the WordPile
applications and gave vague answers. Some
if possible, otherwise it candidates overlooked this part of the question.
returns '\Y
(a) Specify the class Word Pile giving the details
of the constructor, Answering Tip
void pushChar (char) and char popChar ().
The main function and algorithm need not be w . More practice should be done in data structure
written. programs like the stacks, queues, de queues, etc.
working must be shown as to how the stack or
(b) What is the name of the entity described a queue performs (examples can be supportive).
above and state one of its applications. The concept of LIFO and FIFO must be learnt
Ans. (a) public class WordPile by the students with examples from real world.
{ Implementation of stacks, queues and de queues
char ch [ ]= new char [20] ; using arrays should be emphasized. Only the
int capacity, top; concept has to be learnt taking the base as an
array. It should be made clear that it is not an
WordPile (int cap)
array related program which can be manipulated
by shifting / inserting or initializing by any value
capacity m cap ; since these data structures requires pointers and
top = -1; pointers are not supported in java. So, the array is
ch = new charfcapacity]; used to show the working of a stack, queue or a
de queue
void pushChar(char v)
w Stacks and Queues must be learnt in details giving
all its applications / uses.
if (top < capacity - 1)
ch[++top] = v; w Students should read the question carefully and
else answer accordingly.
System.out.println(“WordPile
is full”) ;
DATA STRUCTURES 211
Q. 2. A stack is a linear data structure which enables
the user to add and remove integers from one end
= new BufferedReader
(new InputStreamReader
only, using the concept of LIFO ( Last In First Out).
An array containing the marks of 50 students in
(System in));
,

ascending order is to be pushed into the stack. inti;


System.out.println
Define a Class Array to Stack with the following
details: [ISC 2014]
(“Enter array element:”);
for (i = 0; i < cap; i++)
Class Name Array to Stack
Data members/instance variables: m[i]= Integer.parselnt
m[] to store the marks. (br.readl .ine ( )) ;
}
st [] to store the stack elements.
int len = m.length ;
cap maximum capacity of the
int j,small, p, lemp;
array and stack.
for (i = 0; i < len; i++)
top to point the index of the
topmost element of the stack.
small = m[i] ;
Member Functions int pos m I;
_ _
Array to Stack Parameterised constructor to for( j = i + 1; j < len; j++)
(int n) initialise cap = n and top = -1. {
void input _ to input the marks from if (m[j] < small)
marks ( ) user and store it in the array
m[] in ascending order and
small = m[ j] ;
simultaneously push the
marks into the stack st[] P°s = j;
by invoking the function
pushmarks ().
temp = m[i] ;
v o i d to push marks into the stack at
pushmarks (int top location if possible, otherwise m[i] = m [pos];
v) display "not possible". m [pos] = temp;
int popmarks to return marks from the stack
pushmarks(m [i]);
0 if possible, otherwise returns
- 999.
void display to display the stack elements. void pushmarks (int v)
0
_ _
Specify the class Array to Stack giving the
if (top < cap)
_
details of the constructor (int), void input marks().
top++;
void pushmarks(int ). int popmarks() and void
display ( ). The main( ) function and algorithm st[top] = v;
need to not be written. System.out.println
(“ Element” +v+ “is pushed to
Ans. import java .io.*;
_ _
class Array to stack
stack!”) ;

else
public intm[ ] ;
public int st[ ], top;
System.out. println
public static int cap ;
(“not possible”) ;
pubic ArrayJoJStack (int n)

cap = n;
int popmarks ( )
top = - 1;
m = newinfc [n] ;
st - new int[n]; if (top >= 0)

voidinputmarks () throws IOException intx = st[top] ;

BufferedReader br
top |—
return x;
212 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Class Name Dequeue
I
else Data members/Instance variables:
arr [ ] array to hold upto 100 integer
return - 999 ; elements
lim stores the limit of the dequeue
front to point the index of the front
public void display ( )
end
rear to point the index of the rear
if (top > = 0) end.
Member Functions
System.outprintln
Dequeue (int constructor to initialise the
(“Elements in stack:”) ;
1) data members lim = 1; front =
for (int i = 0; i <= top; i++) rear = 0
{ void addfront to add integer from the front
System.out.println(st[i]); (int val ) if possible else display the
message ("Overflow from
1 front")
void addrear to add integer from the rear
(int val ) if possible else display the
[ISC Marking Scheme 2014] message ("Overflow from
rear")
int popfront return element from front,
Examiner's Comments 0 if possible otherwise return
-9999
w The concept of stack was not clear to most of the
candidates. Common errors made by candidates intpoprear () return elements from rear, if
were: possible otherwise returns -9999
w Incorrect declaration of array; (ii) the condition/ Specify the class Dequeue giving details of the
logic for underflow and overflow was not constructor (int). void addfront (int). void addrear
answered correctly. (int). int popfront ( ) and int poprear ( ). The main
function and algorithm need not to be written.
w Increment/decrement of top index was not done
Ans. Class Dequeue
properly; Top was initialized to 0 instead of - 1 in
some cases; The pushing of marks from array to
stack was confusing to many candidates; Some int arr [ ] ; //array to hold values
sorted the array and then pushed the values into int front , rear ;
the stack whereas in other cases it was directly
int lim ;
done; The methods pushmarks () and popmarks
() were found to be difficult by some candidates. public Dequeue (int 1)
The class declaration and construction were well
answered. lim = 1;
front = -1;
rear= - 1;
Answering Tip arr = new int [lim] ;
w More practice should be done in data programs
with the stacks, queues, de queues. Boolean isEmpty 0
if (front == rear)
Q. 3. A doubly queue is a linear data structure which
enables the user to add and remove integers return (true);
from either ends, i.e., from front or rear. Define a }
class Dequeue with the following details: public void addfront (int val)
[ISC 2013]
if (front == -1)
I front = 0; rear = 0 ; if (front == rear)
DATA STRUCTURES 213

arr [front] = val ; front = rear = - 1;


else
else if (front > 0 && front < arr.length) rear -
{ return element;
arr [- - front] = val ; }
}
else }
System .out. printin (“ overflow from Q. 4. Link is an entity which can hold a maximum
front”) ; of 100 integers. Link enables the user to add
} elements from the rear end and remove integers
from the front end of the entity. Define a class
public void addrear (int val)
Link with the following details: [ISC 2012]
{
if (rear == -1) Class Name Link
{ Data members/instance variables:
front = 0; rear = 0 ; lnk[ ] entity to hold the integer
arr [rear] = val; elements
max stores the maximum capacity
else if (rear + 1 < arr. length) of the entity
arr [++ rear] = val ; begin to point to the index if the
else front end
System .out. println(“ OVERFLOW end to point to the index of the rear
from rear ”) ; end
}
Member Functions
public int popfront ( )
{ Link (int constructor to initialise max =
mm ) mm, begin = 0, end = 0
int element ;
if (isEmpty ( )) void addlink to add an element from
(int v) the rear index if possible
return - 9999 ;
otherwise display the message
else "Outside of size"
{
int delink () to remove and return an
element = arr [front]; element from the front index,
if (front == rear) if possible otherwise display
front = - 1; the message "Empty..." and
rear = - 1; return -99
else void display display the element of the
front ++; 0 entity
return element; (i) Specify the class Link giving details of the
constructor (int ), void addlink (int ), int
} delink() and void display ().
public int poprear 0 The main( ) function and algorithm need to
{ be written.
int element ; (ii) Which type of data structure is the above
if (is Empty ( )) entity?
return - 9999 ; Q. 5. Stack is a kind of data structure which contains
else elements with the restriction that an element can
{ be added or removed from the top only.
[ISC 2011]
element = arr [rear] ;

||
* These questions are for practice and their solutions are available at the end of the chapter
214 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
The details of the class Stack is given below: ctr++ ;
I
Class Name Stack
}
Data members/instance variables:
String popname ( )
st [] the array to hold the names
size the maximum capacity of the
String S = “ » .
string array
if (top < 0)
top the index of the topmost
element of the stack
System.out.println (“ Underflow”) ;
ctr to count the number of
else
elements of the stack {
Member Functions S = st [top] ;
Stack () default constructor top - - ;
Stack (int parameterized constructor to ctr -
cap) initialise size = cap and top return S ;
=-l }
void to push a name into the stack }
pushname if the stack is full, display the void display ( )
(string n) message "OVERFLOW".
String removes a name from the top for (int i = 0; i <= top; i++)
popname () of the stack is empty, display System.out.println(st [i]) ;
the message "UNDERFLOW" }
void display display the elements of the
stack (ii) Stack works on LIFO ( Last In First Out)
(i) Specify class Stack giving details of the principle.
constructor, void pushname (String n), String Q. 6. Define a class Repeat which allows the user to
popname ( ) and void display ( ). add elements from one end (rear) and remove
The main ( ) function and algorithm need not elements from the other end (front) only.
to be written. [ISC 2010]
(ii) Under what principle does the above entity The following details of the class Repeat are
work? given below:
Ans. (i) class Stack
Class Name Repeat

String st [ ]; Data members/instance variables:


int size, top, ctr ; st[] an array to hold a maximum of
Stack 0 100 integer elements

cap stores the capacity of the array.


top = - 1; ctr = 0 ; size = 0 ;
f to point the index of the front.
Stack (int cap) r to point the index of the rear.
{
st = new String [cap] ; Member Functions
size = cap; Repeat (int constructor to initialise the
m) data number cap = m, f = 0,
top = -1
r = 0 and to create the integer
ctr = 0;
array.
}
void to add integers from the rear
void pushname(String n)
pushvalue (int index if possible else display
A the message ("OVERFLOW").
if (top >= size - 1) int to remove and return elements
System.out.println(“ Overflow ”) ; popvalue () from the front
else if array is empty then return
-9999
top++ ; void disp () display the elements present
st [top] = n ; in the list
I (i) Specify the class Repeat giving details of void disp( )
DATA STRUCTURES 215

the constructor(int), member functions, void


push value(int), int popvalue( ) and void
for (int i = f ; i <= r; i++)
disp( ). The main( ) function need not to be
written.
(ii) What is the common name of the entity System.out.print(st [i] + “ ”) ;
described above?
(iii) On what principle does this entity work? }
Ans. (i) class Repeat }
(ii) The common name of the entity described
int st[ ] ; above is queue.
int cap; (iii) The entity work on FIFO (First In First Out)
int f , r; Principal.
Repeat (int m) Q. 7. Give the output of the following program
segment. [ISC 2006]
cap = m ; class Stack
f = 0;
r = 0; int Stack [ ] = new int [50] ;
st = new int [100] ; int top;
Stack ( )
void pushvalue(int v)
{ top = 0;
if (r == cap - 1) }
void Push (int x)
System.out.Println (“ OVERFLOW”)
Stack [++top] = x;
else if (r ==0)
int pop ( )
f = r = 1;
st [r] = v; return Stack [top - -] ;
}
else st[++ r] = v; public static void main (String args [ ])

int popvalue 0 Stack si = new Stack ( ) ;


{ si.push (51) ;
if (f == 0) si.push (27) ;
si.push (5) ;
System.out.println(“ EMPTY”) ; Sytem.out.println(sl.pop( )) ;
return -9999; System.out.println(sl.popO) ;
} sl.push(18) ;
else if (f = = r) sl.push(72) ;
sl.push(517) ;
int k = st[f ] ; System.out.println(s).pop ( )) ;
f = r = 0; }
return k ; }
} Ans. 5
else 27
return (st [f++]) ; 517
216 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
Im TopiC- 2

Revision Notes
Trees and Link list
Concepts covered: Trees; Terminology related to a tree; Binary tree;
Linked list and implementing various data structures using linked list.

> A binary tree is made of nodes, where each node contains a "left" pointer, a "right" pointer, and a data element.
> The "root" pointer points to the topmost node in the tree.
> The left and right pointers recursively point to smaller "subtrees" on either side.
> A null pointer represents a binary tree with no elements -- the empty tree.
> A Binary tree is either empty or it consists of a node called the root, pointing to two nodes, left and right, each
being a binary tree in itself.
> A "binary search tree" (BST) or "ordered binary tree" is a type of binary tree where the nodes are arranged in
order: for each node, all elements in its left subtree are less-or-equal to the node ( < = ), and all the elements in its
right subtree are greater than the node ( > ).
> A linked-list is a linear collection of data elements called nodes, pointing to the next following nodes by means of
pointers.
> In linked lists number of elements need not be predetermined.
> Linked lists are of two types:
Single linked list.
doubly linked list.
> Single linked list contain nodes with single pointer pointing to the next node.
> START if a single linked list is a special reference which stores the address of the first mode.
> Next or link reference of the last node of the list is always NULL.

|Key Terms
> Parent and Child: Every node (except the root) has a unique predecessor called its parent successor of a node is
known as its child.
> Siblings: Two nodes of some parent.
> The line drawn from a node to its successor is called an edge.
> Path: Sequence of consecutive edges is called a path.
> leaf: Terminal node
> branch: A path ending in a leaf.
> level number: Root has level number 0 and each child has level number one more than us parent.
> Weight/depth: It is the largest level number of a tree.

OBJECTIVE TYPE QUESTIONS (1 mark each)


..
Q 1 Node of a tree which has no parent is: The sequence ACEGIFNKM shows which order
(A) leaf (B) root of traversal:
(C) terminal (D) internal (A) Preorder (B) Inorder
.
Ans Option (B) is correct . (C) Postorder (D) None of these
Explanation: The root node is the very first or .
Ans Option (A) is correct,
parent node. Explanation: . Preorder traversal is used to create a
..
Q 2 Consider the following binary tree structure: copy of the tree. Preorder traversal is also used to
get prefix expression on an expression tree.
..
Q 3 Total number of nodes in a complete binary tree
of depth 3 will be:
(A) 7 ( B) 3
(C) 15 (D) 8
.
Ans Option (C) is correct .
I
Q. 4. Number of leaf nodes in a complete binary tree of
DATA STRUCTURES 217
Q. 8. An attempt to delete a node from an empty list is
depth d' is: called:
(A) 2d ~ 1 - 1 (B ) 2d +1- 1 (A) overflow (B ) underflow
d
(C) 2 - 1 (D) 2d (C) runtime error (D) none of these
Ans. Option (D) is correct. Ans. Option (B) is correct.
Q. 5. Order of a binary tree can be: Explanation: . When a list is empty (i.e. TOP = -1)
(A) 0 (B ) 1 and we try to delete more element from it, then
(C) 2 (D) All of these. this condition is called underflow condition.
Ans. Option (D) is correct. Q. 9. An attempt to insert a node in a linked list, when
Q. 6. Last node in a single linked list contains there is no memory available, is called
(A) null link (B ) no data (A) overflow (B ) underflow
(C) reference to start (D) none of these (C) stack full (D) none of these
Ans. Option (A ) is correct. Ans. Option (A ) is correct.
Q. 7. The predecessor of first node of a single linked Explanation: . When list is completely full (i.e. TOP
list is: = MaxSize -1 ) and we try to insert more element
(A) START pointer (B ) none onto list then this condition is called overflow
(C) null (D) next node condition and no further element could be inserted
Ans. Option (B) is correct. now until any element is deleted.

yf SUBJECTIVE TYPE QUESTIONS


Q. 3. State the difference between a Binary Tree
Answer Type
<& Short \
Questions I -
Q. 1. Answer the following questions on the diagram
(2 marks)
structure and a single Linked List.
^
[ISC 2020]
Q. 4. State any two characteristics of Binary tree.
[ISC 2015]
of a Binary Tree given below: Ans. (i) It is acyclic.
(ii) No two node can be similar or identical
(iii) It is recursive
(iv) There is only one unique path between two
nodes.
(v) Rooted data structure OR Linear data
structure OR Dynamic data structure
(vi) Every node has a maximum of two sub
State the degree of the nodes C and G. Also, state nodes (or maximum degree 2)
the level of these nodes when the root is at level 0. [ISC Marking Scheme 2015]
[ISC Sem-2 Paper 2021-22]
Ans. Degree of C is 2 and degree of G is 0. Level of node
C is 1 and level of node G is 3. Examiner's Comment
Q. 2. Answer the following questions on the diagram
of a Binary Tree given below:
r- Various answers were given by candidates. Some
explained with the help of a diagram.

Answering Tip
w More practice should be done in Binary Tree, its
parts and characteristics.

Write the pre order and post order traversal of the Q. 5. State the sequence of traversing a binary tree in
above tree structure. [ISC Sem-2 Paper 2021-22] [ISC 2014]

Ans. Preorder ABDCEFG (i) Preorder

Postorder DBEGFCA (ii) Postorder
These questions are for practice and their solutions are available at the end of the chapter
218 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class- XII

Ans. (i) root-left-right ( + LR) (i) Preorder Traversing: Preorder traversal prints
I
the contents of a binary in preorder. In other
- -
(ii) Left right root (LR + )
words, the contents of the roots node are
[ISC Marking Scheme 2014]
printed first, followed by left subtree and
finally the right subtree, as shown
Examiner's Comment Root -» Left subtree Right subtree
(ii) Inorder Traversing: Inorder traversal prints
w In parts (i) and (ii), some candidates explained
with the help of a diagram. A few used the term the contents of a sorted tree are in inorder. In
vertex or an operator to represent root. other words, the contents of the left subtree
are printed first, followed by root and finally
the right subtree, as shown
Answering Tip — —
Left subtree > Root > Right subtree

Students should do practice in binary trees and Short Answer Type


w
various terms used. Questions II - (3 marks)

Q. 1. Answer the following questions from the diagram


Detailed Answer: of a Binary Tree given below: [ISC 2017]
(i) Preorder: To traverse a binary tree in preorder,
following operation are carried out
Root -» Left subtree Right subtree
(ii) Postorder: To traverse a binary tree in
postorder, following operations are carried out
Left subtree Right subtree Root
Q. 6. State how a binary tree is a recursive data (i) Write the postorder traversal of the above tree
structure. [ISC 2012] structure.
Ans. A binary tree can be viewed as a recursive data (ii) State the level numbers of the nodes N and R
structure. This means that trees are made up of
if the root is at 0 (zero) level.
subtrees as its children, as shown
Left tree Right tree (iii) List the internal nodes of the right sub-tree.
'
4
A 5 6
X „ 7 4
2
5
A7
6
Ans. (i) Postorder traversal: W- > F- > Y- > N- > R- > Z-
> D- > G- > M
Here, 2 and 3 are children of 1 and 4, 5 are children (ii) N is at level 1 and R is at level 3
of 2. So, it is concluded that a binary tree is a (iii) Internal nodes in right sub-tree = G,Z.
recursive tree.
Q. 2. Answer the following questions from the diagram
Q. 7. List the nodes in the trees given below:[ISC 2008]
of a Binary Tree given. [ICSE Specimen Question
(i) Preorder (ii) Postorder Paper 2016]
60
40 70
/ \ \
20 45 80

10 25 41 50 75 85
Ans. (i) Preoder: (i) Name the Root and the leaves of the tree.
= 60, 40, 70 (ii) Write the post order traversal of the tree.
= 60, 40, 20, 45, 70, 80
(iii) Separate the Internal nodes and the External
= 60, 40, 20, 10, 25, 45, 41, 50, 70, 80, 75, 85 nodes of the tree.
(ii) Postorder:
Ans. (i) Root of the tree = A
= 40, 70, 60
Leaves of the tree = D, E, G
= 20, 45, 40, 80, 70, 60
= 10, 25, 20, 41, 50, 45, 40, 75, 85, 80, 70, 60 (ii) Post order traversal
Q. 8. Explain any two standard ways of traversing a DBEGFCA
binary tree. [ISC 2007] (iii) Internal nodes of the tree = B, A, C, F
Ans. IWo standard ways of traversing a binary tree are: External nodes of the tree = D, E, G
I DATA STRUCTURES 219

Long Answer Type (b) (i) FDJBAEHGCI


<&\ Questions-II (5 marks) (ii) Parent of B = A and Parent of G = E
(iii) Hand I
Q. 1. (a) A linked list is formed from the objects of the [ISC Marking Scheme 2016]
class Node. The class structure of the Node is
given below: [ISC 2016]
class Node Examiner's Comment
{
w Most candidates answered this part correctly and
String name; scored full credit. Some candidates had problems
Node next; in moving the pointer to the next node and
checking for null. Some wrote the algorithm in
simple English covering all the main steps.
Write an Algorithm or a Method to search
for a given name in the linked list. The w (i) This part was answered correctly by most of
declaration of method is given below: the candidates but some wrote the post order
and the pre order of the tree.
Boolean search Name (Node start, String v)
(ii) Almost all candidates answered this part
(b) Answer the following questions from the diagram correctly.
of a Binary Tree given below:
(iii) Most of the candidates answered this part
correctly. A few candidates mentioned the
leaves of the tree instead of the right sub tree.

Answering Tip
w Students should have knowledge to explain
binary tree with the various parts as root, nodes,
height, depth, level, size, tree traversal ( preorder,
(i) Write the inorder traversal of the above tree inorder and postorder), etc.
structure. w Students should do regular practice on algorithms
(ii) Name the parent of the nodes B and G. or programs of link list and binary tree data
structure with the help of appropriate illustrations
(iii) Name the leaves of the right sub-tree. and diagrams.
Ans. (a ) Algorithm
Step 1. Start Q. 2. Answer the following questions from the diagram
Step 2. Set temporary pointer to the first node of a Binary Tree given below: [ISC 2015]
Step 3. Repeat steps 4 and 5 until the pointer
reaches null
Step 4. Search for the node. If found display
details, exit
Step 5. Move pointer to the next node
Step 6. End
Method:
Boolean searchName (Node start, String v)
(i) -
Name the leaf nodes of the right sub tree.

{ Node temp = new Node (start) ; -


(ii) Write post order traversal of the left sub tree
of node B including itself.
while (temp.name.equalsfv)
(iii) State the level number of nodes R and M
== false && temp.next! = null) when the root is at level 0.
temp = temp.next;
(iv) Name the internal nodes of the tree.
if(temp.name.equals(v) = = true)
return true; Ans. (i) RE
else (ii) R, N, M, C, B
return false; (iii) 2 and 2
(iv) C, M, F, H, B [ISC Marking Scheme 2015]
220 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
I
n
w
Examiner's Comment
Several candidates mentioned the leaf nodes of
the entire tree instead of right sub tree.
Ans. (i) Preorder traversal of tree
= AIB
=AIBCD
=AIBCDEF
=AIBCDEGHF
w While most candidates answered this part correctly (ii) Children of node E = (G, H)
some wrote the post order of the entire tree.
(iii) Left subtree of D =
w This part was well answered by most candidates.
w Some candidates included root 'B' also in the
Level 0
answer for internal nodes. However, most of the
candidates answered this part well. Level 1

Level 2
Answering Tip
Level 3
w Understand binary tree with different parts like
root, nodes (internal and external), height, depth, Level 4
level, size tree traversal (preorder, inorder and The height of tree = 4
postorder), etc. Q.5. Answer the following questions from the diagram
of a binary tree given below: [ISC 2012]
Q. 3. Answer the following questions from the diagram
of a binary tree given below:

(i) External nodes of the tree


(ii) Parent of node D
(iii) Inorder traversal of the tree
(iv) Right subtree of node B
(i) Root of the tree Ans. (i) Nodes that do not contain any child node are
(ii) Left subtree known as external nodes.
So, external node = D, E, G
(iii) Inorder traversal of the tree
(ii) Parent Node of D = C
(iv) Size of the tree
(iii) Inorder traversal of tree is as follows
Q. 4. Answer the following questions from the diagram
of a binary tree given below [ISC 2013] = B AF
= BCAFG
= BDCEAFG
(iv) Right subtree of B is

Q. 6. Answer the following questions from the diagram


of a binary tree given below [ISC 2011]

(i) Preorder traversal of tree.


(ii) Children of node E.
(iii) Left subtree of node D
(iv) Height of the tree when the root of the tree is
at level 0.

These questions are for practice and their solutions are available at the end of the chapter
I (i ) Write the Postorder tree traversal (i )
DATA STRUCTURES

Name the parents of node E.


221

(ii) Name the leaves of tree. (ii) Write the Postorder tree traversal.
(iii) Height of the tree (iii) Write the internal node of the tree.
(iv) Root of the tree (iv) State the level of the root of the tree.
Ans. (i ) Postorder traversal of tree is Ans. (i ) Parent node of E = C
= BCA (ii) Postorder tree traversal is as
= B DE CA = BCA
= BDFECA = DBECA
= BDGHFECA = FGDBHECA
(ii) Leaves of the tree are those nodes that do not (iii) Internal nodes of the tree are as
have any child and also known as external = A, B, C, D, E
nodes. iv
( ) The level of the root of the tree is 0.
Hence, leaves of tree = B, D, G, H
Q. 8. Answer the following diagram of a binary tree
(iii) Height of tree = 4
A Level 0
given below t
< |[ISC 2009]

Bj [C Level 1

EH \E Level 2

F Level 3

G2 El - - Level 4 (i) Root of the tree.


(iv) Root of the tree = A (ii) External nodes of the tree.
Q. 7. Answer the following from the diagram of a (iii) List of nodes in the tree using Inorder
binary tree given below [ISC 2010] traversal.
(iv) Left subtree.
( v) Height of the tree.

These questions are for practice and their solutions are available at the end of the chapter
222 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

Solutions for Practice Questions


TOPIC-1 if (front==size) {
2 Marks Questions System.out.
6. Given expression (A*(B/C)/E + F) println("Underflow") ;
return -9999;
Infix Stack Postfix
}
( (
else if (front == rear)
A ( A d = Que [front] ;
C A front = 0;
( (*( A rear = 0;
B ( *( AB return d ;
/ (*(/ AB
C (*(/ ABC else
(* ABC/ return Que[front ++] ;
}
/ (7 ABC/*
}
E (7 ABC/* E
}
+ (+ ABC/* E/
F (+ ABC/* E/F
ABC/* E/F + 10. Marks Questions
13. From above the expression eliminate brackets 4. (i) class Link
as per operator precedence from left to right
associativity, int lnk[ ] , max , begin , end ;
= (AB + )/C * (DE + ) Link (int mm)
= (AB + C/) * (DE + )
= (AB + C/)(DE + )* max = mm ;
The postfix expression is, begin = 0;
= AB + C/DE + * end = 0;
5. Marks Questions Ink = new int[max] ;
2. public class Queue
void addlink (int v)

int Que[] if (end == max - 1)


{ System.out.println (“out of size ”) ;
int Que[] ; else
int size, rear, front; lnk [end ++] = v;
Queue (int mm)
int dellink Q
Que[] = new int [mm ] ;
if (end == begin)
front=0; {
rear=0; System.out.println (“ Empty”) ;
void addele (int v) { return -99;
if (rear == size) { }
System .out. else
printlnfOverflow”) return lnk [begin ++] ;
}
else{ void display ( )
Que[rear++] = v;
for (int i = begin ; i < end ; i++)
{
int delele ( ) {
I Systm.out.println(lnk [i]) ;
DATA STRUCTURES 223

= CDBGFAKLJ
}
= CDEBGHFAKLJ
} (iv) Size of tree = n, where n = number of
} total nodes
(ii) In above algorithm, we used queue as a data = 11
structure . [ISC Marking Scheme, 2020]
TOPIC-2 8. (i) Root of the tree =A
2 Marks Questions (ii) External nodes of the tree are as
3. Binary Tree: A data structure in which each node
has at most two sub nodes/children (left & right)
= D, H, I, F, G
(iii) In order traversal of the tree
Linked list: A linear collection of data elements
whose order is not given by their physical = B AC
placement in memory. Instead, each element = DBEAFACG
points to the next. It is a data structure consisting = DBHEIAFCG
of a collection of nodes which together represent (iv ) Left subtree is
a sequence .
5 Marks Questions
3. ( i ) Root of the tree = A
( ii ) Left subtree is,

Highest
(v ) Height of the tree = Level of the tree = 3
AJ Level 0

H cl Level 1

20 [JL FJ [y Level 2
( iii ) In order traversal of tree is followed as,
Left subtree —> Root —> Right subtree H] [I Level 3
= B AJ
= CBFAKJ
224 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class-XII

SELF ASSESSMENT PAPER - 5


Maximum Marks: 30 Timing: 1 Hour
.
1 What is overflow in data structures? [1]
.
2 How does implementing stacks using arrays differ from implementing them through link list? [2]
.
3 List two implementations each of stacks and queues. [2]
.
4 Convert the following infix notation to their corresponding:
(a) Prefix notation (b) Postfix notation
a + b c - d/e - (a b + c)
* *
show steps also. [2 + 2]
.
5 What is a binary tree? Explain with the help of a diagram. [2]
.
6 Stack is a kind of data structure which can store elements but these can be added or removed from the top end
only.
Class name Words
Data members/instance variables
word [ ] array to hold words
size stores the maximum capacity of the stack,
top points to the topmost index of the stack
Member functions
word (int s) : Constructor to initialize the data member size = s, top = -1 and create
the word array.
void push-word (string w) : to add words to the word array.
String pop-word ( ) : to remove and return words from the top end, if any else returns "! ! !".
void display ( ) : to display elements of the stack.
Specify the class word, giving the details of void push-word (string), string pop-word ( ) and display ( ). [4]
.
7 Observe the following tree and answer the questions that follow. [5]

(a) root of the tree


(b) parent of node G
(c) siblings of B & J
(d) height of the tree
(e) leaf nodes of the tree
(f ) Draw right subtree of node B.
.
8 A data structure allows addition of elements from end and removal from the other. The details of the class Token
is given below:
Class name Token
Data members/instance variables
int num [ ] array to hold the numbers
size stores the size of array.
front points to the end from where elements are added
rear point to the end from where elements are removed.
I Member function / methods:
225

Token (int s) : Constructor to initialize the data members size = s Front = rear = 0 and
create the integer array.
void addele (int n) : to add a token at front, if possible.
int removals (g) : to remove and return token number if possible else return -1.
Specify the class Token giving the details of the functions void addele (int num) and int removable ( ).
Name the data structure mentioned here. [4 + 1]

OSWAAL LEARNING TOOLS


For Solutions of the above Self Assessment Paper, follow the link

Visit: https:// bit.ly/ 3JJIP16 Or Scan the Code


226 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class-XII

PRACTICE PAPER - 1

COMPUTER SCIENCE
PAPER-1 (Theory)
( Maximum Marks: 70 )
( Time allowed : Three hours )
Answer to this Paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes .
This time is to be spent in reading the question paper.
The time given at the head of this Paper is the time allowed for writing the answers .

This Paper is divided into two Parts .


Attempt all questions in Part-I (Compulsory ) and six questions from Part-II , Choosing two questions from
Section-A, two from Section-B and two from Section-C .
The intended marks for questions or parts of questions are given in brackets [ ].

-
PART I (20 Marks)
(Attempt all questions)

Question 1 .
(a) What is MINTERM? [1]
(b) When does a bi-conditional results into false. [1]
(c) Find the dual of :
A + AB = A + B
(d) Name the two forms of a canonical expression. [1]
(e) Draw logic circuit diagrams for the following:
xy + xy + xz [1]
Question 2 .
(a) What is a linked list? What is the role of next reference in a linked list? [2]
(b) A 2-D array defined as B[4...7, -1...3] requires 3 words of storage space for each element. If the array is stored
in column-major form, calculate the address of A[6, 2] given the base address as 100. [2]
(c) What are function signature and function prototype? [2]
(d) Consider the following stack:
STACK:AJNTS<-Top
Describe the stack when the following operations take place. Consider every time the new stack for next
operation.
(i) Push (STACK, K)
(ii) Pop (STACK) [2]
(e) What is a fll through? How can it be avoided? [2]
Question 3 .
Consider the following code in Java and predict the output. Also show the working. What does the method
func() do?
class Hello

static int func (int a [] , int n)


I {
PRACTICE PAPER 227

int x ;
if (n== l)
return a [0] ;
else
x=func(a , n-1) ;
if (x >a [n-l])
return a ;
else
return a [n-1] ;
}
Public static void main (string[] args)

int arr[] ={12, 10, 30 , 50, 100};


system.out. printlnf "+func (arr, 5) + ” '') ;

} [5]

-
PART II (50 Marks)
Answer six questions in this part , choosing two questions from
Section A, two from Section B and two from Section C .
SECTION-A
(Attempt any 2 questions from the given Section)

Question 4 .
(a) Given the boolean function: F(A, B, C) = 1(1, 3, 6, 7).
(i) Reduce the function by using 3 variable Karnaugh map, showing the various groups (i.e., octet, quads
and pairs).
(ii) Draw the logic gate diagram for the above function. Assume that the various variables and their
complements are available as inputs. [4 + 1]
(b) Given the boolean function: F(A, B, C, D) = n( 3, 5, 7, 8, 10, 11, 12, 13)
(i) Reduce the function by using 4-variable Karnaugh map, showing the various groups (i.e., octet, quads
and pairs).
(ii) Draw the logic gate diagram for the above function. Assume that the various variables and their
complements are available as inputs? [4 + 1]
Question 5 .
(a) What do you understand by a multiplexer? State any one application of a multiplexer circuit. Draw the logic
diagram and function table for 4 x1 multiplexer. [5]
(b) Draw the logic gate diagram for the Boolean function
F(A, B, C) = (A' + B) (B' + C)
making use of NOR gates only. [3]
(c) Convert the following expressions to canonical POS form
(A + C) (C + D) [2]
Question 6 .
(a) A combinational circuit has 4-inputs and one output. Output is 1 if :
(i) All the inputs are equal to 1.
(ii) None of the inputs are equal to 1.
(iii) An odd number of inputs are equal to 1.
(I) Obtain the truth table.
(II) Find the simplified output function in SOP form.
(III) Draw the logic diagram. [5]
228 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
(b) What is a decoder? Draw the truth table and a logic circuit diagram for a 2 by 4 decoder.
I[3]
, ,
(c) F(A, B, C, D) = (A' + C)(A' + C')(A + B + C D)
Reduce the above expression using boolean laws. [2]

SECTION-B
(Attempt any 2 questions from the given Section)

Question 7 .
Design a class SumDigits to find the sum and product of digits of a given number. Class specifications are given
below:
Class name : SumDigits
Data members/instance variables:
n : integer to store the number.
sum : integer to store the sum.
product : integer to store the product.
Methods/members functions:
SumDigits : default constructor
void accept() : to accept the number
void sum() : to calculate and display the sum of digits without using( % ) modulus
operator.
void product() : to calculate and display the product of digits without using ( % ) modulus
operator.
Specify the class SumDigits giving details of the constructor, void accept(), void sum (), void product(). Define a
main() function to create an object and call the functions accordingly. [10]
Question 8 .
Given a 2-D array write a program to print it in spiral order. Implement class display with the following
specifications:
Class Name : Display
Data members
Arr 2D : an NxN array
size : integer to hold the value of N.
Member methods:
Display (int) : receives the value of size and creates an array with values 1 to size.
Print() : prints the array elements as a matrix.
PrintSpiral() : prints the array in spiral order
void accept() : to accept the array elements.
Also create main() method that should obtain the value of size and calls the other functions. [10]
Question 9 .
Write the Java program to implement a class swap used to swap adjacent letters of a string. The class contains a

datamember str that holds the string and two functions accept() (to accept string from the user) and swapPairs()
(to swap adjacent letters).
Design the class giving details of the constructor and both the function. Also write main method to create object
of the class and call the functions. [10]

SECTION-C
(Attempt any 2 questions from the given Section)

Question 10 .
A data structure line reads the input from the terminal as a string. Write a code to output the string in the reverse
order, with each character appearing twice, for e.g., input string TISHYA is displayed as AAYYHHSSIITT.
Which type of data structure is line? [4 +1]
I
Question 11 .
PRACTICE PAPER 229

A class one with data members int a and char b inherits from another class. Two with data members float F and
int x. Write definitions for one and two for the following situation:
(i) Objects of both the classes are able to access all the data members of both the classes.
(ii) Only the members of class one can access all the data members of both the classes. [5]

Question 12 .
(a) A linked list is formed from the objects of the class node. The class structure of the node is given below:
Class Node

int num ;
Node next;
}
Write an algorithm or a method to print all the prime numbers from the list. The method of declaration is as
follows:
void primeNum(Node start) [2]
(b) Consider the tree structure given below and answer the questions that follow:

(i) What is the degree of the tree. [1]


(ii) Name the siblings of Node I. [1]
(iii) Draw the left subtree of Node G. [1]

OSWAAL LEARNING TOOLS


For Solutions of the above Practice Paper, follow the link

Visit: https:// bit.ly/ 3JH74 ND Or Scan the Code


230 Oswaal ISC Question Bank Chapterwise & Topicwise, COMPUTER SCIENCE, Class-XII

PRACTICE PAPER 2 -
COMPUTER SCIENCE
PAPER-1 (Theory)
( Maximum Marks: 70 )
( Time allowed : Three hours )
Answer to this Paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes .
This time is to be spent in reading the question paper.
The time given at the head of this Paper is the time allowed for writing the answers .

This Paper is divided into two Parts .


Attempt all questions in Part-I (Compulsory ) and six questions from Part-II , Choosing two questions from
Section-A, two from Section-B and two from Section-C .
The intended marks for questions or parts of questions are given in brackets [ ].

-
PART I (20 Marks)
(Attempt all questions)

Question 1.
(a) What is a truth value? [1]
(b) What is a Binary Decision? [1]
(c) Find minterm is maxterm designation of UVW [1]
(d) Draw Karnaugh map for [1]
F(W, X, Y) = 1(0, 2, 3)
e
( ) Define a logic circuit. [1]
Question 2.
(a) State the purpose of finally block in a try catch statement. What is exception? [2]
(b) What is Autoboxing? Give one reason why primitive types should be preferred over wrappers. [2]
(c) How is a 2D-Array stored in memory? How is this storage achieved ? [2]
(d) List any two applications of queues. [2]
(e) Define the following with respect to a binary tree.
(i) leaf
(ii) degree [2]
Question 3.
Following function is part of some class. Predict the output when x = 57 giving the working. What is the given
function doing, [5]
int funcl (int x)

int d ;
if (x ==0)
return 0 ;
else

d = 2%10;
I return (d*d + funcl (x/10)) ;
PRACTICE PAPER 231

PART-II (50 Marks )


Answer six questions in this part, choosing two questions from
Section A, two from Section B and two from Section C .
SECTION-A
(Attempt any 2 questions from the given Section)

Question 4.
(a) Given the Boolean function:
F(W, X; X Z) = 1(0, 4, 8, 12)
-
(i) Reduce the above expression by using 4 variable Karnaugh map, showing the various groups (i.e.,
octals, quads and pairs). [4]
(ii) Draw the logic gate diagram for the reduced expression. Assume that the variables and their
complements are available as inputs. [1]
(b) Given the Boolean function:
F(A, B, C, D) = n( 0,1, 3, 5, 6, 7, 10, 14, 15)
-
(i) Reduce the above expression by using 4 variable Karnaugh map, showing the various groups. [4]
(ii) Draw the logic gate diagram for the reduced expression. Assume that the variables and their
complements are available as inputs. [1]

Question 5.
(a) Draw the truth table and logic circuit diagram for a Hexadecimal to Binary encoder. [5]
b
( ) What is a Half Adder? Draw the truth table, derive its Boolean expression and draw a logic diagram for Half
Adder. [3]
(c) Convert A B + B C to its canonical SOP for using Boolean Algebra. [2]

Question 6.
(a) A person is allowed to travel in a reserved coach of the train, if he/she satisfies the criteria given below: [5]
The person has a valid reservation ticket and a valid ID proof.
OR
The person does not have a valid reservation ticket, but holds a valid pass issued by the Railway
department with a valid ID proof.
OR
The person is a disabled person and holds a valid pass issued by the Railway department along with a
valid ID proof.
The inputs are:
Inputs
R The person has a valid reservation ticket.
P The person holds a valid pass issued by the railway department.
D The person has a valid ID proof .
H The person is a disabled person.
Output: T-Denotes allowed to travel (1 indicates yes and 0 indicates no in all cases.)
(i) Draw the truth table for the inputs and outputs given above and write the POS expression for T(R, R D, H).
(ii) Reduce T(R, R D, H) using Karnaugh's Map.
-
( ) Implement the following Boolean functions in minimized 2 level NOR NOR form.
b - [3]
F(a, b, c, d) = Im (l, 3, 4, 6, 9, 12)
Assume complements of the input Boolean variables are available.
(c) Reduce the following expression using Boolean laws: [2]
- -
A (A' + B) CC (A + B)
232 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII

SECTION-B
I
(Attempt any 2 questions from the given Section)

Question 7.
A magic number is a number in which the eventual sum of digits of the number is equal to 1.
eg --
'
721 = 7 + 2 + 1 = 10
10 = 1 + 0 = 1
Thus, 721 is a magic number.
Design a Class Magic to check if a given number is a magic number. Some of the members of the class are given
below:
Class name : Magic
Data members/instance variables
n : stores the number
Member functions:
Magic() constructor to assign 0 to n.
void inputnum(int no) to assign the parameter value to the number, n.
int digitsSum returns the sum of the digits of a number.
void is magic)) checks if the given number is a magic number by calling the function
digitsum(int) and display appropriate message.
Specify the class magic giving details of the constructor, void inputnum(int no), int digitsum (int) and void
ismagic(). You do not need to write the main function. [10]
Question 8.
Design a class word which enables a word to be arranged in ascending order according to its letters. The details
of the members of the class are given below.
Class name : Alpha
Data members/instance variables:
str : to store a word
Member functions:
word () default constructor
void readword() : to accept a word
void arrange)) : to arrange the word in alphabetical order using any standard sorting
technique.
void disp() : displays the word.
Specify the class word giving details of the constructor and the member functions void readword(), void arrange)),
void disp() and defining the main)) function to create an object and call the function in order to execute the class
by displaying the original word and the changed word with proper message. [10]
Question 9.
A class shuffle contains a two dimensional integer array of order (m&n) where the maximum value of both m and
n is 6. Design the class shuffle to shuffle the matrix (i.e., the first row becomes the last, the second row becomes
the first and so on). The details of the members of the class are given below:
Class name : Shuffle
Data members:
matrix[] : stores the array element
m : integer to store the member of rows
n : integer to store the numbers of columns
Member functions/methods:
Shuffle (int row, int col) : Parameterized constructor to initialize the data members m = row, n = col
void input() : accepts elements of the array
void shift (shuffle S) : enables the matrix of the object(s) to shift each row upwards m a cyclic
manner and store the resultant matrix in the current object.
void display : display the matrix elements.
Specify the class shuffle giving details of the construct(), void inputs)), void cyclic (shuffle) and void display)).
[10]
I SECTION-C
PRACTICE PAPER 233

(Attempt any 2 questions from the given Section)

Question 10.
Chain is an entity which can hold at the most 50 integers. The chain enables the user to add and remove integers
from hot the ends i.e., front and rear. Define a class chain with the following details:
Class name Chain
ele[] the array to hold the integer elements
cap stores the maximum capacity of the array,
front to point the index of the front
rear to point the index of the rear
Member functions:
chain (int max) : constructor to initialize the data cap = max, front = rear = 0 and to create
the integer array.
void pushfront(int v) : to add integers from the front index if possible else display the message-
"Front is Full".
int popfront : to remove and return elements from front. If array is empty then
return-999.
void pushrear(int v) : to add integers from the front index if possible else display the message
"Rear is full".
int poprearQ : to remove and return elements from rear. If the array is empty then
return-999.
(a) Specify the class chain giving details of the constructor and all the member functions. No need to write the
main function.
(b) Name the data structure implemented above. [4 + 1]
Question 11.
A super class worker has been defined to store the details of a worker. Define a subclass wages to compute the
monthly wages for the worker. Both the classes are defined as follows: [5]
Class name : Worker
Data members/instance variables:
name : to store the name of the worker
basic : to store the basic pay in decimals
Member functions:
Worker (...) Parameterized constructor to assign values to the instance variables.
void display() displays the workers details
class name wages
Data members:
hrs : to store the hours worked
rate : stores rate per hour
wage : stores the overall wage of the worker
Member functions:
wagesQ : parameterized constructor to assign values to the instance variables of
both the classes.
double overtime() : Calculates and return the overtime amount as (hours“ rate)
void display() : Calculates the wage using the formula wage = overtime amount +
Basic pay and displays it along with the other details.

Question 12.
(a) A linked list is formed from the objects of the class node. The class structure of the node is given below:
class node
{
int num ;
234 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Node next;
I
Write an algorithm or a method to delete 'nlh' node from the list. The method of declaration is as follows:
void del (Node start, int n) [2]
(b) Consider the tree structure given below and answer the questions that follow:

(i) Write the preorder transversal of the tree. [1]


(ii) Draw the right subtree of the root. [1]
(iii) Name the leaf nodes of the tree. [1]
n
$£ OSWAAL LEARNING TOOLS
For Solutions of the above Practice Paper, follow the link

Visit: https:// bit.ly/ 3QvjhXR Or Scan the Code


PRACTICE PAPER - 3

COMPUTER SCIENCE
PAPER-1 (Theory)
( Maximum Marks: 70 )
( Time allowed: Three hours )
Answer to this Paper must be written on the paper provided separately.
You will not be allowed to write during the first 15 minutes.
This time is to be spent in reading the question paper.
The time given at the head of this Paper is the time allowed for writing the answers.

This Paper is divided into two Parts.


- -
Attempt all questions in Part I (Compulsory ) and six questions from Part II , Choosing two questions from
- -
Section A, two from Section B and two from Section C. -
The intended marks for questions or parts of questions are given in brackets [ ].

PART-I (20 Marks)


(Attempt all questions)

Question 10.
(a) Draw the equivalent logic circuit for the following Boolean expression:
(AB) + C [1]
(b) Correct the following boolean, statements [1]
(i) X + 1 = X
(ii) (A + B)' = A.B
(c) State DeMorgan's laws of Boolean Algebra. [1]
(d ) Derive a canonical SOP expression for the Boolean function F, represented by the following truth table: [1]
P Q R F(P, Q, R )
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 1
(e ) When does a XNOR gate produce high output? [1]

Question 2.
(a) Convert the following to a postfix expression [2]
(a + b)*(c + d)
(b) State difference in implementing stacks using array and implementing them using linked list. [2]
c
( ) X is a 2- array
D [10 x 5]. Each element of the array is stored in 2 memory locations. If X[l, 1] begins at address
100, find the location of X[3, 4] if the arrangement is row-major wise. [2]
236 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
(d ) (i) What should be the data type of the variable C, for Java to generate no error? Why?
I[2]
C = 5.7F +8.9/2 + 6*3.75;
(ii) What is coercion? Give one example.
(e) What is polymorphism? How is it implemented in Java? [2]
Question 3.
Read the following code carefully and predict the output of the function count A if the value passed to the
function count A is "Mississipi". [5]
What is the function count A() doing. Show the working also,
public int count A (string str)

int count = 0 ;
if (str.length ==0)
return 0
if (str.substring(0, l) .equals("i"))
count = 1;
return count + count A (str.substring(l)) ;
}

-
PART II (50 Marks)
SECTION-A
(Attempt any 2 questions from the given Section)

Question 4.
(a ) Given the Boolean function
F(A, B, C, D) = 1(1, 2, 3, 4, 5, 6, 7, 12, 13)
(i) Reduce the above expression by using 4-variable Karnaugh map, showing the various groups. [4]
(ii) Draw logic gate diagram for the reduced expression. Assume that the variables and their complements
are available as inputs. [1]
(b) Given the Boolean function
F(W, X, Y, Z) = n( 0, 2, 4, 6)
(i) Reduce the above expression by using 4-variable Karnaugh map, showing the various groups. [4]
(ii) Draw logic gate diagram for the reduced expression. Assume that the variables and their complements
are available as inputs. [1]
Question 5.
(a ) What is an encoder? Draw the logic circuit diagram for decimal to binary encoder, and its truth table. [5]
(b) Why is NOR gate regarded as a universal gate? Draw its symbol and truth table for two input NOR gate.
[3]
(c) Express P + Q • R in canonical SOP form. [2]
Question 6.
(a ) A provisional store announces a special discount on all its products as a festival offer only to those who
satisfy any one of the following conditions:
• If he/she is an employee of the store and has a service of more than 10 years.
OR
• If he/she is a senior citizen but not a regular customer of the store.
The inputs are:
E : Employee of the store
R : Regular customer of the store
S : Service of the employee is more than 10 years.
C : Senior citizen of 65 years or above.
I Output:
PRACTICE PAPER 237

X : Denotes eligible for discount [1 indicates YES and 0 indicates NO in all cases]
Draw the truth tables for the inputs and outputs given above and write the SOP expression for X[E, R, S, C],
[5]
(b) Represent F(a, b) = a.b using only NOT and OR gates. [3]
(c) Verify the following using boolean laws [2]
XY + XY = (X + Y) (x + y)
SECTION-B
(Attempt any 2 questions from the given Section)

Question 7.
Write a program to declare a single dimensional arrayX[] and a square matrix Y[][] of size N where 2 < N <10.
Allow the user to input positive integers into single dimensional array. Now
(a) Sort the elements of the single dimensional array in ascending order using and standard sorting technique.
(b) Fill the square matrix in the following format.
If array X[] = {6, 7, 2, 9} then after
sorting X[] = 12, 6, 7, 9}
Now matrix Y[] is filled as follow:
2 6 7 9
2 6 7 2
2 6 2 6
2 2 6 7 [10]

Question 8.
Write a program in Java to enter a number. Check and display whether it is prime perfect or not.
A number is said to be prime perfect, if all the factors are prime including 1 and excluding the number itself and
also the sum of all factors including 1 and excluding the number is equal to the number,
e.g. 6 is a prime perfect because factors of 6 i.e., 3 & 2 are prime and 1 + 2 + 3 = 6. [10]

Question 9.
You can encode or decode a string in many ways. One of them is to replace each vowel by two characters ahead
in ASCII table and each consonant by the next character. The replacement of characters may wrap around (i.e., A
follows Z). Write a program in Java to accept a word and encrypt it as follows: [10]
Word Encrypted form
SIDDHANT TKEEICOU

SECTION-C
(Attempt any 2 questions from the given Section)

Question 10.
Queue is an entity which can hold a maximum of 100 integers. The queue enables the user to add integers from
the rear and remove integers from the front.
Define a class Queue with the following details:
Class Name : Queue
Data members
Que [] array to hold the integer elements,
Size stores the size of the array,
Front to point the index of the front,
rear to point the index of the rear.
238 Oswaal ISC Question Bank Chapterwise & Toplcwlse, COMPUTER SCIENCE, Class-XII
Member functions:
I
Queue (int mm) : constructor to initialize the data size = mm, front = -1, rear = -1.
void addele (int V) : to add integer from the rear if possible else display the message
"overFlow"
it delete() : returns elements from front if present, otherwise displays the message
"Underflow" and return -9999.
void displaysQ : displays the array elements.
(a ) Specify the class Queue giving details of only the function void addele(int) and int delele(). Assume that the
other functions have been defined. The main function and algorithm need not be written. [4]
(b) What is the name of the data structure that allows addition and deletion of data from one end only? On
which principle it is based? [1]

Question 11.
A class personal contains employee details and another class retire calculates the employee's provident fund and
gratuity. [5]
The details of the two classes are given below:
Class Name : Personal
Data Members:
Name : stores the employee name
Pan : stores the employee PAN numbers
basic-pay : stores the employee basic salary
acc-no : stores the employee bank account number.
Member functions:
Personal (...) parameterized constructor to assign value to data members
void display() to display the employee details.
class name Retire
Data members:
Yrs : stores the employee years of service
PF : stores the employee's provident fund amount
Grat : stores the employee's gratuity amount
Member functions:
Retire(...) : parameterized constructor to assign value to data members of both the
classes.
void provident() : calculates the PF as (2% of the basic pay)*years of service.
void gratuity() : calculates the gratuity as 12 months salary, if the years of service is more
than or equal to 10 years else the gratuity amount is nil.
void display1() : Displays the employee details along with the PF and gratuity amount.
Specify the class personal giving details of the constructor and member functions void display(). Using the
concept of inheritance, specify the class retire giving details of constructor and function void provident(), void
gratuity() and void displayl (). The main function need not be written.

Question 12.
(a ) A linked list is formed from the objects of the class Node as given below:
class Node {
string name ;
node next;

Write an algorithm or a method to count and return number of nodes in the list; The method is defined as
int count(Node n); [2]
I (b) Answer the following questions based on the structure of the tree given below:
PRACTICE PAPER 239

(i) Write the post order traversal of the above tree. [1]
(ii) Name the siblings of nodes E&K. [1]
(iii) What is the order and degree of the above tree if root is at level 0. [1]

OSWAAL LEARNING TOOLS


For Solutions of the above Practice Paper, follow the link

Visit: https:// bit.ly/ 3QipYwE Or Scan the Code


WRITING YOUR NOTES

Just in case you have forgotten today, takedown your notes!


But why is it so important?
Tools for the hands are tools for the brain writes Hetty Roessingh.
Handwritten notes are a powerful tool for encrypting embodied cognition and in turn supporting the
.
brain's capacity for recuperation of information If that sounds so scientific then in simple words:
Writing notes by hand help you in:
Increasing your comprehension Strengthening your memory Igniting your creativity
Engaging your mind Increasing your attention span
Are these reasons enough to get you started?

1.
2.

3.

4.

5.

6.

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

18.

19.

20.
Highly recommended titles from
m OSWAAL BOOKS ®

ISC
« OSWAAL
_
BOOKS
tBMstantMB mm etraan
®

<
QUESTION BANK
FOR CLASS XII 0
^P
4
ISC
QUESTION
BANK
Chapterwise & Topicwise
SOLVED
PAPERS
IL t i

BENEFITS
• Latest Board Examination Paper
• Latest Solved Board Specimen Paper
2010- 2021
CLASS 12
BIOLOGY Bfi
k331
.fy 1
.
• Strictly as per the Latest Syllabus
‘On Tips Notes' & Mind Map
x
laid!Board

• Topics Found Difficult & Suggestions for Students


•Examiners’Comments & Answering Tips
j%
Si 1 °'Sr“ !
mm
•Concept Videos for blended Learning k
ALL SUBJECTS ARE AVAILABLE IN THIS SERIES


I ISC
fm « rut
OSWAAL BOOKS
rrmrrt EIMBHU
®
SAMPLE QUESTION PAPER
i: FOR CLASS XII
ISC 1A
m W SAMPLE
' i -


Si
iii
MI \\
?///
QUESTION
PAPERS
CLASS 12
SEMESTER 2
CHEMISTRY
r • Strictly
BENEFITS
• Updated Typologies of Questions as per Latest ISC
Specimen Paper
as per the latest syllabus
• On Tips Notes’ & Mind Map
W :SS 2£ -3B=

• Topics found difficult & suggestions for students
• Answer key with Explanations for every question
M Academically Important Questions (Al)
M
WK«G ALL SUBJECTS ARE AVAILABLE IN THIS SERIES

HftjE
Scan this QR code on your mobile for instant
access to all these books and more.

m
Get future ready
with comprehensive titles from
« OSWAAL BOOKS
LE OTraG mnm SIMPLE
[ &
®

® OSWAAL BOOKS
ns&BiEnaoi ; srTsrrr
TOPPER’S HANDBOOK
BENEFITS
• Definitions and Revision Notes
• Mind Maps
• 500+ Concept Videos
• Hybrid Edition with Print & Online Support,
• Useful for Class 12 Board Examination
and medical and other competitive examinations
SUBJECTS AVAILABLE IN THIS SERIES
• Physics • Chemistry
• Mathematics • Biology

34 YEARS NEET (UG)


SOLVED PAPERS
BENEFITS
• Latest Sample Question Papers
• Previous 34 Years’ Questions of NEET & AIPMT
• Chapterwise and Topicwise Presentation
• Hybrid Edition with Print & Online Support
SUBJECTS AVAILABLE IN THIS SERIES
• Physics • Chemistry • Biology

« OSWAAL BOOKS
JEE (MAIN) MOCK TEST
r Rfvinrrcft CSICJR srrcrrn
- 15 SAMPLE QUESTION PAPERS &
JEE (MAIN) SOLVED PAPERS
• Latest Solved Papers ( all 4
Shifts) of 2021 Exam
• Concept based Revision Notes
• Valuable Exam insights, Tips,
Tricks & Shortcuts
• Two Sample Practice Papers
• ‘Strictly as per the scheme of
examination for JEE (MAIN) 2022
issued by NTA
• Fully solved 15 Mock Papers with
90 Question each
• Get concpet clarity - Mind Maps
NEET (UG) coH&o]

« OSWAAL
16 YEARS’ SOLVED PAPERS BOOKS
(.nfiirtrnre rs/, flR crrcrrr

2006- 2021 • Latest Solved Pa


BENEFITS (all 4 Shifts) of 2021 Exam
• Subjectwise Trend Analysis 2021 - 2009 • Concept based Revision
• Valuable Exam Insights, Tips, Tricks & Shortcuts Notes
• Blended Learning with Print & Online Support • Valuable Exam insights,
• 2 Sample Question Papers for Practice
Tips, Tricks & Shortcuts
• Cognitive Learning Tools, Mind Maps, Mnemonics
& Appendix • Two Sample Practice
Papers

You might also like