Uploaded by Nidhi Agarwal

Comp.Sc.

advertisement
Nirmal Bhartia School
Computer Science(283) Compendium,
2019-20
Class XII
Contents:
1.
2.
3.
4.
5.
CBSE Curriculum Class XII (Old Computer Science – 283).
Computer Science
Sample Paper 2019-20.
Sample Paper 2019-20 Marking Scheme.
Analysis of the Sample Paper.
Topic Wise Notes, Solved Questions, Practice Questions From Previous Year Board Papers
and Sample papers, Tips for solving questions.
1.CLASS XII CBSE CURRICULUM
COMPUTER SCIENCE (OLD)(CODE - 283)
Class XII (Theory) - C++
Session 2019-20)
Duration: 3 hours
Unit
No.
1.
2.
3.
4.
5.
Total Marks: 70
Unit
Name
OBJECT ORIENTED PROGRAMMIMG IN C++
DATA STRUCTURE
DATABASE MANAGEMENT SYSTEM AND SQL
BOOLEAN ALGEBRA
COMMUNICATION TECHNOLOGIES
Total
Unit 1: Object Oriented Programming in C++
Mar
ks
30
14
8
8
10
70
(50 Theory + 40 Practical) Periods
Review: C++ covered in class XI,
Object Oriented Programming: Concept of Object Oriented Programming – Data hiding, Data
encapsulation, Class and Object, Abstract class and Concrete class, Polymorphism (Implementation of
polymorphism using Function overloading as an example in C++); Inheritance, Advantages of Object
Oriented Programming over earlier programming methodologies,
Implementation of Object Oriented Programming concepts in C++: Definition of a class, Member of
a class – Data Members and Member Functions (methods), Using Private and Public visibility modes,
default visibility mode (private); Member function definition: inside class definition and outside class
definition using scope resolution operator (::); accessing members from object (s), Objects as function
arguments–pass by value and pass by reference;
Constructor and Destructor: Constructor: special
1 characteristics, declaration and definition of a
constructor, default constructor, overloaded constructors, copy constructor, constructor with default
arguments;
Destructor: Special Characteristics, declaration and definition of destructor;
Inheritance (Extending Classes): Concept of Inheritances, Base Class, Derived classes, protected
visibility mode; Single level inheritance, Multilevel inheritance and Multiple inheritance, Privately
derived, publicly derived and Protectedly derived class, accessibility of members from objects and within
derived class (es);
Data File Handling: Need for a data file, Types of data files – Text file and Binary file;
Text File: Basic file operations on text file: Creating/Writing text into file, Reading and Manipulation of
text from an already existing text File (accessing sequentially).
Binary File: Creation of file, Writing data into file, Searching for required data from file, Appending
data to a file, Insertion of data in sorted file, Deletion of data from file, Modification of data in a file;
Implementation of above mentioned data file handling in C++;
Components of C++ to be used with file handling:
Header file: fstream.h; ifstream, ofstream, classes;
Opening a text file in—in, out, and app modes;
Using cascading operators (>>,<<) for writing text to the file and reading text from the file; open (), get
(), read (), put (), write(), getline() and close() functions; Detecting end-of-file (with or without using
eof() function), tellg(), tellp(), seekg(), seekp();
Pointers:
Introduction to Pointer, Declaration and Initialization of Pointer; Dynamic memory allocation/deallocation operators: new, delete; Pointers and Arrays: Array of Pointers, Pointer to an array (1
dimensional array), Function returning a pointer, Reference variables and use of alias; Function call by
reference. Pointer to structure: De-reference/Deference operator: *, ->; self referential structure;
Unit 2:
Data Structures
(42 Theory + 36 Practical) Periods
Introduction to data structure- array, stack queues primitive and non-primitive data structure, linear and
non-linear structure, static and dynamic data structure.
Arrays:
One and two Dimensional arrays: Sequential allocation and address calculation;
One dimensional array: Traversal, Searching (Linear, Binary Search), Insertion of an element in an array,
deletion of an element from an array, Sorting (Insertion, Selection, Bubble)
Two-dimensional arrays: Traversal Finding sum/difference of two NxM arrays containing numeric values,
Interchanging Row and Column elements in a two dimensional array;
Stack (Array and Linked implementation of Stack):
2
Introduction to stack (LIFO: Last in First out Operations)
Operations on stack (PUSH and POP) and its Implementation in C++, Converting expressions from
INFIX to POSTFIX notation and evaluation of Postfix expression;
Queue: (Array and Linked Implementation)
Introduction to Queue (FIFO: First in First out operations)
Operations on Queue (Insert and Delete and its Implementation in C++, circular queue using array.
Unit 3:Database Management System and SQL
(20Theory + 20Practical) Periods
Data base Concepts: Introduction to data base concepts and its need.
Relational data model: Concept of domain, tuple, relation, key, primary key, alternate key, candidate key;
Relational algebra: Selection, Projection, Union and Cartesian product;
Structured Query Language:
General Concepts: Advantages of using SQL, Data Definition Language and Data Manipulation Language;
Data Types: NUMBER/DECIMAL, CHARACTER/VARCHAR/VARCHAR2, DATE;
SQL COMMANDS: CREATE TABLE, DROP TABLE, ALTER TABLE, UPDATE ….SET…., INSERT,
DELETE; SELECT, DISTINCT, FROM, WHERE, IN, BETWEEN, GROUP BY, HAVING, ORDER BY;
SQL functions: SUM ( ), AVG ( ), COUNT ( ), MAX ( ) AND MIN ( ); Obtaining results (SELECT
query) from 2 tables using equi-join, Cartesian product and Union
Note: Implementation of the above mentioned commands could be done on any SQL supported software on
one or two tables.
Unit 4: Boolean Algebra
(16 Theory + 0 Practical) Periods
Role of Logical Operations in Computing.
Binary-valued Quantities, Boolean Variable, Boolean Constant and Boolean Operators: AND, OR, NOT;
Truth Tables; Closure Property, Commutative Law, Associative Law, Identity law, Inverse Law,
Principle of Duality, Idempotent Law, Distributive Law, Absorption Law, Involution Law, DeMorgan’s
Law and their applications;
Obtaining Sum of Product (SOP) and Product of Sum (POS) form the Truth Table, Reducing Boolean
Expression (SOP and POS) to its minimal form, Use of Karnaugh Map for minimization of Boolean
expressions (up to 4 variables);
Application of Boolean Logic: Digital electronic circuit design using basic Logic Gates (NOT, AND,
OR, NAND, NOR)
Use of Boolean operators (NOT, AND, OR) in SQL SELECT statements Use of
Boolean operators (AND, OR) in search engine queries.
Unit 5:
Communication Technologies
(16 Theory + 3 Practical) Periods
3
Evolution of Networking: ARPANET, Internet, Interspace Different ways of sending data across the
network with reference to switching techniques (Circuit and Packet switching).
Data Communication terminologies: Concept of Channel, Bandwidth (Hz, KHz, MHz) and Data
transfer rate (bps, Kbps, Mbps, Gbps, Tbps).
Transmission media: Twisted pair cable, coaxial cable, optical fiber, infrared, radio link, microwave
link and satellite link.
Network devices: Modem, RJ45 connector, Ethernet Card, Router, Switch, Gateway, wifi card.
Network Topologies and types: Bus, Star, Tree, PAN, LAN, WAN, MAN.
Network Protocol: TCP/IP, File Transfer Protocol (FTP), PPP, SMTP, POP3 Remote Login (Talent),
and Internet Wireless/Mobile Communication protocol such as GSM, CDMA, GPRS, and WLL.
Mobile Telecommunication Technologies: 1G, 2G, 3G and 4G; Mobile processors; Electronic
mail protocols such as SMTP, POP3
Protocols for Chat and Video Conferencing VOIP Wireless technologies such as Wi-Fi and WiMax
Network Security Concepts:
Threats and prevention from Viruses, Worms, Trojan horse, Spams Use of
Cookies, Protection using Firewall, https;
India IT Act, Cyber Law, Cyber Crimes, IPR issues, hacking.
Introduction To Web services: WWW, Hyper Text Markup Language (HTML), Extensible Markup
Language (XML); Hyper Text Transfer Protocol (HTTP); Domain Names; URL; Website, Web browser,
Web Servers; Web Hosting, Web Scripting – Client side (VB Script, Java Script, PHP) and Server side
(ASP, JSP, PHP), Web 2.0 (for social networking)
E-commerce payment transactions using online banking, mobile banking and payment apps and services.
Class XII (Practical) –C++
Duration: 3 Hours
Total Marks: 30
1. Programming in C++
10
One programming problem in C++ to be developed and tested in Computer during the
examination. Marks are allotted on the basis of following:
Logic
Documentation/Indentation
Output presentation
: 6 Marks
: 2 Marks
: 2 Marks
4
Notes: The types of problem to be given will be of application type from the following topics
 Arrays (One dimensional and two dimensional)
 Class(es) and objects
 Stack using arrays and or linked implementation
 Queue using arrays (circular) and or linked implementation
 Binary File operations (Creation, Displaying, Searching and modification)

Text File operations (Creation, Displaying and modification)
2. SQL Commands
05
Five Query questions based on a particular Table / Relation to be tested practically on Computer
during the examination. The command along with the result must be written in the answer sheet.
3. Project Work
05
The project has to be developed in C++ language with Object Oriented Technology and also
should have use of Data files. (The project is required to be developed in a group of 2-4 students)
 Presentation on the computer
 Project report (Listing, Sample Outputs, Documentations)
 Viva
* 1 mark is for innovation while writing programme.
4. Practical File
06
Must have minimum 20 programs from the following topics
 Arrays (One dimensional and two dimensional, sorting, searching, merging, deletion &
insertion of elements)
 Class(es) and objects
 Stacks using arrays and linked implementation
 Queue using arrays & linked implementation (circular also).
 File (Binary and Text) operations (Creation,
Updation, Query)


Any computational Based problems
15 SQL commands along with the output based on any table/relation:
5. Viva Voce
04
Viva will be asked from syllabus covered in class XII and the project developed by student.
1.
Preamble
The academic course in Computer Science includes one Project in each year. The Purpose
behind this is to consolidate the concepts and practices imparted during the course and to serve
as a record of competence.
A group of 2-3 students as team may be allowed to work on one project.
2.
Project content
Project for class XI can be selected from the topics mentioned in the syllabus or domains on the
similar lines
Project for class XII should ensure the coverage of following areas of curriculum:
 Flow of control
 Data Structure
5


Object Oriented Programming C++
Data File Handling
Theme of the project can be
Any subsystem of a System Software or Tool
Any Scientific or a fairly complex algorithmic situation
School Management, Banking, Library Information System, Hotel or Hospital
Management System,
Transport query system
Quizzes / Games;
Tutor, Computer Aided Learning Systems
It is suggested to prepare a bilingual (English and other Indian language) user manual part of
project file.
The aim of the project is to highlight the abilities of algorithmic formulation, modular
programming, optimized code preparation, systematic documentation and other associated
aspects of Software Development.






2. SAMPLE PAPER 2019-20
Class XII
Computer Science - OLD (283)
Sample Question Paper 2019-20
Time allowed: 3 Hours
Max. Marks: 70
General Instructions:
(a) All questions are compulsory.
(b)
Programming Language with C++
(c)
In Question 2(b, d) ,3 and 4 has internal choices.
Q. No.
Part
Question Description
1
(a)
Write the type of C++ Operators (Arithmetic, Logical, and Relational
Operators) from thefollowing:
(i)
Marks
!(ii) !=(iii) &&(iv) %
6
(2)
(b)
Observe the following program very carefully and write the name of those
header file(s), which are essentially needed to compile and execute
thefollowing program successfully:
void main()
{
char text[20], newText[20];
gets(text);
strcpy(newText,text);
for(int i=0;i<strlen(text);i++)
if(text[i] = =’A’)
text[i] = text[i]+2;
puts(text);
}
(1)
(c)
Rewrite the following C++ code after removing any/all Syntactical Error(s)
with each correction underlined.
(2)
Note: Assume all required header files are already being included in the
program.
#define float PI 3.14
void main( )
{
float R=4.5,H=1.5;
A=2*PI*R*H + 2*PIpow(R,2);
cout<<‘Area=’<<A<<endl;
}
7
(d)
Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in
the program.
void main( )
{
int Ar[ ] = { 6 , 3 , 8 , 10 , 4 , 6 , 7} ;
int *Ptr = Ar , I ;
cout<<++*Ptr++ << '@' ;
I = Ar[3] - Ar[2] ;
cout<<++*(Ptr+I)<<'@'<<"\n" ;
cout<<++I + *Ptr++ << '@' ;
cout<<*Ptr++ <<'@'<< '\n' ;
for( ; I >=0 ; I -=2)
cout<<Ar[I] << '@' ;
}
(3)
(e)
Find and write the output of the following C++ program code:
typedef char STRING[80];
void MIXNOW(STRING S)
{
int Size=strlen(S);
for(int I=0;I<Size;I+=2)
{
char WS=S[I];
S[I]=S[I+1];
S[I+1]=WS;
}
for (I=1;I<Size;I+=2)
if (S[I]>=’M’ && S[I]<=’U’)
S[I]=’@’;
}
void main()
{
STRING Word=”CBSEEXAM2019”;
MIXNOW(Word);
cout<<Word<<endl;
}
(2)
(f)
Observe the following program and find out, which output(s) out of (i) to
(iv) willbe expected from the program? What will be the minimum and the
maximum value assigned to the variable Alter?
(2)
Note: Assume all required header files are already being included in the
program.
void main( )
{
randomize();
int Ar[]={10,7}, N;
8
int Alter=random(2) + 10 ;
for (int C=0;C<2;C++)
{
N=random(2) ;
cout<<Ar[N] +Alter<<”#”;
}
}
(i) 21#20#
(iii) 20#17#
2
(ii) 20#18#
(iv) 21#17#
(a)
What is a copy constructor? Illustrate with a suitable C++ example.
(2)
(b)
Write the output of the following C++ code. Also, write the name of feature
of Object Oriented Programming used in the following program jointly
illustrated by the Function 1 to Function 4.
void My_fun ( )
// Function 1
{
for (int I=1 ; I<=50 ; I++) cout<< "-" ;
cout<<end1 ;
}
void My_fun (int N)
// Function 2
{
for (int I=1 ; I<=N ; I++) cout<<"*" ;
cout<<end1 ;
}
void My_fun (int A, int B)
// Function 3
{
for (int I=1. ;I<=B ;I++) cout <<A*I ;
cout<<end1 ;
}
void My_fun (char T, int N)
// Function 4
{
for (int I=1 ; I<=N ; I++) cout<<T ;
cout<<end1;
}
void main ( )
{
int X=7, Y=4, Z=3;
char C='#' ;
My_fun (C,Y) ;
My_fun (X,Z) ;
}
(2)
OR
(b) Write any four differences between Constructor and Destructor function
with respect to object oriented programming.
9
(c)
Define a class Ele_Bill in C++ with the following descriptions:
Private members:
Cname
of type character array
Pnumber
of type long
No_of_units
of type integer
Amount
of type float.
Calc_Amount( )
This member function should calculate the
amount as No_of_units*Cost .
Amount can be calculated according to the following conditions:
No_of_units Cost
First 50 units
Free
Next 100 units
0.80 @ unit
Next 200 units
1.00 @ unit
Remaining units
1.20 @ unit
Public members:
* A function Accept( ) which allows user to enter Cname,
Pnumber, No_of_units and invoke function Calc_Amount().
* A function Display( ) to display the values of all the data members
on the screen.
(d)
Answer the questions (i) to (iv) based on the following:
class Faculty
{
int FCode;
protected:
char FName[20];
public:
Faculty();
void Enter();
void Show();
};
class Programme
{
int PID;
protected:
char Title[30];
public:
Programme();
void Commence();
void View();
};
class Schedule: public Programme, Faculty
{
int DD,MM,YYYY;
public:
10
(4)
(4)
Schedule();
void Start();
void View();
};
void main()
{
Schedule S;
//Statement 1
//Statement 2
}
(i)
Write the names of all the member functions, which are directly accessible
by the object S of class Schedule as declared in main() function.
(ii)
Write the names of all the members, which are directly accessible by the
memberfunction Start( ) of class Schedule.
(iii)
Write Statement 2 to call function View( ) of class Programme from the
object S of class Schedule.
(iv)
What will be the order of execution of the constructors, when the object S
of class Schedule is declared inside main()?
OR
(d)
Consider the following class State :
class State
{
protected :
int tp;
public :
State( ) { tp=0;}
void inctp( ) { tp++;};
int gettp(); { return tp; }
};
Write a code in C++ to publically derive another class ‘District’
with the following additional members derived in the public
visibility mode.
Data Members :
Dname
string
Distance
float
Population
long int
Member functions :
DINPUT( ) : To enter Dname, Distance and population
DOUTPUT( ) : To display the data members on the screen.
11
3
(a)
(2)
Write a user-defined function AddEnd4(int A[][4],int R,int C) in C++ to
find and display the sum of all the values, which are ending with 4 (i.e., unit
place is 4).
For example if the content of array is:
24 16 14
19 5 4
The output should be
42
OR
(a)
Write a user defined function in C++ to find the sum of both left and right
diagonal elements from a two dimensional array.
(b)
Write a user-defined function EXTRA_ELE(int A[ ], int B[ ], int N) in C++
to find and display the extra element in Array A. Array A contains all the
elements of array B but one more element extra. (Restriction: array
elements are not in order)
Example
(3)
If the elements of Array A is 14, 21, 5, 19, 8, 4, 23, 11
and the elements of Array B is 23, 8, 19, 4, 14, 11, 5
Then output will be 21
OR
(b)
Write a user defined function Reverse(int A[],int n) which accepts an
integer array and its size as arguments(parameters) and reverse the array.
Example : if the array is 10,20,30,40,50 then reversed array is
50,40,30,20,10
(c)
An array S[10] [30] is stored in the memory along the column with each of
its element occupying 2 bytes. Find out the memory location of S[5][10], if
element S[2][15] is stored at the location 8200.
(3)
OR
(c)
(d)
An array A[30][10] is stored in the memory with each element requiring 4
bytes of storage ,if the base address of A is 4500 ,Find out memory
locations of A[12][8], if the content is stored along the row.
Write the definition of a member function Ins_Player() for a class
CQUEUE in C++, to add a Player in a statically allocated circular queue of
PLAYERs considering the following code
is already written as a part of the program:
struct Player
{
long Pid;
char Pname[20];
12
(4)
};
const int size=10;
class CQUEUE
{
Player Ar[size];
int Front, Rear;
public:
CQUEUE( )
{
Front = -1;
Rear = -1;
}
void Ins_Player(); // To add player in a static circular queue
void Del_Player(); // To remove player from a static circular queue
void Show_Player(); // To display static circular queue
};
OR
(d)
Write a function in C++ to delete a node containing Books information
,from a dynamically allocated stack of Books implemented with the help of
the following structure:
struct Book
{
int BNo;
char BName[20];
Book *Next;
};
(e)
Convert the following Infix expression to its equivalent Postfix expression,
showing the stack contents for each step of conversion.
A/B+C*(D-E)
(2)
OR
Evaluate the following Postfix expression :
4,10,5,+,*,15,3,/,4
(a)
Write a function RevText() to read a text file “ Input.txt “ and Print only
word starting with ‘I’ in reverse order .
Example: If value in text file is: INDIA IS MY COUNTRY
Output will be: AIDNI SI MY COUNTRY
OR
(a)
Write a function in C++ to count the number of lowercase alphabets present
in a text file “BOOK..txt".
13
(2)
(b)
Write a function in C++ to search and display details, whose destination is
“Cochin” from binary file “Bus.Dat”. Assuming the binary file is
containing the objects of the following class:
class BUS
{
int Bno;
// Bus Number
char From[20];
// Bus Starting Point
char To[20];
// Bus Destination
public:
char * StartFrom ( ); { return From; }
char * EndTo( ); { return To; }
void input() { cin>>Bno>>; gets(From); get(To); }
void show( ) { cout<<Bno<< “:”<<From << “:” <<To<<endl; }
};
(3)
OR
(b)
Write a function in C++ to add more new objects at the bottom of a binary
file "STUDENT.dat", assuming the binary file is containing the objects of
the following class :
class STU
{
int Rno;
char Sname[20];
public: void Enter()
{
cin>>Rno;gets(Sname);
}
void show()
{
count << Rno<<sname<<endl;
}
};
(c)
Find the output of the following C++ code considering that the binary file
PRODUCT.DAT exists on the hard disk with a list of data of 500 products.
class PRODUCT
{
int PCode;char PName[20];
public:
void Entry();void Disp();
};
void main()
{
fstream In;
In.open("PRODUCT.DAT",ios::binary|ios::in);
PRODUCT P;
In.seekg(0,ios::end);
cout<<"Total Count: "<<In.tellg()/sizeof(P)<<endl;
14
(1)
In.seekg(70*sizeof(P));
In.read((char*)&P, sizeof(P));
In.read((char*)&P, sizeof(P));
cout<<"At Product:"<<In.tellg()/sizeof(P) + 1;
In.close();
}
OR
5
(c)
Which file stream is required for seekg() ?
(a)
Observe the following table and answer the parts(i) and(ii) accordingly
Table:Product
Pno
101
102
103
109
113
Name
Pen
Pencil
Eraser
Sharpener
Clips
Qty
102
201
90
90
900
PurchaseDate
12-12-2011
21-02-2013
09-08-2010
31-08-2012
12-12-2011
(i)
Write the names of most appropriate columns, which can be considered as
candidate keys.
(ii)
What is the degree and cardinality of the above table?
(b)
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to
(viii), which are based on the tables.
TRAINER
TID TNAME
CITY
HIREDATE SALARY
101 SUNAINA
MUMBAI
1998-10-15 90000
102 ANAMIKA
DELHI
1994-12-24 80000
103 DEEPTI
CHANDIGARG 2001-12-21 82000
104 MEENAKSHI
DELHI
2002-12-25 78000
105 RICHA
MUMBAI
1996-01-12 95000
106 MANIPRABHA CHENNAI
2001-12-12 69000
CID
C201
C202
C203
C204
C205
C206
CNAME
AGDCA
ADCA
DCA
DDTP
DHN
O LEVEL
COURSE
FEES
STARTDATE
12000
2018-07-02
15000
2018-07-15
10000
2018-10-01
9000
2018-09-15
20000
2018-08-01
18000
2018-07-25
15
(2)
TID
101
103
102
104
101
105
(4+2)
6
(i)
Display the Trainer Name, City & Salary in descending order of their
Hiredate.
(ii)
To display the TNAME and CITY of Trainer who joined the Institute in the
month of December 2001.
(iii)
To display TNAME, HIREDATE, CNAME, STARTDATE from tables
TRAINER and COURSE of all those courses whose FEES is less than or
equal to 10000.
(iv)
To display number of Trainers from each city.
(v)
SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT
IN(‘DELHI’, ‘MUMBAI’);
(vi)
SELECT DISTINCT TID FROM COURSE;
(vii)
SELECT TID, COUNT(*), MIN(FEES) FROM COURSE GROUP BY
TID HAVING COUNT(*)>1;
(viii)
SELECT COUNT(*), SUM(FEES) FROM COURSE WHERE
STARTDATE< ‘2018-09-15’;
(a)
State any one Distributive Law of Boolean Algebra and Verify it using
truth table.
(2)
(b)
Draw the Logic Circuit of the following Boolean Expression:
((U + V’).(U + W)). (V + W’)
(2)
(c)
Derive a Canonical SOP expression for a Boolean function F(X,Y,Z)
represented by the following truth table:
(1)
X Y Z F(X,Y,Z)
0
0
0
0
1
1
1
1
(d)
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
1
1
0
0
1
0
0
1
Reduce the following Boolean Expression to its simplest form using KMap:
F(X,Y,Z,W)= Σ (0,1,2,3,4,5,8,10,11,14)
16
(3)
7
(a)
Arun opened his e-mail and found that his inbox was full of hundreds of
unwanted mails. It took him around two hours to delete these unwanted
mails and find the relevant ones in his inbox. What may be the cause of his
receiving so many unsolicited mails? What can Arun do to prevent this
happening in future?
(2)
(b)
Assume that 50 employees are working in an organization. Each employee
has been allotted a separate workstation to work. In this way, all computers
are connected through the server and all these workstations are distributed
over two floors. In each floor, all the computers are connected to a switch.
Identify the type of network?
(1)
(c)
Your friend wishes to install a wireless network in his office. Explain him
the difference between guided and unguided media.
(1)
(d)
Write the expanded names for the following abbreviated terms used in
Networking and Communications:
(i) CDMA
(ii) HTTP
(iii)
XML (iv)
URL
(2)
(e)
Multipurpose Public School, Bangluru is Setting up the network
between its Different Wings of school campus. There are 4
wings named as SENIOR(S), JUNIOR(J), ADMIN(A) and
HOSTEL(H).
(4)
Multipurpose Public School, Bangluru
JUNIOR
SENIOR
ADMIN
HOSTEL
17
Distance between various wings are given below:
WingAtoWingS
100m
WingAtoWingJ
200m
WingAtoWingH
400m
WingStoWingJ
300m
WingStoWingH
100m
WingJtoWingH
450m
Number of Computers installed at various wings are as follows:
Wings
NumberofComputers
WingA
20
WingS
150
WingJ
50
WingH
25
(i)
Suggest the best wired medium and draw the cable layout to efficiently
connect various wings of Multipurpose PublicSchool, Bangluru.
(ii)
Name the
most
suitable wing where the
be installed. Justify your answer.
(iii)
Suggest a device/software and its placement that would provide
data security for the entire network of the School.
(iv)
Suggest a device and the protocol that shall be needed to provide wireless
Internet access to all smartphone/laptop users in the campus
of
Multipurpose Public School, Bangluru.
18
Server should
3. SAMPLE PAPER 2019-20, MARKING SCHEME
SAMPLE QUESTION PAPER 2019-20
Marking Scheme
COMPUTER SCIENCE - OLD (Code: 283)
CLASS:-XII
Time:3 Hrs.
M.M.:70
Q. No. Part
Question Description
1
Write the type of C++ Operators (Arithmetic, Logical, and Relational
Operators) from the following:
(a)
Marks
2
(i) !(ii) !=(iii) &&(iv) %
Ans.
(i) Logical
(ii) Relational
(iii)Logical
(iv) Arithmetic
(1/2 Mark for each correct Operator Type)
(b)
Ans.
Observe the following program very carefully and write the name of those
header file(s), which are essentially needed to compile and execute
thefollowing program successfully:
void main()
{
char text[20], newText[20];
gets(text);
strcpy(newText,text);
for(int i=0;i<strlen(text);i++)
if(text[i]==’A’)
text[i]=text[i]+2;
puts(text);
}


1
stdio.h
string.h
(½ Mark for writing each correct header file)
NOTE: Any other header file to be ignored
(c)
Rewrite the following C++ code after removing any/all Syntactical Error(s)
with each correction underlined.
Note: Assume all required header files are already being included in the
program.
#define float PI 3.14
void main( )
{
float R=4.5,H=1.5;
A=2*PI*R*H + 2*PIpow(R,2);
cout<<‘Area=’<<A<<endl;
}
19
(2)
#define PI 3.14//Error 1
void main( )
{
float R=4.5,H=1.5;
floatA=2*PI*R*H + 2*PI*pow(R,2);
cout<<“Area=”<<A<<endl;
}
//Error 2, 3
//Error 4
(½ Mark for each correction)
OR
(1 mark for identifying the errors, without suggesting corrections)
(d)
Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in
the program.
void main( )
{
int Ar[ ] = { 6 , 3 , 8 , 10 , 4 , 6 , 7} ;
int *Ptr = Ar , I ;
cout<<++*Ptr++ << '@' ;
I = Ar[3] - Ar[2] ;
cout<<++*(Ptr+I)<<'@'<<"\n" ;
cout<<++I + *Ptr++ << '@' ;
cout<<*Ptr++ <<'@'<< '\n' ;
for( ; I >=0 ; I -=2)
cout<<Ar[I] << '@' ;
}
Ans
[email protected]@
[email protected]@
[email protected]@
(3)
(½ Mark for writing each correct value)
OR
(Only ½ Mark for writing all ‘@’ at proper places)
Note:
● Deduct only ½ Mark for not considering any or all correct placements of
@
● Deduct only ½ Mark for not considering any or all line break
(e)
Find and write the output of the following C++ program code:
typedef char STRING[80];
void MIXNOW(STRING S)
{
int Size=strlen(S);
for(int I=0;I<Size;I+=2)
{
char WS=S[I];
20
(2)
S[I]=S[I+1];
S[I+1]=WS;
}
for (I=1;I<Size;I+=2)
if (S[I]>=’M’ && S[I]<=’U’)
S[I]=’@’;
}
void main()
{
STRING Word=”CBSEEXAM2019”;
MIXNOW(Word);
cout<<Word<<endl;
}
Ans.
[email protected]
(2 Marks for correct output)
OR
(½ Mark for each of two correct consecutive alphabets not exceeding 1½
marks )
(f)
Observe the following program and find out, which output(s) out of (i) to
(iv) willbe expected from the program? What will be the minimum and the
maximum value assigned to the variable Alter?
Note: Assume all required header files are already being included in
the program.
void main( )
{
randomize();
int Ar[]={10,7}, N;
int Alter=random(2) + 10 ;
for (int C=0;C<2;C++)
{
N=random(2) ;
cout<<Ar[N] +Alter<<”#”;
}
}
(i) 21#20#
(ii) 20#18#
(iii) 20#17#
(iv) 21#17#
Ans.
The output expected from the program is (iii) 20#17#
Minimum Value of Alter = 10
Maximum Value of Alter = 11
(1 Mark for writing correct option (iii))
( ½ Mark for writing correct Minimum Value of Alter)
( ½ Mark for writing correct Maximum Value of Alter)
21
(2)
2
3
(a)
What is a copy constructor? Illustrate with a suitable C++ example.
Ans.
A copy constructor is an overloaded constructor in which an object of the
same class is passed as reference parameter.
class X
{
int a;
public:
X()
{
a=0;
}
X(X &ob)
//copy constructor
{
a=ob.a;
}
};
(2)
(Full 2 Marks to be awarded if the copy constructor is explained with an
appropriate example)
OR
(1 Mark for correct explanation of copy constructor only without an
example)
(b)
Write the output of the following C++ code. Also, write the name of
feature of Object Oriented Programming used in the following program
jointly illustrated by the Function 1 to Function 4.
void My_fun ( )
// Function 1
{
for (int I=1 ; I<=50 ; I++) cout<< "-" ;
cout<<end1 ;
}
void My_fun (int N)
// Function 2
{
for (int I=1 ; I<=N ; I++) cout<<"*" ;
cout<<end1 ;
}
void My_fun (int A, int B)
// Function 3
{
for (int I=1. ;I<=B ;I++) cout <<A*I ;
cout<<end1 ;
}
void My_fun (char T, int N)
// Function 4
{
for (int I=1 ; I<=N ; I++) cout<<T ;
cout<<end1;
22
(2)
}
void main ( )
{
int X=7, Y=4, Z=3;
char C='#' ;
My_fun (C,Y) ;
My_fun (X,Z) ;
}
OR
Write any four differences between Constructor and Destructor function
with respect to object oriented programming
Ans.
####
71421
Polymorphism
OR
Function Overloading
OR
Constructor
Destructor
Name of the constructor function is Name of the destructor function is
same as that of class
same as that of class preceded by
~
Constructor functions are called
Destructor functions are called
automatically at the time of
automatically when the scope of
creation of the object
the object gets over
Constructor can be overloaded
Destructor ca not be overloaded
Constructor is used to initialize the Destructor is used to de- initialize
data members of the class
the data members of the class
(½ Mark for writing each correct line of output)
(1 Mark for writing the feature name correctly)
OR
(½ Mark for writing each correct difference)
(c)
Define a class Ele_Bill in C++ with the following descriptions:
Private members:
Cname
of type character array
Pnumber
of type long
No_of_units
of type integer
Amount
of type float.
Calc_Amount( )
This member function should calculate the
amount asNo_of_units*Cost .
23
(4)
Amount can be calculated accordingto the following conditions:
No_of_units Cost
First 50 units
Free
Next 100 units
Next 200 units
Remaining units
0.80 @ unit
1.00 @ unit
1.20 @ unit
Public members:
* A function Accept( ) which allows user to enter Cname,
Pnumber, No_of_units and invoke function Calc_Amount().
* A function Display( ) to display the values of all the data members
on the screen.
Ans.
class Ele_Bill
{
char Cname[20];
long Pnumber;
int No_of_units;
float Amount;
void Calc_Amount( );
public:
void Accept();
void Display();
};
void Ele_Bill : : Calc_Amount( )
{
if(No_of_units<=50)
{
Amount=0;
}
else if(No_of_units<=150)
{
Amount=(No_of_units-50)*0.80;
}
else if(No_of_units<=350)
{
Amount=80+(No_of_units-150)*1.00;
}
else
{
Amount=80+200+(No_of_units-350)*1.20;
}
}
void Ele_Bill :: Accept( )
24
{
gets(Cname);
cin>Pnumber>>No_of_units;
Calc_Amount( );
}
void Ele_Bill :: Display( )
{
cout<<Cname<<Pnumber<<No_of_units<<Amount;
}
(½ Mark for declaring class header correctly)
(½ Mark for declaring data members correctly)
(1 Mark for defining Calc_Amount() correctly)
(½ Mark for taking inputs of Cname, Pnumber and No_of_units in
Accept())
(½ Mark for invoking Calc_Amount() inside Accept())
(½ Mark for defining Display() correctly)
(½ Mark for correctly closing class declaration with a semicolon ; )
NOTE:
Marks to be awarded for defining the member functions inside or
outside the class
(d)
Answer the questions (i) to (iv) based on the following:
class Faculty
{
int FCode;
protected:
char FName[20];
public:
Faculty();
void Enter();
void Show();
};
class Programme
{
int PID;
protected:
char Title[30];
public:
Programme();
void Commence();
void View();
};
class Schedule: public Programme, Faculty
{
int DD,MM,YYYY;
public:
Schedule();
25
(4)
void Start();
void View();
};
void main()
{
Schedule S;
//Statement 1
//Statement 2
}
OR
Consider the following class State :
class State
{
protected :
int tp;
public :
State( ) { tp=0;}
void inctp( ) { tp++;};
int gettp(); { return tp; }
};
Write a code in C++ to publically derive another class ‘District’
with the following additional members derived in the public
visibility mode.
Data Members :
Dname
string
Distance
float
Population
long int
Member functions :
DINPUT( ) : To enter Dname, Distance and population
DOUTPUT( ) : To display the data members on the screen.
(i)
Write the names of all the member functions, which are directly accessible
by the object S of class Schedule as declared in main() function.
Ans.
Start(), Schedule::View(), Commence(), Programme::View()
(1 Mark for writing all correct member names )
NOTE:
● Ignore the mention of Constructors
(ii)
Write the names of all the members, which are directly accessible by the
memberfunction Start( ) of class Schedule.
Ans.
DD,MM,YYYY, Schedule::View()
Title, Commence( ), Programme::View()
Fname, Enter(), Show()
(1 Mark for writing all correct member names )
26
NOTE:
● Marks not to be awarded for partially correct answer
● Ignore the mention of Constructors
(iii)
Write Statement 2 to call function View( ) of class Programme from the
object S of class Schedule.
Ans.
S.Programme::View( );
(1 Mark for writing Statement 2 correctly)
(iv)
What will be the order of execution of the constructors, when the object S
of class Schedule is declared inside main()?
Ans.
Programme( ), Faculty( ), Schedule( )
OR
Ans.
class District : public State
{
public :
char
Dname[20];
float
Distance;
long int Population;
void DINPUT( )
{
gets(Dname);
cin>>distance;
cin>>Population;
}
void DOUTPUT( )
{
cout<<Dname<<endl;
cout<<Distance<<endl;
cout<<population<<endl;
}
};
(1 Mark for writing correct order)
● No Marks to be awarded for any other combination/order.
● Names of the constructor/class without parenthesis is acceptable
OR
(1 Mark for correct syntax for derived class header)
(½ Mark for writing public : )
(½ Mark for correct declaration of data members Dname ,Distance and
Population)
(1 Mark for defining the function DINPUT( ) )
(1 Mark for defining the function DOUTPUT( ) )
27
(a)
Ans.
Write a user-defined function AddEnd4(int A[][4],int R,int C) in C++ to
find and display the sum of all the values, which are ending with 4 (i.e.,
unit place is 4).
For example if the content of array is:
24 16 14
19 5 4
The output should be 42
OR
Write a user defined function in C++ to find the sum of both left and right
diagonal elements from a two dimensional array.
void AddEnd4(int A[ ][4], int R, int C)
{
int I,J,sum=0;
for(I=0;I<R;I++)
{
for(J=0;J<C;J++)
if(A[I][J]%10 ==4)
sum=sum+A[I][J];
}
cout<<sum;
}
OR
void Diagsumboth(int A[][4], int n)
{
int sumLt=0,sumRt=0;
for(int i=0;i<n;i++)
{
sumLt+=A[i][i];
else
sumRt+=A[n-1-i][i];
}
cout<<”sum of left diagonal”<<sumlt<<endl;
cout<<”sum of right diagonal”<<sumRt<<endl;
}
(½ Mark for correct loops)
(½ Mark for correct checking values ending with 4)
( ½ Mark for finding sum of values)
( ½ Mark for displaying the sum )
OR
(1/2 Mark for correct loop)
(1/2 Mark each for calculating sum of left or right diagonals)
(1/2 Mark for displaying)
28
(2)
(b)
Write a user-defined function EXTRA_ELE(int A[ ], int B[ ], int N) in C++
to find and display the extra element in Array A. Array A contains all the
elements of array B but one more element extra. (Restriction: array
elements are not in order)
Example
If the elements of Array A is 14, 21, 5, 19, 8, 4, 23, 11
and the elements of Array B is 23, 8, 19, 4, 14, 11, 5
Then output will be 21
OR
Write a user defined function Reverse(int A[],int n) which accepts an
integer array and its size as arguments(parameters) and reverse the array.
Example : if the array is 10,20,30,40,50 then reversed array is
50,40,30,20,10
Ans.
void EXTRA_ELE(int A[], int B[],int N)
{
int i,j,flag=0;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
if(A[i]==B[j])
{
flag=1;
break;
}
}
if(flag==0)
cout<<"Extra element"<<A[i];
flag=0;
}
}
OR
void Reverse( int A[ ] , int n)
{
int temp;
for(int i=0;i<n/2;i++)
{
temp=A[i];
A[i]=A[n-1-i];
A[n-1-i]=temp;
}
}
(1 Mark for correct loops)
(1 Mark for checking array elements which are equal)
( ½ Mark for display the extra element)
29
(3)
OR
(1 Mark for correct loop)
(2 Marks for swapping elements)
(c)
An array S[10] [30] is stored in the memory along the column with each of
its element occupying 2 bytes. Find out the memory location of S[5][10], if
element S[2][15] is stored at the location 8200.
OR
An array A[30][10] is stored in the memory with each element requiring 4
bytes of storage ,if the base address of A is 4500 ,Find out memory
locations of A[12][8], if the content is stored along the row.
Ans.
OPTION 1:
ASSUMING LBR=LBC=0
W=2 BYTES, NUMBER OF ROWS(M)=10, NUMBER OF
COLUMNS(N)=30
LOC(S[I][J]) = B +(I + J*M)*W
LOC(S[2][15]) = B +(2+15*10)* 2
8200 = B + (152*2)
B = 8200 - 304
B = 7896
LOC(S[5][10]) = 7896 +(5+10*10)* 2
= 7896 + (105*2)
= 7896 + 210
= 8106
OPTION 2:
ASSUMING LBR=2,LBC=15 AND B = 8200
W=2 BYTES, NUMBER OF ROWS(M)=10, NUMBER OF
COLUMNS(N)=30
LOC(S[I][J]) = B +((I-LBR) + (J-LBC)*M)*W
LOC(S[5][10])= 8200 + ((5-2) + (10-15)*10)*2
= 8200 + (3 + (-5)*10) * 2
= 8200 + (3 + (-50)) * 2
= 8200 + (3 – 50) * 2
= 8200 + (-47) * 2
= 8200 – 94
= 8106
OR
Loc of A[12][8]= B+W*(N*(I-LBR)+(J-LBC))
=4500+4*(10*12+8)
= 4500 4*(128)
=4500 + 512
= 5012
30
(3)
1 Mark for writing correct formula (for column major)
OR substituting formula with correct values)
(1 Mark for correct step calculations)
(1 Mark for final correct address)
OR
1 Mark for writing correct formula (for Row major)
OR substituting formula with correct values)
(1 Mark for correct step calculations)
(1 Mark for final correct address)
(d)
Write the definition of a member function Ins_Player() for a class
CQUEUE in C++, to add a Player in a statically allocated circular queue of
PLAYERs considering the following code
is already written as a part of the program:
struct Player
{
long Pid;
char Pname[20];
};
const int size=10;
class CQUEUE
{
Player Ar[size];
int Front, Rear;
public:
CQUEUE( )
{
Front = -1;
Rear=-1;
}
void Ins_Player(); // To add player in a static circular queue
void Del_Player(); // To remove player from a static circular queue
void Show_Player(); // To display static circular queue
};
OR
Write a function in C++ to delete a node containing Books information
,from a dynamically allocated stack of Books implemented with the help of
the following structure:
struct Book
{
int BNo;
char BName[20];
Book *Next;
};
31
(4)
Ans.
void CQUEUE : : Ins_Player( )
{
if((Front==0 && Rear==size-1) || (Front==Rear+1)
{
cout<< “Overflow”;
return;
}
else if(Rear = = -1)
{
Front=0;
Rear=0;
}
else if(Rear= =size-1)
{
Rear=0;
}
else
{
Rear++;
}
cout<< “Enter Player Id=”;
cin>>Ar[Rear].Pid;
cout<< “Enter Player Name=”;
gets(Ar[Rear].Pname);
}
OR
struct Book
{
int BNo;
char BName[20];
Book *Next;
}*temp,*top;
void pop()
{
temp=new Book ;
temp=top;
top=top->next;
delete temp;
}
(1 Mark for checking if Queue is Full)
(1 Mark for checking if Queue is Empty)
(½ Mark for checking Rear is at size-1)
(½ Mark for incrementing Rear)
(½ Mark for assigning Values to the Rear location of the Queue)
32
OR
( 1 Mark for creating new node Book)
(1 Mark for assigning top to temp)
(1 Mark for top=top->next)
(1 Mark for delete top)
(e)
Convert the following Infix expression to its equivalent Postfix expression,
showing the stack contents for each step of conversion.
A/B+C*(D-E)
(2)
OR
Evaluate the following Postfix expression :
4,10,5,+,*,15,3,/,Ans:
Element
A
/
B
+
C
*
(
D
E
)
Stack
Postfix
A
A
AB
AB/
AB/C
AB/C
AB/C
AB/CD
AB/CD
AB/CDE
AB/CDEAB/CDE-*
AB/CDE-*+
/
/
+
+
+*
+*(
+*(
+*(+*(+*
+
OR
55
(½ Mark for conversion upto each operator illustrating through stack)
OR
(1/2 Mark for evaluating each operator)
4
(a)
Write a function RevText() to read a text file “ Input.txt “ and Print only
word starting with ‘I’ in reverse order .
Example: If value in text file is: INDIA IS MY COUNTRY
Output will be: AIDNI SI MY COUNTRY
OR
Write a function in C++ to count the number of lowercase alphabets
present in a text file “BOOK..txt".
33
(2)
Ans.
void RevText( )
{
ifstream Fin(“Input.txt”);
char Word[20];
while(!Fin.eof())
{
Fin>>Word;
if(Word[0]==’I’)
strrev(Word);
cout<<Word<< “ ”;
}
Fin.close( );
}
OR
int Countalpha()
ifstream ifile ("BOOK.txt");
char ch;
int count =0;
while (! ifile.eof())
{
ifile.get(ch);
if(isfower(ch))
count ++;
}
ifile.close();
return (count)
}
(½ Mark for opening Input.txt correctly)
(½ Mark for reading each Word from the file)
(½ Mark for checking the word starting with ‘I’ )
(½ Mark for reversing and displaying the word)
OR
(½ Mark for opening Input.txt correctly)
(½ Mark for reading each character from the file)
(½ Mark for checking the lower character )
(½ Mark for displaying the count)
(b)
Write a function in C++ to search and display details, whose destination is
“Cochin” from binary file “Bus.Dat”. Assuming the binary file is
containing the objects of the following class:
class BUS
{
int Bno;
// Bus Number
char From[20];
// Bus Starting Point
34
(3)
char To[20];
// Bus Destination
public:
char * StartFrom ( ); { return From; }
char * EndTo( ); { return To; }
void input() { cin>>Bno>>; gets(From); get(To); }
void show( ) { cout<<Bno<< “:”<<From << “:” <<To<<endl; }
};
OR
Write a function in C++ to add more new objects at the bottom of a binary
file "STUDENT.dat", assuming the binary file is containing the objects of
the following class :
class STU
{
int Rno;
char Sname[20];
public: void Enter()
{
cin>>Rno;gets(Sname);
}
void show()
{
count << Rno<<sname<<endl;
}
};
Ans.
void Read_File( )
{
BUS B;
ifstream Fin;
Fin.open(“Bus.Dat”, ios::binary);
while(Fin.read((char *) &B, sizeof(B)))
{
if(strcmp(B.EndTo(), “Cochin”)==0)
{
B.show( ) ;
}
}
Fin.close( );
}
OR
void Addrecord()
{
ofstream ofile;
ofile.open("STUDENT.dat", ios ::out);
STU S;
char ch='Y';
while (Ch=='Y' || Ch = = 'y')
{
35
S.Enter();
ofile.write (Char*) & S, sizeof(s));
cout << "more (Y/N)";
cin>>ch;
}
ofile.close();
}
(½ Mark for opening Bus.Dat correctly)
(1 Mark for reading each record from Bus.Dat)
(1 Mark for comparing value returned by EndTo( ) with “Cochin”)
(½ Mark for displaying the matching record)
OR
(1 Mark for opening STUDENT.Dat correctly)
(1 Mark for S.Enter())
(1 Mark for writing each record into the file)
(c)
Find the output of the following C++ code considering that the binary file
PRODUCT.DAT exists on the hard disk with a list of data of 500 products.
class PRODUCT
{
int PCode;char PName[20];
public:
void Entry();void Disp();
};
void main()
{
fstream In;
In.open("PRODUCT.DAT",ios::binary|ios::in);
PRODUCT P;
In.seekg(0,ios::end);
cout<<"Total Count: "<<In.tellg()/sizeof(P)<<endl;
In.seekg(70*sizeof(P));
In.read((char*)&P, sizeof(P));
In.read((char*)&P, sizeof(P));
cout<<"At Product:"<<In.tellg()/sizeof(P) + 1;
In.close();
}
OR
Which file stream is required for seekg() ?
Ans.
Total Count:500
At Product: 73
OR
36
(1)
fstream/ ifstream
(½ Mark for each correct value of In.tellg()/sizeof(P) as 500 and 73
respectively)
OR
(1 Mark for correct stream)
5
(a)
Observe the following table and answer the parts(i) and(ii) accordingly
Table:Product
Pno
101
102
103
109
113
Name
Pen
Pencil
Eraser
Sharpener
Clips
Qty
102
201
90
90
900
(2)
PurchaseDate
12-12-2011
21-02-2013
09-08-2010
31-08-2012
12-12-2011
(i)
Write the names of most appropriate columns, which can be considered as
candidate keys.
Ans.
Candidate Key: Pno, Name
(1 Mark for writing correct Candidate Keys)
(ii)
What is the degree and cardinality of the above table?
Ans.
Degree:4
Cardinality:5
(½ Mark for writing correct value of degree)
(½ Mark for writing correct value of cardinality)
(b)
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to
(viii), which are based on the tables.
TRAINER
TID
101
102
103
104
105
106
TNAME
SUNAINA
ANAMIKA
DEEPTI
MEENAKSHI
RICHA
MANIPRABHA
CITY
MUMBAI
DELHI
CHANDIGARG
DELHI
MUMBAI
CHENNAI
37
HIREDATE
1998-10-15
1994-12-24
2001-12-21
2002-12-25
1996-01-12
2001-12-12
SALARY
90000
80000
82000
78000
95000
69000
(4+2)
COURSE
CID
C201
C202
C203
C204
C205
C206
CNAME
AGDCA
ADCA
DCA
DDTP
DHN
O LEVEL
FEES
12000
15000
10000
9000
20000
18000
STARTDATE
2018-07-02
2018-07-15
2018-10-01
2018-09-15
2018-08-01
2018-07-25
TID
101
103
102
104
101
105
(i)
Display the Trainer Name, City & Salary in descending order of their
Hiredate.
Ans.
SELECT TNAME, CITY, SALARY FROM TRAINER ORDER BY
HIREDATE;
(½ Mark for SELECT TNAME, CITY, SALARY FROM TRAINER)
(½ Mark for ORDER BY HIREDATE)
(ii)
To display the TNAME and CITY of Trainer who joined the Institute in the
month of December 2001.
Ans.
SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE
BETWEEN ‘2001-12-01’ AND ‘2001-12-31’;
OR
SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE >=
‘2001-12-01’ AND HIREDATE<=‘2001-12-31’;
OR
SELECT TNAME, CITY FROM TRAINER WHERE HIREDATE LIKE
‘2001-12%’;
(½ Mark for SELECT TNAME, CITY FROM TRAINER)
(½ Mark for
WHERE HIREDATE BETWEEN ‘2001-12-01’ AND ‘2001-12-31’
OR
WHERE HIREDATE >= ‘2001-12-01’ AND HIREDATE<=‘2001-12-31
OR
WHERE HIREDATE LIKE ‘2001-12%’
(iii)
To display TNAME, HIREDATE, CNAME, STARTDATE from tables
TRAINER and COURSE of all those courses whose FEES is less than or
equal to 10000.
Ans.
SELECT TNAME,HIREDATE,CNAME,STARTDATE FROM
TRAINER, COURSE WHERE TRAINER.TID=COURSE.TID AND
FEES<=10000;
38
(1 Mark for correct query)
OR
(½ Mark for correct SELECT )
(½ Mark for correct WHERE Clause)
(iv)
To display number of Trainers from each city.
Ans.
SELECT CITY, COUNT(*) FROM TRAINER GROUP BY CITY;
(1 Mark for correct query)
OR
(½ Mark for correct SELECT )
(½ Mark for GROUP BY CITY)
(v)
SELECT TID, TNAME, FROM TRAINER WHERE CITY NOT
IN(‘DELHI’, ‘MUMBAI’);
Ans.
TIDTNAME
103
DEEPTI
106
MANIPRABHA
(½ Mark for correct output)
(vi)
SELECT DISTINCT TID FROM COURSE;
Ans.
DISTINCT TID
101
103
102
104
105
(½ Mark for correct output)
(vii)
SELECT TID, COUNT(*), MIN(FEES) FROM COURSE GROUP BY
TID HAVING COUNT(*)>1;
Ans.
TIDCOUNT(*)MIN(FEES)
101
2
12000
(½ Mark for correct output)
(viii) SELECT COUNT(*), SUM(FEES) FROM COURSE WHERE
STARTDATE< ‘2018-09-15’;
Ans.
COUNT(*)SUM(FEES)
4
65000
(½ Mark for correct output)
39
6
(a)
State any one Distributive Law of Boolean Algebra and Verify it using
truth table.
Ans.
Distributive Law:
A+BC=(A+B)(A+C)
Verification
(2)
A B C BC A+BC (A+B) (A+C) (A+B)(A+C)
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
0
0
1
0
0
0
1
0
0
0
1
1
1
1
1
0
0
1
1
1
1
1
1
0
1
0
1
1
1
1
1
0
0
0
1
1
1
1
1
OR
A(B+C)=AB+AC
A B C B+C A(B+C) AB AC AB+AC
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
1
0
1
1
1
0
0
0
0
0
1
1
1
0
0
0
0
0
0
1
1
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
(1 Mark for stating any one Distributive Law correctly)
(1 Mark for correctly verifying the stated Law using Truth Table)
(b)
Draw the Logic Circuit of the following Boolean Expression:
((U + V’).(U + W)). (V + W’)
(2)
Derive a Canonical SOP expression for a Boolean function F(X,Y,Z)
represented by the following truth table:
(1)
Ans.
(c)
40
X Y Z F(X,Y,Z)
0 0 0
1
0 0 1
1
0 1 0
0
0 1 1
0
1 0 0
1
1 0 1
0
1 1 0
0
1 1 1
1
Ans.
F(X,Y,Z)= X’Y’Z’+X’Y’Z+XY’Z’+XYZ
OR
F(X,Y,Z)=∑(0,1,4,7)
(1 Mark for the correct SOP form)
OR
(½ Mark for writing any two term correctly)
(d)
Reduce the following Boolean Expression to its simplest form using KMap:
F(X,Y,Z,W)= Σ (0,1,2,3,4,5,8,10,11,14)
(3)
Simplified Expression: X’Z’+Y’W’+Y’Z+XZW’
(½ Mark for drawing K-Map and correctly plotting 1s in the given cells)
( ½ Mark each for 4 groupings)
( ½ Mark for writing final expression in reduced/minimal form)
Note:
● Deduct ½ mark if wrong variable names are used
7
(a)
Arun opened his e-mail and found that his inbox was full of hundreds of
unwanted mails. It took him around two hours to delete these unwanted
mails and find the relevant ones in his inbox. What may be the cause of his
receiving so many unsolicited mails? What can Arun do to prevent this
happening in future?
41
(2)
Ans.
Arun’s email has been attacked with spam.
These may be promotional mails from different advertisement groups.
Arun must have checked some promotional offers while surfing the
Internet.
He should create filters in his email to stop receiving these unwanted mails.
(1 Mark for writing correct Answer)
(1 Mark for writing correct Justification to prevent Spam)
(b)
Assume that 50 employees are working in an organization. Each employee
has been allotted a separate workstation to work. In this way, all computers
are connected through the server and all these workstations are distributed
over two floors. In each floor, all the computers are connected to a switch.
Identify the type of network?
Ans.
LAN(Local Area Network)
(1)
(1 Mark for writing correct Answer)
(c)
Your friend wishes to install a wireless network in his office. Explain him
the difference between guided and unguided media.
Ans.
Guided media uses cables to connect computers, whereas unguided media
uses waves.
(1)
(1 Mark for writing any correct difference between guided and unguided
media)
(d)
Ans.
Write the expanded names for the following abbreviated terms used in
Networkingand Communications:
(i) CDMA
(ii) HTTP
(iii)
XML (iv)
URL
(i)
(ii)
(iii)
(iv)
(2)
Code Division Multiple Access
Hyper Text Transfer Protocol
Extensible Markup Language
Uniform Resource Locator
( ½ Mark for writing each correct expansion)
(e)
Multipurpose Public School, Bangluru is Setting up the network
between its Different Wings of school campus. There are 4
wings
namedasSENIOR(S),JUNIOR(J),ADMIN(A)andHOSTEL(H).
Multipurpose Public School, Bangluru
42
(4)
SENIOR
JUNIOR
ADMIN
HOSTEL
Distance between various wings are given below:
WingAtoWingS
100m
WingAtoWingJ
WingAtoWingH
200m
400m
WingStoWingJ
300m
WingStoWingH
WingJtoWingH
100m
450m
Number of Computers installed at various wings are as follows:
Wings
NumberofComputers
WingA
20
WingS
WingJ
150
50
WingH
25
(i)
Suggest the best wired medium and draw the cable layout to efficiently
connect various wings of Multipurpose PublicSchool, Bangluru.
Ans
Best wired medium: Optical Fibre OR CAT5 OR CAT6 OR CAT7 OR
CAT8 OR Ethernet Cable
43
SENIOR
JUNIOR
HOSTEL
ADMIN
(½ Mark for writing best wired medium)
(½ Mark for drawing the layout correctly)
(ii)
Name the most suitable wing where the
installed. Justify your answer.
Ans.
Wing Senior(S)- Because it has maximum number of computers.
Server should be
(½ Mark for correct Wing)
(½ Mark for valid justification)
(iii)
Suggest a device/software and its placement that would provide
data security for the entire network of the School.
Ans.
Firewall - Placed with the server at Senior
OR
Any other valid device/software name
(½ Mark for writing device/software name correctly)
(½ Mark for writing correct placement)
(iv)
Suggest a device and the protocol that shall be needed to provide wireless
Internet access to all smartphone/laptop users in the campus of
Multipurpose Public School, Bangluru.
Ans.
Device Name: WiFi Router OR WiMax OR RF Router OR Wireless
Modem OR RFTransmitter
Protocol : WAP OR 802.16 OR TCP/IP OR VOIP OR MACP OR 802.11
(½ Mark for writing correct device name)
(½ Mark for writing correct protocol)
4. ANALYSIS OF THE QUESTION PAPER

The question paper has 7 questions, each question having subparts.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 44


Question number 2 (b, d), 3 and 4 has internal choices.
Question wise details are as follows:
Marks
Question
Subpart
Topic
No.
1
a
2
C++ Theory ( Class XI)
b
1
Header Files
c
2
Identifying Syntax Errors
( Based on C++ language syntax)
d
3
Predicting Output
( Class XI or Class XII C++ Concepts)
e
2
Predicting Output
( Class XI or Class XII C++ Concepts)
f
2
Predicting Output
( Random number generation in C++)
2
a
2
C++ Theory ( Class XII)
b
2
Classes and Objects
(Function Overloading +
Constructors and Destructors)
c
4
Classes and Objects
(Class Definition)
d
4
Classes and Objects
( Inheritance Concepts, Defining derived class
using a base class )
3
a
2
Data Structures
( Functions based on 1D arrays and 2D arrays)
b
3
Data Structures
( Functions based on 1D arrays and 2D arrays)
c
3
Data Structures
( Address Computation in 2D arrays)
d
4
Data Structures
( Array based and Linked Stacks and Queues)
e
2
Data Structures
( Infix and Post Fix expressions)
4
a
2
File Handling
(Program based on text file handling)
b
3
File Handling
(Program based on binary file handling)
c
1
File Handling
(Theory or output question)
5
a
2
Database Management
( Concepts based)
b
6
Database Management
( Writing SQL Queries and Predicting
Outputs of SQL Queries)
6
a
2
Boolean Algebra
( Laws of Boolean Algebra)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 45
7
b
2
c
1
d
3
a
2
b
1
c
1
d
2
e
4
Boolean Algebra
( Logic Circuits )
Boolean Algebra
( POS and SOP Equations)
Boolean Algebra
( Karnaugh Maps )
Networking
( Networking Concepts – Theory )
Networking
( Networking Concepts – Theory )
Networking
( Networking Concepts – Theory )
Networking
( Networking Concepts – Theory )
Networking
( Designing a network )
5. TOPIC/QUESTION WISE NOTES, SOLVED AND UNSOLVED
QUESTIONS, TIPS
5.1 QUESTION 1 ( Topic: Revision Of C++ Done In Class XI) : ( 12 Marks )
5.1.1 QUESTION 1 (a) Class XI Theory ( 2 Marks )
5.1.1.1 Revision Notes
 About the C++ language:
o
o
o
o
o
o
Developed by Bjarne Strousstrup in 1980.
High level third generation language. ( => English like in nature )
Free format language ( no restrictions on the placement of statements ).
Compiled language. ( Translated in one go and the object code stored on disk )
C with classes.(Superset of C. Adds the new feature of classes )
Case Sensitive language (distinguishes between upper case and lower case
characters ).
o Object oriented language
 Program revolves around classes and objects.
 Data is given first class status.
 Exhibits features like data encapsulation, data hiding, data abstraction,
polymorphism, inheritance.
 Program development process:
o Done using an IDE (Integrated Development Environment )
o C++ compiler is called an IDE because it provides all tools ( like editor, compiler,
linker, loader, debugger etc. ) that are required for program development under one
environment.
o Examples of IDE ( Turbo C++, Borland C++, Codeblocks )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 46
o Stages of program development…..Edit -> Compile -> Link -> Run ( extension at
each stage … .cpp, .obj, .exe )
 Programming Methodology
o Guidelines for writing good programs:
 Use of meaningful identifier names.
 Use of comments.
 Use of proper indentation.
 Clarity and simplicity of expressions used.
 Use of blank lines and spaces wherever required to increase the readability
of code.
 Program should have proper internal and external documentation so that
program maintenance is easy.
 The program should be correct, user friendly, efficient, robust and portable.
 The program should be correct, user friendly, efficient, robust and portable.
 The program should be modular.
o Comments:
 lines of text inserted in a C++ program to enhance it's readabilityand
understandability.
 These lines are not executable i.e. they are ignored by the compiler.
 Single line comments : Begin with a // and continue till the end of the line.
 multi line comments. Begin with a /* and end with a */
o Indentation:
 Refers to the statement formatting style that uses tabs and spaces to make
the program clear and readable.
 All statements at the same level of nesting are made to start from the same
column position i.e. fall one below the other. Thus, a closing brace i.e. } will
always lie exactly below its corresponding opening brace i.e. {.
 Makes it easy to detect errors on account of extra or missing curly braces.
o Documentation:
 provides written information about a program.
 Refers to all written material that helps to explain the design, use and
maintenance of a program.
 External Documentation: Includes written material that is not a part of the
source code of the program. Includes manuals like a users guide, operators
guide, reference manual etc.
 Internal Documentation: Is part of the program source code. Includes
explanatory comments, use of meaningful identifier names etc.
o Robust:
 Program is robust if it is able to gracefully recover following an error or
adverse situation and continues operating within its environment.
o Portable?
 Program is portable if it can be carried to another machine and executed
there without having to make any changes in its source code.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 47
o Modularity?
 The feature wherein a large program can be partitioned into smaller
components called modules is called modularity.
 Each module is a named logically complete unit in itself containing logically
related data and instructions, performing a specific function and which can
be invoked from other parts of the program.
 Modularity promotes code reusability.
 Resultant programs are more readable and understandable.
 Modules can be independently tested and so program maintenance is easy.
 Errors ( with examples ) :
o An error in a program is also called a bug.
o The act of identification and removal of errors is called debugging.
o Compile time errors : occur at the time of compilation
 Syntax Error
- errors caused due to the violation of the grammatical rules
governing the formation of valid statements in the C++ language.
- ( e.g. missing semicolon ) and
 Semantic Error
- errors that occur when the statements are not meaningful
- ( e.g. incorrect data types or inputs to a function)
o Linker Error : occur at the time of linking
 ( e.g. missing main(), missing library function )
o Runtime Error : occur when the program is running and the program usually
aborts or hangs.
 ( e.g. attempt to divide by 0 )
o Logical Error: also occurs during run time but in this case the program gives an
incorrect output.
 ( e.g. using the expression a+b / 2 to find the average of two numbers )
 C++ Program Structure:
o Character set
 Letters, Digits, Special symbols, White spaces, Other characters
o Tokens ( smallest individual unit of a program that has meaning )
 Identifiers
 Names given to parts of a program e.g. variable name, function
name.
 Rules for naming identifiers:
o can use alphabet, digits or underscore.
o cannot start with a digit.
o cannot be a keyword.
 Operators
 Unary ( one operand – e.g. ++ , --, ! ), Binary ( 2 operands – e.g. +,,*,/,%), Ternary ( 3 operands - ?: or conditional operator )
 Arithmetic ( +, -, *, /, % ) , Logical ( && , ||, ! ) , Relational ( <.
<=, >, >=, ==, != )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 48


Only compile time operator – sizeof
& - address of operator ( returns the address of the variable with
which it is used ).
 * - indirection operator ( used with a pointer and returns the location
that the pointer is pointing to ).
 Difference between ++a and a++
 Difference between = and ==
 Difference between / and %
 % does not work with real numbers.
 / gives an integer result ( the quotient ) if both its operands are
integers.
 Literals/Constants
 Integer constants
o can be expressed as decimal, octal [ begin with 0 ] ,
hexadecimal [ begin with 0x or 0X ]
 Real constants
o default is double
 Character constants
o written within single quotes.
o include escape sequences that are non graphic characters that
begin with a \. e.g. ‘\n’, ‘\t’
 String constants
o Enclosed within double quotes.
o Occupy one extra byte ( for the string terminator ‘\0’ )than
the no of characters in the string.
 Keywords
 Language reserved words.
 Examples … if, while, break
 Punctuators
 Separators like , ; etc
o Expressions
 Order of evaluation of expressions:
 Depends on operator precedence ( decides which operator will get
its operands first ) and associativity ( usually left to right but some
like assignment are right associative ).
 Also compiler dependent.
 Type conversion
 implicit ( done by the compiler e.g. 5/2.0 is 2.5 ) and
 explicit ( type casting e.g. ( (double)5)/2 is also 2.5)
 C++ shorthands
 +=, -=, *=, /+, %=
o Statements
 Simple statement.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 49


 A single C++ statement.
Compound statement.
 A set of statements enclosed within curly braces.
Selection statements.
 Statements that allow us to choose the set of instructions to be
executed based on the truth value of an expression.
 Also called conditional statements or decision statements.
 Comparison of if and switch. / Limitations of switch
o The case labels can only be integer or character constants.
o One can compare the switch expression with the case labels
only for equality. Relational operators cannot be used for
comparisons so no range checks possible
o Since the if-else can handle ranges, can evaluate relational
and logical expressions, can compare with variables and also
with floating point data , therefore, the if else is a more
versatile statement as compared to a switch.
 Significance of default clause:
o The default clause is executed when the switch expression
does not match with any of the case labels.
 A missing break in a switch thus leads to a fall through.. This
implies that the code of the next case will also get executed and this
will continue till a break is encountered or the end of switch is
encountered.

Iteration statements.
 looping statements that perform a task repetitively.
 for, while and do while
 While loop vs. do while loop.
o While is Entry controlled loop , do while is Exit controlled.
o do while is executed at least once but while may not be
executed even once ( when the while condition is false)
 Infinite loop
o runs forever
o for(;;);
o while(1)
 Nesting of loops
o loop inside a loop.
 Jump statements.
 Break, continue, return, goto
 Difference between break and continue
o break takes you out of the loop or a switch, while continue is
only used in a loop and it takes you to the next loop iteration.
o Functions
o File
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 50
o Project
 Standard C++ library and Header files:
o What does the library contain?
 definitions of commonly required functions in their compiled form.
o What do the header files contain?
 prototypes of library functions, definition of data types ( e.g. ifstream ),
variables ( e.g. cout ) and constants .
o iostream.h … cin and cout.
o Buffered ( getchar() ) Vs. Unbuffered I/O ( getch(), putch(), getche() ).
o math.h, ctype.h, string.h, process.h, stdlib.h()
o getline() vs. get() while reading in lines of text ( removal vs. non removal of
delimiter )
 Data in a C++ program:
o Data types:
 Fundamental ( atomic, inbuilt in the language, void , int, char, float, double)
 Derived ( made up using the fundamental types, struct, class, array, enum)
o Data type modifiers
 Signed (allows both +ve and –ve values ), unsigned ( allows only +ve
values)
 short ( tends to decrease memory space ), long ( tends to increase memory
space )
o Typedefs – advantages
o Constants
 data items that do not change their values during the program run.
o Macros
 Preprocessor directive of the form #define name replacementtext that causes
name to be replaced by replacementtext wherever it occurs in code.
 2 types : Simple, Macros with arguments
 In case of macro with arguments need to be careful about putting brackets
around the argument as well as around the entire replacement text
……otherwise unintended grouping of arithmetic expressions can take
place.
o Variables
 Named memory locations whose contents can change during run time.
o Reference variables
 Variables that are another name for pre existing variables.
o Defining constants
 const keyword vs. #define
 const has associated data type and is processed by the compiler. Its
scope obeys usual scope rules for variables.
 #define has no associated data type, is processed by the pre
processor and scope lasts till the end of the file.
o Defining variables and initializing them
o Scope
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 51
 That part of the program in which a variable can be accessed.
o Lifetime
 The time between the creation of a variable and its destruction.
o Local and global variables
 Variables defined within braces i.e. { } in a C++ program are called local
variables. These variables are visible and can be accessed only by code
within the braces, not outside. Their lifetime is also within the braces in
which they lie.
 Global variables are defined outside of all functions, generally at the
beginning of the program. These are visible to all functions that follow their
definition and so can be accessed by all functions. Their lifetime is the entire
program run.
o Storage class
 Static
 A static local variable is one that is visible only in the function in
which it is defined but it's lifetime is the entire program run. This
means that such a variable retains it's value between function calls.
 Extern
 Used when a global variable defined in one file is to be accessed by
another file when a program spans multiple files. Using extern
ensures that no fresh memory is allocated for that variable.
 Auto
 Automatic storage class. Same as local variables.
 By default, all variables defined within a function are automatic
variables so this keyword is often not used.
 Auto variables are automatically created when the function in which
they are defined is executed and destroyed when the function returns.
They are visible only in the function in which they are defined.
These variables are not initialized by default.
 Register
 Same as auto variables with the exception that, if possible, these
variables are stored in the CPU registers and not in primary storage.
This means that access to these variables is faster.
 Functions:
o What?
 A named unit that groups together one or more C++ program statements.
This unit can then be invoked from other parts of the program.
o Why required?
 they make the program modular and better organized
 they promote code reusability and reduce program size.
o Function prototype
 Introduces a function to the compiler.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 52


The information that it gives to the compiler includes the function name, the
number, order and data types of the input parameters and the return data
type.
o Function definition
 The function definition contains the actual code of the function. It contains
the set of statements that show how the function accomplishes the task that
it represents.
o Function call.
 A function call or invocation is a statement that causes the function code to
be executed.
 The parameter names that are written in the function call are the actual
parameters. When a function actually works the input that it works with is
the actual parameter.
o Actual and formal parameters.
 The parameter name that is mentioned in the function header of the function
definition is called formal or dummy parameter name.
o Call by value vs. call by reference.
 In call by value, when arguments are passed to a function by value, the
function makes a local copy of the passed inputs. The function makes a copy
of the actual parameters in the formal/dummy parameters. It then works
with this local copy. Thus, if the function were to make changes in it's
formal parameters in it's body, those changes would not get reflected back in
the actual parameters.
 In call by reference the actual parameters become another name for the
dummy parameters. Thus, if the function makes changes in the dummy
parameters the changes get reflected back in the actual parameters.
o Default arguments.
 Function arguments which are provided default values in the function
prototype/header.
 Default arguments allow us to leave out arguments during a function call.
 Limitation is that they must always be trailing ones.
o Recursive functions
 A function that calls itself within its code.
o Inline functions
 Function whose code gets copied at the place of the function call.
o Returning by reference.
 When a function returns a reference to the variable location rather than the
value of the variable.
 Indicated using & with the return data type.
Derived data types:
o Arrays
 Single dimensional and two dimensional arrays
 Groups together elements that are of the same data type.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 53

Is a static data structure. Dimension of an array is a constant that cannot
be changed at runtime. This is a disadvantage as it may lead to overruns
and under runs.
 Searching – Linear and binary. Binary is more efficient on an average as it
eliminates half the elements in one comparison.
 Sorting –
 Insertion sort :
o Divides the array into 2 halves – the sorted part ( consisting
of the first element ) and the unsorted part.
o Then picks up one element from the beginning of the
unsorted part and inserts it in the sorted part in such a way
that the sorted part remains sorted.
o Continues till all elements of the unsorted part have been
inserted in the sorted part.
 Selection sort :
o Selects the smallest element and its position and swaps it
with the first element. This way the smallest element reaches
the beginning of the array.
o Repeats this process by changing the array beginning each
time. ( incrementing it by 1 )
 Bubble sort
o Compares adjacent elements and swaps them if they are not
in order. In this manner the largest element bubbles to the
end.
o Repeats this process by changing the array end each time. (
decrementing it by 1 )
 Merging of two sorted arrays
o Compares beginning elements of the two arrays and transfers
the smaller to the third array. Updates indices and repeats the
process.
o Structures
 What ?
 derived, user defined data type of C++.
 Usually combines together logically related data members that may
or may not be of the same data type..
 The only composite operation that is allowed on structures is that one
structure variable can be assigned to another, provided they are of the same
structure type.
 Self-referential structures
 When one of the members of a structure is a pointer to the same
structure type.
o Enumerated data types
 Represents a set of integer values that have associated names.
 Comparison with int
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 54
o Typedefs
 Used for giving an alias or a new name to an existing data type.
 required as they increase the readability of code, increase portability and can
also act as a short name for otherwise long declarations.
5.1.1.2 Sample Solved Question:
Pick out the keywords and user defined identifiers from the following list :
(i) delete
(ii) Long
(iii) 4Level (iv) _count
Ans.
(i) keyword (ii) Identifier (iii) None (iv) Identifier
2
( ½ X 4 = 2 marks for identifying correctly)
5.1.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Write the type of C++ Operators (Arithmetic, Logical, and relational Operators) from
thefollowing:
(i) !(ii) !=(iii) &&(iv) %
CBSE Sample Paper ( 2017-18)
What is the role of a parameter/argument passed in a function? Can a default value be
assigned to a parameter(Yes/No)? If yes, justify your answer with the help of a suitable
example otherwise give reason.
CBSE Sample Paper ( 2016-17)
Explain conditional operator with suitable example?
CBSE Sample Paper ( 2015-16)
Define Macro with suitable example.
CBSE Sample Paper ( 2014-15)
Differentiate between ordinary function and member functions in C++. Explain with an example.
CBSE Sample Paper ( 2013)
Write the prototype of a function named Percent, which takes an integer as value parameter
and return a float type value. The parameter should have a default value 10.
CBSE Sample Paper ( 2012)
Differentiate between the post increment and pre-increment operators. Also give a suitable C++
code to illustrate both.
5.1.1.4 Questions From Previous Year Board Papers:
CBSE Delhi – 2019
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 55
Write the names of any four fundamental data types of C++.
CBSE All India – 2018
Write the type of C++ tokens (keywords and user defined identifiers) from the following :
else
Long
4Queue
_count
CBSE All India – 2017
Write the type of C++ tokens (keywords and user defined identifiers)from the following :
(i) new
(ii) While
(iii) case
(iv) Num_2
CBSE Delhi – 2017
Write the type of C++ tokens (keywords and user defined identifiers) from thefollowing :
(i) For
(ii) delete
(iii) default
(iv) Value
CBSE All India– 2016
Out of the following , find those identifiers which cannot be used for naming Variables, Constants
or Functions in a C++ program.
Total*Tax, double, Case, My Name, NeW, switch, Column31, _Amount
CBSE Delhi – 2016
Out of the following find those identifiers which cannot be used for naming variable, constants or
functions in a C++ program: ( Delhi )
_Cost, Price*Quantity, float, Switch, Address One, Delete, Number12, do
CBSE All India - 2015
Find the correct identifiers out of the following, which can be used for naming Variable, Constants
or Functions in a C++ program:
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
CBSE Delhi - 2015
Find the correct identifiers out of the following, which can be used for naming variable, constants
or functions in a C++ program:
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
CBSE All India - 2014
What is the difference between call by reference and call by value with respect to memory
allocation ? Give a suitable example to illustrate using C++ code.
CBSE Delhi - 2014
What is the difference between actual parameters and formal parameters? Also give suitable C++
code to illustrate both.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 56
CBSE Compartment - 2014
Explain in brief the purpose of function prototype with the help of a suitable example.
CBSE All India - 2013
What is the benefit of using default parameter/argument in a function? Give a suitable example to
illustrate it using C++ code.
CBSE Delhi - 2013
What is the benefit of using function prototype for a function? Giive a suitable example to
illustrate it using C++ code.
CBSE Compartment - 2013
What is the difference between type casting and automatic type conversion? Explain with suitable
example.
CBSE All India - 2012
What is the difference between type casting and automatic type conversion? Explain with suitable
example.
CBSE Delhi - 2012
What is the difference between actual parameter and formal parameter? Give an example in C++ to
illustrate both types of parameters.
CBSE Compartment - 2012
Define a macro. Give examples illustrating the use.
CBSE All India - 2011
What is the difference between type casting and automatic type conversion? Explain with suitable
example.
CBSE Compartment - 2011
What is the purpose of using a typedef command in C++. Explain with a suitable example.
CBSE All India - 2010
Differentiate between call by value and call by reference giving suitable examples of each.
CBSE Delhi - 2010
What is the difference between type casting and automatic type conversion? Explain with suitable
example.
CBSE All India - 2009
What is the difference between actual parameter and formal parameter? Give an example in C++ to
illustrate both types of parameters.
CBSE Delhi - 2009
Differentiate between call by value and call by reference giving suitable examples of each.
CBSE Compartment - 2009
What is the function of #define keyword? Give an example to illustrate its use.
CBSE All India - 2008
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 57
What is the purpose of using a typedef command in C++. Explain with a suitable example.
CBSE Delhi - 2008
What is the difference between a #define and a constant? Explain with a suitable example.
CBSE Compartment - 2008
What is the difference between type casting and automatic type conversion? Explain with suitable
example.
CBSE All India - 2007
Differentiate between a logical error and a syntax error. Also give suitable examples of each in
C++.
CBSE Delhi - 2007
Differentiate between a logical error and a syntax error. Also give suitable examples of each in
C++.
CBSE All India - 2006
Illustrate the use of an inline function in C++ with the help of an example.
CBSE Delhi - 2006
Illustrate the use of a #define in C++. Give examples illustrating the use.
CBSE Compartment - 2006
What is the difference between Local variable and Global variable? Also give a suitable C++ code
to illustrate the same.
CBSE All India - 2005
Differentiate between call by value and call by reference giving suitable examples of each.
5.1.1.5 Important Tips:


Please include all relevant points in your answer.
Whenever the question asks you to explain using an example give a C++ code example.
5.1.2 QUESTION 1 (b) Identification of Header Files ( 1 Mark )
5.1.2.1 Revision Notes
Header File
Functions/Variables
conio.h
clrscr(), getch(), getche(), putch()
iostream.h
cin, cout, getline(), write(), endl
stdio.h
getchar(), putchar(), getc(), putc(), gets(), puts(), printf(), scanf(),
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 58
fflush(), remove(),rename()
iomanip.h
setw()
ctype.h
isupper(), islower(), isalpha(), isalnum(), isdigit(), isspace(), toupper(),
tolower()
string.h
strlen(), strcpy(), strcmp(), strcmpi(), strrev(), strcat(), strupr(), strlwr()
math.h
pow(), sqrt(), sin(), cos(), tan(), abs(), fabs(), floor(), ceil(), log(), log10(),
exp(), frexp(), modf(), atof()
stdlib.h
randomize(), random(), atoi(), atol(), atof(), itoa(), ltoa()
process.h
exit()
fstream.h
open(), close(), read(), write(), tellg(), tellp(), seekg(), seekp()
5.1.2.2 Sample Solved Questions:
Write the names of all the header files, which are necessary to run the following program
code:
1
void main()
{
float A,Number,Outcome;
cin>>A>>Number;
Outcome=pow(A,Number);
cout<<Outcome<<endl;
}
Ans.
(i) iostream.h
(ii) math.h
(½ X 2 = 1 mark for identifying correctly)
5.1.2.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 59
Observe the following program very carefully and write the name of those header file(s), which
are essentially needed to compile and execute thefollowing program successfully:
void main()
{
char text[20], newText[20];
gets(text);
strcpy(newText,text);
for(inti=0;i<strlen(text);i++)
if(text[i] = =’A’)
text[i] = text[i]+2;
puts(text);
}
CBSE Sample Paper ( 2017-18)
Raman suggests Kishan the following header files which are required to be
included in the given C++ program. Identify the header files which are
wrongly suggested by Raman.
Program:
Suggested header files:1. iostream.h
2. stdio.h
3. conio.h
4. ctype.h
CBSE Sample Paper ( 2016-17)
Which C++ header file(s) are essentially required to be included torun/execute the following C++
code :
void main()
{
char *word1="Hello",*word2="Friends";
strcat(word1,word2);
cout<<word1;
}
CBSE Sample Paper ( 2015-16)
Which C++ header file (s) will be included to run /execute the following C++ code?
void main( )
{ int Last =26.5698742658;
cout<<setw(5)<<setprecision(9)<<Last; }
CBSE Sample Paper ( 2014-15)
Write the related library function name based upon the given information in C++.
(i) Get single character using keyboard. This function is available in stdio.h file.
(ii) To check whether given character is alpha numeric character or not. This function is available
in ctype.h file.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 60
CBSE Sample Paper ( 2013)
Write the names of header files, which are NOT necessary to run the following program:
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
void main()
{
char STR[80];
gets(STR);
puts(strrev(STR));
}
CBSE Sample Paper ( 2012)
Which C++ header file(s) are essentially required to be included torun/execute the following C++
code :
void main()
{
int Last = 25;
for ( int C= 9; C <= Last ; C++ )
{
cout<< C << “ : “ <<sqrt(C) <<endl;
}
}
5.1.2.4 Questions From Previous Year Board Papers:
CBSE All India – 2017
Anil typed the following C++ code and during compilation he foundthree errors as follows :
(i) Function strlen should have prototype
(ii) Undefined symbol cout
(iii) Undefined symbol endl
On asking, his teacher told him to include necessary header files inthe code. Write the names of the
header files, which Anil needs toinclude, for successful compilation and execution of the
followingcode :
void main()
{
char Txt[] = "Welcome";
for(int C= 0; C<strlen(Txt); C++)
Txt[C] = Txt[C]+1;
cout<<Txt<<endl;
}
CBSE Delhi – 2017
Anil typed the following C++ code and during compilation he found four errors asfollows :
(i) Function strlen should have a prototype
(ii) Undefined symbol cout
(iii) Undefined symbol endl
(iv) Functiongetchar should have a prototype
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 61
On asking his teacher told him to include necessary header files in the code. Writethe names of the
header files, which Anil needs to include, for successfulcompilation and execution of the following
code :
void main()
{
char S[] = "Hello";
for(inti = 0; i<strlen(S); i++)
S[i] = S[i]+1;
cout<<S<<end1;
getchar();
}
CBSE Compartment – 2017
Jayneel has just started learning C++. He typed the following C++ code and duringthe compilation
of the code, he got some errors. When Jayneel asked his teacher,the teacher told him to include
necessary header files in the code.Write the names of those header files, which Jayneel needs to
include, forsuccessful compilation and execution of the following code.
void main()
{
cout<<"We win !"<<endl;
cout<<strlen("The World")<<endl ;
}
CBSE All India – 2016
Ronica Jose has started learning C++ and has typed the following program. When she compiled
the following code written by her, she discovered that she needs to include some header files to
successfully compile and execute it. Write the names of those header files which are required to be
include in the code.
CBSE Delhi – 2016
Jayapriya has started learning C++ and has typed the following program. When she
compiled the following code written by her, she discovered that she needs to
include some header files to successfully compile and execute it. Write the names
of those header files, which are required to be included in the code.
void main()
{
floatA,Number,Outcome;
cin>>A>>Number;
Outcome=pow(A,Number);
cout<<Outcome<<endl;
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 62
CBSE All India – 2015
Observe the following program very carefully and write the names of those header file(s), which
are essentially needed to compile and execute the following program successfully :1
typedef char STRING[80];
void main()
{
STRING Txt[] = “We love Peace”;
int Count=0;
while (Txt[Count]!=’\0’)
if (isalpha(Txt[Count]))
Txt[Count++]=’@’;
else
Txt[Count++]=’#’;
puts(Txt);
}
CBSE Delhi – 2015
Observe the following program very carefully and write the names of those headerfile(s), which
are essentially needed to compile and execute the following programsuccessfully :
typedef char TEXT[80];
void main()
{
TEXT Str[] = “Peace is supreme”;
int Index=0;
while (Str[Index]!=’\0’)
if (isupper(Str[Index]))
Str[Index++]=’#’;
else
Str[Index++]=’*’;
puts(Str);
}
CBSE Delhi – 2014
Observe the following C++ code and write the name(s) of the header fiIe(s) which will be
essentially required to run it in a C++ compiler :
void main ( )
{
char Text, [20] , C;
cin>>Text;
C=tolower (Text [0] ) ;
cout<<C<<" is the first char of " <<Text<<end1;
}
CBSE All India – 2013
Observe the following C++ code and write the name(s) of the header fiIe(s) which will be
essentially required to run it in a C++ compiler:
void main ( )
{
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 63
int number;
cin>>number;
if ( abs(number) == number )
cout<< “positive” <<endl;
}
CBSE Compartment – 2013
Observe the following C++ code and write the name(s) of the header fiIe(s) which will be
essentially required to run it in a C++ compiler :
void main ( )
{
charA = ‘K’, B;
if ( islower(A) )
B = toupper(A);
else
B = ‘*’;
cout<< A << “turned to” << B <<endl
}
5.1.2.5 Important Tips:


Please do not mention extra header file names. List only the ones required for the given
code segment.
Read the question carefully. Sometimes it asks you to list out header files that are NOT
required.
5.1.3 QUESTION 1 (c) Identifying Syntax Errors ( 2 Marks )
5.1.3.1 Revision Notes
Following is a list of common error types that you should look for.
1. Missing header file or incorrect use of #include
E.g. include <conio.h> instead of #include <conio.h>
2. Incorrect use of a typedef
E.g. to define a typedef for an array of 10 characters
typedef
char[10]
String
// incorrect
instead of
typedef
char String[10];
//correct
Then to use the above typedef
mystring
String;
// incorrect
instead of
String mystring;
// correct
3. Incorrect use of a macro.
E.g. defining a macro like this
#define
PI
=
Instead of
Ownership
Integrity
3.14 ; // incorrect
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 64
#define
PI
3.14
// correct
4. Incorrect input or output from variables:
Incorrect use of << or >> with cin or cout. ( cin<<x; instead of cin>>x; )
Using gets with a char variable.
Use of endline instead of endl. ( cout << x << endline; )
5. Incorrect control structure syntax :
Missing brackets around the condition of if/while.
Use of , instead of ; in a for loop.
; missing at the end of a do while loop.
6. Missing braces around the statements in the body of an if else.
E.g. if ( x > 20 )
y = y + 5;
z = z + 2;
else
t = t – 3;
7. Incorrect use of “ “ or ‘ ‘.
E.g. cout << ‘Hello’; instead of cout << “Hello”;
8. Missing ; at end of the statement.
E.g. cout<<x<<y
instead of
cout << x << y;
9. Incorrect variable declaration statement.
E.g.
Int x,y;
instead of
int x,y;
E.g. int x ; y ;
instead of
int x , y ;
10. Assigning values to data members inside a structure/class definition.
E.g. struct student
{
char name[10] = “Nalini”;
int
marks;
};
9. Undeclared variable name.
10. Unmatched parenthesis.
11. Left hand side of assignment does not represent an l-value.
E.g. x + y = z;
12. Function with a return data type defined not returning a value or a void function
returning a value.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 65
13. The question may also ask you to check for logical errors in a program segment.
E..g. if ( A[i] < max )
instead of
if ( A[i] > max )
while determining the highest in an array.
5.1.3.2 Sample Solved Questions:
Rewrite the following program after removing the syntactical errors (is any). Underline each
correction. Assume all required header files are included.
2
#define 10*Number MAX(Number)
void main()
{
int Num,NewNum;
cout<<"Number:";
cin<<Num;
if Num<10
NewNum=MAX(Num);
else
NewNum=Num-2;
cout<<"New Number:"<<NewNum<<end;
}
Ans.
#define MAX(Number) 10*Number
void main()
{
int Num,NewNum;
cout<<"Number:";
cin>>Num;
if ( Num<10 )
NewNum=MAX(Num);
else
NewNum=Num-2;
cout<<"New Number:"<<NewNum<<endl;
}
( ½ X 4 = 2 marks for identifying and correcting)
5.1.3.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Rewrite the following C++ code after removing any/all Syntactical Error(s) with each correction
underlined.
Note: Assume all required header files are already being included in the
program.
#define float PI 3.14
void main( )
{
float R=4.5,H=1.5;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 66
A=2*PI*R*H + 2*PIpow(R,2);
cout<<‘Area=’<<A<<endl;
}
CBSE Sample Paper ( 2017-18)
Rewrite the following program after removing the syntactical errors (is any).
Underline each correction.
CBSE Sample Paper ( 2016-17)
Rewrite the following program after removing the syntactical errors(if any). Underline each
correction.
#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdio.h>
class product
{
intproduct_code,qty,price;
char name[20];
public:
product(){
product_code=0;qty=0;price=0;
name=NULL;
}
void entry()
{
cout<<"\n Enter code,qty,price";
cin>>product_code>>qty>>price;
gets(name);
}
voidtot_price() {return qty*price;}
};
void main()
{
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 67
p product;
p.entry();
cout<<tot_price();
}
CBSE Sample Paper ( 2015-16)
Rewrite the following program after removing any syntactical errors. Underline each
correction made. 2
#include<iostream.h>
void main( )
int A[10];
A=[3,2,5,4,7,9,10];
for( p = 0; p<=6; p++)
{ if(A[p]%2=0)
int S = S+A[p];
}
cout<<S;
}
CBSE Sample Paper ( 2014-15)
Rewrite the following C++ program after removing all the syntactical errors (if
any), underlining each correction. :
include<iostream.h>
#define PI=3.14
void main( )
{
floatr;a;
cout<<’enter any radius’;
cin>>r;
a=PI*pow(r,2);
cout<<”Area=”<<a
}
CBSE Sample Paper ( 2013)
Tarunaj has just started working as programmer in the JAGAT WORLD SOFTWARE company.
In the company, he has got his first assignment to develop a small C++ module to find the
biggest number out of a given set of numbers stored in a one dimensional array. Somehow he has
committed a few logical mistakes while writing this code and so he is not getting the desired
result from the code. Find out the mistakes and correct this C++ code so that it provides the
desired result (do not add any new statement in the code). Underline each correction made:
int BIGFIND(int ARR[],int Size)
{
int BIG=ARR[1]; //Statement 1
for (int C=2;C<Size;C++) //Statement 2
if (ARR[C]<BIG) //Statement 3
ARR[C]=BIG; //Statement 4
return BIG; //Statement 5
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 68
5.1.3.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Rewrite
the
following
C++ program
after removing
syntactical error(s). Underline each correction done in the code :
2
Note : Assume all required header files are already included in the program.
#define Area(L,B) = L*B
structure Recta
{
int Length,Breadth;
};
void main()
{
Recta R = [10,15];
cout<<Area(Length.R,Breadth.R);
}
any/all
CBSE All India – 2018
Rewrite the following C++ code after removing any/all syntactical errors with each
correction underlined.
Note : Assume all required header files are already included in the program.
Typedef Count int; void
2
main()
{
Count C;
cout<<"Enter the count:";
cin>>C;
for (K = 1; K<=C; K++)
cout<< C "*" K <<endl;
}
CBSE All India – 2017
Rewrite the following C++ code after removing any/all syntacticalerrors with each correction
underlined.
Note :Assume all required header files are already being included in
the program.
void main()
{
cout<<"Enter an Alphabet:";
cin>>CH;
switch(CH)
case „A‟ cout<<"Ant"; Break;
case „B‟ cout<<"Bear" ; Break;
}
CBSE Delhi – 2017
Rewrite the following C++ code after removing any/all syntactical errors with each
correction underlined.
Note :Assume all required header files are already being included in the program.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 69
void main()
{
cout<<"Enter an integer”;
cin>>N;
switch(N%2)
case 0 cout<<"Even"; Break;
case 1 cout<<"Odd"; Break;
}
CBSE Compartment – 2017
Rewrite the following C++ code after removing any/all syntactical errors with each
correction underlined.
Note :Assume all header files required in the code are already being included.
#define 10*Number MAX(Number)
void main()
{
intNum,NewNum;
cout<<"Number:";
cin<<Num;
if Num<10
NewNum=MAX(Num);
else
NewNum=Num-2;
cout<<"New Number:"<<NewNum<<end;
}
CBSE All India – 2016
Rewrite the following C++ code after removing any/all syntactical errors with eachcorrection
underlined.
Note: Assume all required header files are already being included in the program.
#define Formula(a,b) = 2*a+b
void main()
{
float X=3.2;Y=4.1;
Z=Formula(X,Y);
cout<<’Result=’<<Z<<endl;
}
CBSE Delhi – 2016
Rewrite the following C++ code after removing any/all syntactical errors with eachcorrection
underlined.
Note : Assume all required header files are already being included in the program.
#define Equation(p,q)=p+2*q
void main()
{
float A=3.2;B=4.1;
C=Equation(A,B);
cout<<’Output=’<<C<<endl;
}
CBSE All India – 2015
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 70
Observe the following C++ code very carefully and rewrite itafter removing any/all syntactical
errors with each correctionunderlined.
Note: Assume all required header files are already being includedin the program.
#Define float MaxSpeed=60.5;
void main()
{
intMySpeed
char Alert='N' ;
cin»MySpeed;
ifMySpeed>MaxSpeed
Alert='Y' ;
cout<<Alert<<endline;
}
CBSE Delhi – 2015
Observe the following C++ code very carefully and rewrite it after removingany/all syntactical
errors with each correction underlined. Assume all required header files are already included.
#Define float Max=70.0;
Void main()
{
int Speed
char Stop=’N’;
cin>>Speed;
if Speed>Max
Stop=’Y’;
cout<<Stop<<end;
}
CBSE Delhi – 2014
Rewrite the following C++ code after removing all the syntax error(s) if presentin the code. Make
sure that you underline each correction done by you in thecode.
Important Note :
- Assume that all the required header files are already included, which areessential to run this code.
- The corrections made by you do not change the logic ofthe program.
typedef char [50] STRTNG;
void main ( )
{
City STRING;
gets (City) ;
cout<<City [0] << ‘ \t <<Cit.y [2] ;
cout<<City<<endline;
)
5.1.3.5 Important Tips:



Please do not only mention the errors. Rewrite the entire code after making corrections if
the question is asking you to do so.
Do not forget to underline all the corrections made.
Do not change the logic of the original code in case the question is only asking you to
correct syntax errors.
5.1.4 QUESTION 1 (d), (e) Predicting Output ( 3+2=5 Marks )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 71
5.1.4.1 Revision Notes
Practice Output Questions:
1. Based on passing parameters to functions ( call by value and call by reference)
2. Based on scope of variables : local and global variables being passed as parameters.
3. Based on increment and decrement operators.
4. Based on traversal of 1D arrays.
5. Based on traversal of strings and use of ctype.h functions.
6. Based on structures.
7. Based on pointers.
8. Based on classes e.g. constructor overloading
5.1.4.2 Sample Solved Questions:
Find and write the output of the following C++ program code :
Note : Assume all required header files are already included in the program.
void Convert(float &X, int Y=2)
{
X=X/Y;
Y=X+Y;
cout<<X<<"*"<<Y<<endl;
}
void main()
{
float M=15, N=5;
Convert(M,N);
Convert(N);
Convert(M);
}
Ans.
3*8
2.5*4
1.5*3
3
(1 mark for each correct line of output)
5.1.4.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 72
Find and write the output of the following C++ program code: Note: Assume all required
header files are already being included in the program.
void main( )
{
intAr[ ] = { 6 , 3 , 8 , 10 , 4 , 6 , 7} ;
int *Ptr = Ar , I ;
cout<<++*Ptr++ << '@' ;
I = Ar[3] - Ar[2] ;
cout<<++*(Ptr+I)<<'@'<<"\n" ;
cout<<++I + *Ptr++ << '@' ;
cout<<*Ptr++ <<'@'<< '\n' ;
for( ; I >=0 ; I -=2)
cout<<Ar[I] << '@' ;
}
Find and write the output of the following C++ program code:
typedef char STRING[80];
void MIXNOW(STRING S)
{
int Size=strlen(S);
for(int I=0;I<Size;I+=2)
{
char WS=S[I];
S[I]=S[I+1];
S[I+1]=WS;
}
for (I=1;I<Size;I+=2)
if (S[I]>=’M’ && S[I]<=’U’)
S[I]=’@’;
}
void main()
{
STRING Word=”CBSEEXAM2019”;
MIXNOW(Word);
cout<<Word<<endl;
}
CBSE Sample Paper ( 2017-18)
Write the output of the following C++ program code(assume all necessary header files
are included in program):
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 73
Write the output of the following C++ program code(assume all necessary header files
are included in program):
CBSE Sample Paper ( 2016-17)
Write the output of the following C++ program code:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 74
Note: Assume all required header files are already being included inthe program.
void change(int *s)
{
for(inti=0;i<4;i++)
{
if(*s<40)
{
if(*s%2==0)
*s=*s+10;
else
*s=*s+11;
}
else
{
if(*s%2==0)
*s=*s-10;
else
*s=*s-11;
}
cout<<*s<<" ";
s++;
}
}
void main()
{
int score[]={25,60,35,53};
change(score);
}
Write the output of the following C++ program code:
Note: Assume all required header files are already being included inthe program.
class seminar
{
char topic[30];
int charges;
public:
seminar()
{
strcpy(topic,"Registration");
charges=5000;
}
seminar(char t[])
{
strcpy(topic,t);
charges=5000;
}
seminar(int c)
{
strcpy(topic,"Registration with Discount");
charges=5000-c;
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 75
voidregis(char t[],int c)
{
strcpy(topic,t);
charges=charges+c;
}
voidregis(int c=2000)
{
charges=charges+c;
}
void subject(char t[],int c)
{
strcpy(topic,t);
charges=charges+c;
}
void show()
{
cout<<topic<<"@"<<charges<<endl;
}
};
void main()
{
seminar s1,s2(1000),s3("Genetic Mutation"),s4;
s1.show();
s2.show();
s1.subject("ICT",2000);
s1.show();
s2.regis("Cyber Crime",2500);
s2.show();
s3.regis();
s3.show();
s4=s2;
s4.show();
getch();
}
CBSE Sample Paper ( 2015-16)
Find the output of the following C++ program:
#include<iostream.h>
voidrepch(char s[])
{
for (inti=0;s[i]!='\0';i++)
{
if(((i%2)!=0) &&(s[i]!=s[i+1]))
{
s[i]='@';
}
else if (s[i]==s[i+1])
{
s[i+1]='!';
i++;
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 76
}
}
void main()
{
charstr[]="SUCCESS";
cout<<”Original String”<<str
repch(str);
cout<<"Changed String"<<str;
}
Find the output of the following :
#include<iostream.h>
void switchover(int A[ ],int N, int split)
{
for(int K = 0; K<N; K++)
if(K<split)
A[K] += K;
else
A[K]*= K;
}
void display(int A[ ] ,int N)
{
for(int K = 0; K<N; K++)
(K%2== 0) ?cout<<A[K]<<"%" : cout<<A[K]<<endl;
}
void main( )
{
int H[ ] = {30,40,50,20,10,5};
switchover(H,6,3);
display(H,6);
}
CBSE Sample Paper ( 2014-15)
Write the output from the following C++ program code:
#include<iostream.h>
#include<ctype.h>
voidstrcon(char s[])
{
for(inti=0,l=0;s[i]!='\0';i++,l++);
for(int j=0; j<l; j++)
{
if (isupper(s[j]))
s[j]=tolower(s[j])+2;
else if ( islower(s[j]))
s[j]=toupper(s[j])-2;
else
s[j]='@';
}
}
void main()
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 77
{
char *c="Romeo Joliet";
strcon(c);
cout<<"Text= "<<c<<endl;
c=c+3;
cout<<"New Text= "<<c<<endl;
c=c+5-2;
cout<<"last Text= "<<c
}
Find the output of the following C++ program:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
classClass
{
intCno,total;
char section;
public:
Class(int no=1)
{
Cno=no;
section='A';
total=30;
}
voidaddmission(int c=20)
{
section++;
total+=c;
}
voidClassShow()
{
cout<<Cno<<":"<<section<<":"<<total<<endl;
}
};
void main()
{
Class C1(5),C2;
C1.addmission(25);
C1.ClassShow();
C2.addmission();
C1.addmission(30);
C2.ClassShow();
C1.ClassShow();
}
CBSE Sample Paper ( 2013)
Find output of the following program segment:
int A[][3] = {{1,2,3}, {5,6,7}};
for (inti = 1; i<2; i++)
for (int j = 0; j<3; j++)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 78
cout<<A[i][j]<<"*\n";
Find output of the following program segment:
int a = 3;
void demo(int x, int y, int&z)
{ a += x+y;
z = a+y;
y += x;
cout<<x<<'*'<<y<<'*'<<z<<endl;
}
void main()
{ int a = 2, b = 5;
demo(::a,a,b);
demo(::a,a,b);
}
5.1.4.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Find and write the output of the following C++ program code :
Note : Assume all required header files are already included in the program.
void Alter(char *S1, char *S2)
{
char
*T;
T=S1;
S1=S2
;
S2=T;
cout<<S1<<"&"<<S2<<end1;
}
void main()
{
char X[]="First", Y[]="Second";
Alter(X,Y);
cout<<X<<"*"<<Y<<end1;
}
2
CBSE All India – 2018
Find and write the output of the following C++ program code :
Note : Assume all required header files are already included in the program.
void Revert(int &Num, int Last=2)
{
Last=(Last%2==0)?Last+1:Last-1;
for(int C=1; C<=Last; C++)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 79
Num+=C;
}
void main()
{
int A=20,B=4;
Revert(A,B);
cout<<A<<"&"<<B<<endl;
B--;
Revert(A,B);
cout<<A<<"#"<<B<<endl;
Revert(B);
cout<<A<<"#"<<B<<endl;
}
CBSE All India – 2017
Find and write the output of the following C++ program code :2
Note :Assume all required header files are already included in the
program.
#define Diff(N1,N2) ((N1>N2)?N1-N2:N2-N1)
void main()
{
int A,B,NUM[] = {10,23,14,54,32};
for(int CNT =4; CNT>0; CNT--)
{
A=NUM[CNT];
B=NUM[CNT-1];
cout<<Diff(A,B)<<'#';
}
}
Find and write the output of the following C++ program code :
Note :Assume all required header files are already being included inthe program.
void main()
{
int *Point, Score[]={100,95,150,75,65,120};
Point = Score;
for(int L = 0; L<6; L++)
{
if((*Point)%10==0)
*Point /= 2;
else
*Point -= 2;
if((*Point)%5==0)
*Point /= 5;
Point++;
}
for(int L = 5; L>=0; L--)
cout<<Score[L]<<"*";
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 80
}
CBSE Delhi – 2017
Find and write the output of the following C++ program code :
Note : Assume all required header files are already included in the program.
#define Big(A,B) (A>B)?A+1:B+2
void main()
{
char W[] = "Exam";
int L=strlen(W);
for(inti=0; i<L–1; i++)
W[i] = Big(W[i],W[i+1]);
cout<<W<<end1;
}
Find and write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
void main()
{
int A[]={10,12,15,17,20,30};
for(inti = 0; i<6; i++)
{
if(A[i]%2==0)
A[i] /= 2;
else if(A[i]%3==0)
A[i] /= 3;
if(A[i]%5==0)
A[i] /=5;
}
for(i = 0; i<6; i++)
cout<<A[i]<<”#”;
}
CBSE Compartment – 2017
Find and write the output of the following C++ program code :
Note : Assume all required header files are already included in the program.
void Decider(int&K,int L=70)
{
if (K>L)
K-=L;
else
K+=L;
}
void main()
{
int M=100,N=40;
Decider(M,N);
cout<<M<<"#"<<N<<endl;
Decider(M);
cout<<N<<"#"<<M<<endl;
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 81
Find and write the output of the following C++ program code :
Note : Assume all required header files are already being included in the program.
voidDispScore(int S[],int N)
{
for(int Count = 0;Count<N;Count++)
cout<<S[Count]<<"#";
cout<<endl;
}
void main()
{
int *Point,Score[]={10,5,20,15};
Point=Score;
DispScore(Score,2);
for(int Count=0; Count<4; Count++)
{
cout<<*Point<<":";
if(Count%2==0)
Point++;
else
{
*Point +=10;
Point++;
}
}
cout<<endl;
DispScore(Score,4);
}
CBSE All India – 2016
Find and write the output of the following C++ program code:
Note: Assume all required header files are already included in the program.
typedef char TEXT[80];
voidJumbleUp(TEXT T)
{
int L=strlen(T);
for (int C=0;C<L1;C+=2)
{
char CT=T[C];
T[C]=T[C+1];
T[C+1]=CT;
}
for (C=1;C<L;C+=2)
if (T[C]>=’M’ && T[C]<=’U’)
T[C]=’@’;
}
void main()
{
TEXT Str=”HARMONIOUS”;
JumbleUp(Str);
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 82
cout<<Str<<endl;
}
Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.
class Share
{
longint Code;
float Rate;
int DD;
public:
Share(){Code=1000;Rate=100;DD=1;}
voidGetCode(long intC,float R)
{
Code=C;
Rate=R;
}
void Update(intChange,int D)
{
Rate+=Change;
DD=D;
}
void Status()
{
cout<<”Date:”<<DD<<endl;
cout<<Code<<”#”<<Rate<<endl;
}
};
void main()
{
Share S,T,U;
S.GetCode(1324,350);
T.GetCode(1435,250);
S.Update(50,28);
U.Update(25,26);
S.Status();
T.Status();
U.Status();
}
CBSE Delhi – 2016
Find and write the output of the following C++ program code:
Note: Assume all required header files are already included in theprogram.
typedef char STRING[80];
void MIXITNOW(STRING S)
{
int Size=strlen(S);
for (int I=0;I<Size1;I+=2)
{
char WS=S[I];
S[I]=S[I+1];
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 83
S[I+1]=WS;
}
for (I=1;I<Size;I+=2)
if (S[I]>=’M’ && S[I]<=’U’)
S[I]=’@’;
}
void main()
{
STRING Word=”CRACKAJACK”;
MIXITNOW(Word);
cout<<Word<<endl;
}
Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.
class Stock
{
longint ID;
float Rate; int Date;
public:
Stock(){ID=1001;Rate=200;Date=1;}
voidRegCode(long intI,float R)
{
ID=I; Rate=R;
}
void Change(intNew,int DT)
{
Rate+=New; Date=DT;
}
void Show()
{
cout<<”Date :”<<Date<<endl;
cout<<ID<<”#”<<Rate<<endl;
}
};
void main()
{
Stock A,B,C;
A.RegCode(1024,150);
B.RegCode(2015,300);
B.Change(100,29);
C.Change(20,20);
A.Show();
B.Show();
C.Show();
}
CBSE All India – 2015
Write the output of the following C++ program code:
Note: Assume all required header files are already being
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 84
included in the program.
void Location(int&X,int Y=4)
{
Y+=2;
X+=Y;
}
void main()
{
int PX=l0,PY=2;
Location(PY) ;
cout<<PX<<" , "<<PY<<endl ;
Location(PX,PY);
cout<<PX<<" , "<<PY<<endl ;
}
Write the output of the following C++ program code:
Note: Assume all required header files are already being includedin the program.
classEval
{
char Level;
int Point;
public:
Eval() {Level='E';Point=0;}
void Sink(int L)
{
Level=L;
}
void Float(int L)
{
Level += L;
Point++;
}
void Show()
{
cout<<Level<<"#"<<Point<<endl;
}
};
void main()
{
Eval E;
E.Sink(3);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
CBSE Delhi – 2015
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 85
void Position (int&C1, int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<”,”<<P2<<endl;
Position(P2,P1);
cout<<P1<<”,”<<P2<<endl;
}
Write the output of the following C++ program code:
Note: Assume all the required header files are already beingincluded in the program.
class Calc
{
char Grade;
int Bonus;
public:
Calc(){Grade=’E’ ; Bonus=0;}
void Down(int G)
{
Grade=G;
}
void Up(int G)
{
Grade+=G;
Bonus++;
}
void Show()
{
cout<<Grade<<”#”<<Bonus<<end1;
}
};
void main()
{
Calc c;
C.Down(2);
C.Show();
C.Up(7);
C.Show();
C.Down(2)
C.Show();
}
CBSE Delhi – 2014
Obtain the output from the following c++ program as expected to appear on thescreen after its
execution.
ImportantNote :
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 86
- All the desired header files are already included in the code, which arerequired to run the code.
void main ( )
{
char*String= “SARGAM” ;
inr. *Ptr, A[]= {1,5,7,9 } ;
Ptr=A;
cout<< * ptrs<<String<<end1 ;
String++;
Ptr+=3;
cout<< * Ptr<< String<<endI ,
}
Obtain the output of the following C++ program, which will appear on thescreen after its
execution.
Important Note :
 Al1 the desired header files are already included in the code, which are required to run the
code.
class Player
{
int Score, Level ;
char Game;
public :
Player (char Gcame='A' )
{score=0; Level=1; Game=GGame; }
void Start (int SC) ;
voidNext();
voidDisp()
{
cout<<Game<< " @" <<Leve1<<end1;
cout<<Score<<endI ;
}
);
void main ( )
{
Player P,Q ('B') ;
P.DispO;
Q. Start (75) ;
Q. uexr();
P. Start (120) ,
Q.DispO;
P.DispO;
}
voidPlayer::Next()
{
Game = ( Game == ‘A’ ? ‘B’ : ‘A’;
}
voidPlayer:::Start (int SC)
{
Score+=SC;
if(Score >= 100 )
Level=3;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 87
else if (Score>=50 )
Level=2;
else
Level=1;
}
CBSE All India – 2013
Find the output of the following program. Assume all required header files are already
being included in the program.
int main()
{
char *String = "SHAKTI";
int *Point, Value[] = {10,15,70,19};
Point = Value;
cout<< *Point << String <<endl;
String++;
Point++;
cout<< *Point << String <<endl;
}
Observe the following C++ code carefully and obtain the output, which will appear on the
screen after execution of it. Assume all required header files are already being included in
the program.
classAroundus
{
int Place, Humidity, Temp;
public:
Aroundus(int P = 2)
{
Place = P;
Humidity = 60;
Temp = 20;
}
void Hot (int T)
{
Temp += T;
}
void Humid(int H)
{
Humidity += H;
}
voidJustSee()
{
cout<< Place << ":" << Temp << "&" << Humidity << "%" <<endl;
}
};
int main()
{
Aroundus A, B(5);
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 88
A.Hot(10);
A.JustSee();
B.Humid(15);
B.Hot(2);
B.JustSee();
A.Humid(5);
A.JustSee();
}
5.1.4.5 Important Tips:



Carry out a code walkthrough while solving output prediction questions.
Draw diagrams to illustrate changes in variable contents as you do your walkthrough.
Do not attempt to solve questions mentally.
5.1.5 QUESTION 1 (f) Predicting Output based on random (2 Marks )
5.1.5.1 Revision Notes
•
Remember that randomize() is used to initialize the random number generator and
random(n) returns a number in the range 0 to n-1.
•
Header file stdlib.h must be included to use random() and randomize().
5.1.5.2 Sample Solved Questions:
Observe the following C++ code and find the possible output(s) from the options (i) to (iv)
following it. Also, write the minimum and maximum values that can possibly be assigned
to the variable End .
2
Note:
 Assume all the required header files are already being included in the code.
 The function random(N) generates any possible integer between 0 and N-1
(both values included)
void main()
{
randomize();
int A[]={10,20,30,40,50,60,70,80};
int Start = random(2) + 1;
int End = Start + random(4);
for(int I=Start; I<=End ; I++)
cout<<A[I]<<"$";
}
(i) 10$20$30$
(ii) 20$30$40$50$60$
(iii) 30$40$50$60$
(iv) 40$50$60$70$
Ans.
(iii) 30$40$50$60$
( 1 mark for the correct answer )
Minimum value = 1
Maximum value = 5
( ½ X 2 = 1 mark for the correct answers)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 89
5.1.5.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Observe the following program and find out, which output(s) out of (i) to (iv) willbe expected
from the program? What will be the minimum and the maximum value assigned to the variable
Alter?
Note: Assume all required header files are already being included in the program.
void main( )
{
randomize();
intAr[]={10,7}, N;
int Alter=random(2) + 10 ;
for (int C=0;C<2;C++)
{
N=random(2) ;
cout<<Ar[N] +Alter<<”#”;
}
}
(i) 21#20# (ii) 20#18#
(iii) 20#17# (iv) 21#17#
CBSE Sample Paper ( 2017-18)
Consider the following C++ program code and choose the option(s) which are not
possible as output. Also, print the minimum &maximum value of variable Pick during
complete execution of the program.(assume all necessary header files are included in
program):
(a) 5:6:6:6:
(b) 4:7:5:3:
(c) 8:6:1:2:
(d) 7:5:3:1
CBSE Sample Paper ( 2016-17)
Observe the following program carefully and attempt the givenquestions:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 90
{
clrscr();
randomize();
char courses[][10]={"M.Tech","MCA","MBA","B.Tech"};
intch;
for(inti=1;i<=3;i++)
{
ch=random(i)+1;
cout<<courses[ch]<<"\t";
}
getch();
}
I. Out of all the four courses stored in the variable courses, whichcourse will never be displayed in
the output and which course willalways be displayed at first in the output?
II. Mention the minimum and the maximum value assigned to thevariable ch?
CBSE Sample Paper ( 2015-16)
Observe the following C++ code and find out , which out of the given options i) to iv) are the
expected correct output.Also assign the maximum and minimum value that can be assigned tothe
variable ‘Go’.
void main()
{
int X [4] ={100,75,10,125};
int Go = random(2)+2;
for (inti = Go; i< 4; i++)
cout<<X[i]<<”$$”;
}
i.
100$$75
ii. 75$$10$$125$$ iii. 75$$10$$ iv.10$$125$
CBSE Sample Paper ( 2014-15)
Study the following C++ program and select the possible output(s) from it :
Find the maximum and minimum value of L.
#include<stdlib.h>
#include<iostream.h>
#include<string.h>
void main()
{
randomize();
char P[]="C++PROGRAM";
long L;
for(int I=0;P[I]!='R';I++)
{
L=random (sizeof(L)) +5;
cout<<P[L]<<"-";
}
}
i) R-P-O-Rii) P-O-R-+iii) O-R-A-Giv) A-G-R-M-
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 91
CBSE Sample Paper ( 2013)
Write a function in C++ to accept two integers as parameters and returns the greater of these
numbers.
CBSE Sample Paper ( 2012)
5.1.5.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Observe the following C++ code and find the possible output(s) from the options (i) to
(iv) following it. Also, write the minimum and maximum values that can possibly be
assigned to the variable End.
Note :
 Assume all the required header files are already being included in the code.
 The function random(N) generates any possible integer between 0 and N-1
(both values included).
void main()
{
randomize();
int A[]={10,20,30,40,50,60,70,80};
int Start = random(2) + 1;
int End = Start + random(4);
for(int I=Start; I<=End, I++)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 92
cout<<A[I]<<"$";
}
(i) 10$20$30$
(ii) 20$30$40$50$60$
(iii) 30$40$50$60$
(iv) 40$50$60$70$
CBSE All India – 2018
Look at the following C++ code and find the possible output(s) from the options (i) to
(iv) following it. Also, write the highest and lowest values that can be assigned in the
array A.
Note :
 Assume all the required header files are already being included in the code.
 The function random(n) generates an integer between 0 and n – 1.
void main()
{
randomize();
int A[4], C;
for(C=0; C<4; C++)
A[C]=random(C+1)+10;
for(C=3; C>=0; C--)
cout<<A[C]<<"@";
}
(i)
(ii)
[email protected]@[email protected]@
15$14$12$10$
(iii)
(iv)
[email protected]@[email protected]@
[email protected]@[email protected]@
CBSE All India – 2017
Look at the following C++ code and find the possible output(s) fromthe options (i) to (iv)
following it. Also, write the maximum valuesthat can be assigned to each of the variables N and
M.
Note :
 Assume all the required header files are already being includedin the code.
 The function random(n) generates an integer between 0 andn – 1.
void main()
{
randomize();
int N=random(3),M=random(4);
int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
for(int R=0; R<N; R++)
{
for(int C=0; C<M; C++)
cout<<DOCK[R][C]<<" ";
cout<<endl;
}
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 93
CBSE Delhi – 2017
Look at the following C++ code and find the possible output(s) from the options(i) to (iv)
following it. Also, write the maximum values that can be assigned to eachof the variables R and C.
Note :
 Assume all the required header files are already being included in the code.
 The function random(n) generates an integer between 0 and n – 1.
void main()
{
randomize();
int R=random(3),C=random(4);
int MAT[3][3] = {{10,20,30},{20,30,40},{30,40,50}};
for(int I=0; I<R; I++)
{
for(int J=0; J<C; J++)
cout<<MAT[I][J]<<" ";
cout<<end1;
}
}
CBSE Compartment – 2017
Look at the following C++ code and find the possible output(s) from the options(i) to (iv)
following it. Also, write the maximum values that can be assigned to eachof the variables Low and
High.
Note :
 Assume all the required header files are already being included in the code.
 The function random(n) generates an integer between 0 and n – 1.
void main()
{
randomize();
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 94
int Low=2+random(3),High=5+random(3);
int C[] = "ABCDEFGHIJ";
for(int I=Low;I<=High;I++)
cout<<C[I];
cout<<endl;
};
CBSE All India – 2016
Look at the following C++ code and find the possible output(s) from the options (i)to (iv)
following it. Also, write the maximum and the minimum values that can beassigned to the variable
PICKER.
Note:
 Assume all the required header files are already being included in the code.
 The function random(n) generates an integer between 0 and n‐1
void main()
{
randomize();
int PICKER;
PICKER=1+random(3);
char COLOR[][5]={”BLUE”,”PINK”,”GREEN”,”RED”};
for(int I=0;I<=PICKER; I++)
{
for(int J=0; J<=I;J++)
cout<<COLOR[J];
cout<<endl;
}
}
CBSE Delhi – 2016
Look at the following C++ code and find the possible output(s) from the options (i)to (iv)
following it. Also, write the maximum and the minimum values that can beassigned to the variable
CHANGER.
Note :
• Assume all the required header files are already being included in the code.
• The function random(n) generates an integer between 0 and n – 1
void main()
{
randomize();
int CHANGER;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 95
CHANGER=random(3);
char CITY[][25]={“DELHI”,”MUMBAI”,”KOLKATA”,”CHENNAI”};
for(int I=0;I<=CHANGER;I++)
{
for(int J=0;J<=I;J++)
cout<<CITY[J];
cout<<endl;
}
}
CBSE All India – 2015
Study the following program and select the possible output(s)from the option (i) to (iv) following
it. Also, write the maximumand the minimum values that can be assigned to the variableVAL.
Note:
‐Assume all required header files are already being included inthe program.
‐random(n) function generates an integer between 0 and n‐1.
void main()
{
randomize();
int VAL;
VAL=random(3)+2;
char GUESS[]="ABCDEFGHIJK";
for (int I=l;I<=VAL;I++)
{
for(int J=VAL;J<=7;J++)
cout«GUESS[J];
cout«endl;
}
}
CBSE Delhi – 2015
Study the following program and select the possible output(s) from the options (i)to (iv) following
it. Also, write the maximum and the minimum values that can beassigned to the variable NUM.
Note :
– Assume all required header files are already being included in the program.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 96
– random(n) function generates an integer between 0 and n – 1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]=”ABCDEFGHIJK”;
for (int I=1;I<=NUM; I++)
{
for(int J=NUM; J<=7;J++)
cout<<TEXT[J];
cout<<end1;
}
}
CBSE All India – 2014
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 97
CBSE Delhi – 2014
Read the following C++ code carefully and find out, which out of the givenoptions (i) to (iv) are
the expected correct output(s) of it. Also, write themadmum and minimum value that can be
assigned to the variable Start used inthe code :
void main ()
{
intGuess[4]= {200,150,20 ,250};
int Start=random (2 ) +2;
for ( int C=Start ,'C<4 ,'C++ )
cout<<Guess[C]<<" #”;
}
CBSE All India – 2013
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 98
CBSE Delhi – 2011
CBSE Delhi – 2010
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 99
5.1.5.5 Important Tips:




Read the question carefully:
o If it is also asking you to mention minimum and maximum value of a variable,
please do that.
o If it is asking you to justify, please justify.
o Check if it is asking you to give all possible outputs or outputs that are not possible.
o It is possible that multiple options may be correct.
o Sometimes a missing : or # can change your answer.
Carry out a code walkthrough while solving output prediction questions.
Draw diagrams to illustrate changes in variable contents as you do your walkthrough.
Do not attempt to solve questions mentally.
5.2 QUESTION 2 ( Topic: Classes and Objects) : ( 12 Marks )
5.2.1 QUESTION 2 (a) Class XII Theory ( 2 Marks )
5.2.1.1 Revision Notes

Classes:
o What is a class?
 A user defined derived data type of C++.
 Combines together data as well as functions into a named unit.
 Serves as a plan or a template that specifies what data and what functions
will be included in entities that will be of that class type.
o Difference between a structure and a class?

All members of a class are private, by default while all members of a
structure are public, by default.
o How does it implement OOP features?
 Data Encapsulation:
 Act of wrapping up data and functions that operate on that data into a
single unit.
 This unit is called a class.
 Data Hiding:
 Hiding certain details.
 When we define an access level for a class member that says that
that member will not be visible/accessible outside the class ( the
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 100
private and protected access levels ) , we are in effect hiding that
member.
 Data Abstraction:
 Act of separating and showing only the essential features while
hiding the background details or explanations.
 The public members of a class are accessible from outside the class
and so represent the essential features while the private and protected
members are not accessible from outside the class and so are hidden
as background details.
 Polymorphism:
 When the same entity exhibits different forms depending on the
situation.
 In C++ functions with the same name execute different code
depending on their arguments ( function overloading ).
 Inheritance
 Process of borrowing features of one entity by another.
 In C++ we can define a new class (called the derived/sub class) in
terms of an existing class (called the base/super class). The derived
class inherits the capabilities of the base class but can add
refinements of its own. Thus, the derived class is a kind of the base
class.
o Access specifiers / Visibility modes.
 private, public and protected.
 Determine the accessibility of the class members from outside the class.
 Members defined as private can only be accessed by member functions and
friend functions of the class and are not otherwise accessible outside the
class.
 Members defined as protected can only be accessed by member functions
and friend functions of the class and by member functions of derived classes
and are not otherwise accessible outside the class.
 Members defined as public can be accessed both inside as well as outside
the class. They are accessed outside the class by using an object of the same
class type.
o Friend functions and friend class.
 A friend function is a non member function of a class that is granted access
to the private as well as protected members of the class ( besides the public
members ).
 A friend class of a class (say class1) is a class all whose member functions
are friends of the class ( class1 ).
 Friend functions are required when we wish to operate on data of two
different classes. They can act as a bridge between two unrelated classes.
o Private Vs. Protected.
 Protected members of a class can be accessed by the member functions of its
derived classes, not private.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 101
o Two ways of defining methods or member functions.
 Inside a class. Such a function automatically becomes inline.
 Outside the class with the prototype inside the class. Its complete qualified
name has to be written which is of the form classname::functionname.
o Concept of this pointer
 invisible pointer that is automatically passed to a class member function
when it is invoked using an object.
 Contains the address of the object that has invoked the method.
o Objects.
 An object is a variable of the class data type.
 It is an identifiable entity with some characteristics ( determined by the data
members) and some behavior ( determined by the member functions ).
o Static members of a class
 A static data member of a class is a data member that is shared by all
objects of that class i.e. only one copy of this data member is maintained.
Such a member has the lifetime of the entire program. It is declared inside
the class but is defined outside the class and can be initialized at the time of
definition.
 A static member function of a class is one that can access only the static
members of the same class. They are invoked using the class name rather
than the object name.
o Constructors
 What?
 A member function of a class with the same name as that of the
class.
 It may or may not have parameters but has no return type (not even
void).
 Need
 Required to provide initial values to the data members of the newly
created object and to perform other housekeeping functions for the
new object (e.g. allocating memory dynamically or allocating
resources).
 When called?
 automatically invoked by the compiler whenever an object of that
class is created.
 Why Public?
 So that we can create class objects outside the class.
 If it is private/protected we cannot invoke it outside the class, and
since it is invoked whenever class objects are created we cannot
create class objects outside the class.
 Constructor overloading
 Having multiple constructors within a class that differ in their
parameter lists.
 Default vs parameterized
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 102

Default constructor is a constructor that takes no arguments.
Parameterized constructor takes arguments.
 In the absence of an explicit constructor function definition, the
compiler supplies a default constructor and this constructor simply
initializes the data members of the object with some dummy values.
 Default constructor vs constructor with default parameters
 Default constructor is a constructor that takes no arguments.
 Constructor with default arguments takes arguments but since
default values have been provided for the arguments it can be
invoked without arguments.
 Copy constructor
 A special type of parameterized constructor function.
 It creates a new object as a duplicate of another object which is
passed to it as a parameter.
 3 situations where copy constructor is called?
 Initialization of an object during its declaration with values from
another object of the same class.
 When an object is passed to a function by value.
 When a function returns an object by value.
 Why is parameter to the copy constructor passed by reference?
 If the copy constructor is called by value it will call itself to make a
copy of its argument. In fact, it will call itself over and over again
until the compiler runs out of memory.
o Destructors
 What?
 Member function of a class with the same name as that of the class
but preceded by the ‘~’ (tilde) character.
 When called?
 invoked automatically by the compiler when the life time of a class
object gets over.
 What does it do?
 Returns any resources that the object may be holding.
 Why not overloaded?
 because it does not take any parameters.
o Inheritance
 Types?
 Single ( One to One)
 Multiple ( Many to One )
 Multi level ( One to One to One )
 Hierarchical ( One to Many )
 Hybrid ( One to Many to One )
 Visibility modes during inheritance.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 103





Determines the visibility of the inherited base class members in the
derived class.
 Private : the public and protected members of the base class become
private members of the derived class.
 Protected: the public and protected members of the base class
become protected members of the derived class.
 Public: the public members of the base class become public
members of the derived class and the protected members of the base
class become protected members of the derived class.
 Default visibility mode is private.
Accessibility of members within derived classes.
 Public and protected members of the base class are accessible within
the derived class, private are not.
Abstract class and concrete class.
 An abstract class is a class which is used only for the purpose of
deriving other classes. No actual instances or objects of this class are
ever created.
 A concrete class is one whose objects are created.
Order of invocation of constructors and destructors.
 First the base class constructor is invoked followed by the derived
class constructor.
 First the derived class destructor, followed by the base class
destructor.
Ambiguity during inheritance.
 Occurs in case of multiple inheritance.
 If two base classes have functions with the same name while a class
derived from both does not have a function of that name, there would
be ambiguity regarding which base class function to invoke when a
call to that function is made using an object of the derived class.
 The ambiguity can be resolved by using the scope resolution
operator to give the qualified name of the function.
Frequently asked questions:
•
Difference between a class and an object
•
Private Vs. Public members
•
Protected Vs. Private members
•
Data Abstraction Vs. Data Hiding
•
How does C++ implement data encapsulation, data abstraction and data hiding
•
Constructor Vs. Destructor
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 104
•
Four characteristics of constructor functions
•
Copy constructor
•
Explain polymorphism
•
What is function overloading or functional polymorphism
•
Multilevel Vs. Multiple Inheritance
5.2.1.2 Sample Solved Questions:
2.
(a) Differentiate between data encapsulation and data abstraction in context of Object
Oriented Programming. Also give a suitable example illustrating the difference. 2
Ans.
Data encapsulation is the act of grouping together data members and member functions in a
single unit. In C++ data members and member functions are grouped together in a class.
Data abstraction is the act of showing only the essential details while hiding background
details. In C++ , class members that are public are visible and accessible outside the class
while private and protected members are hidden within the class.
Example :
class CL1
{
int
m1;
protected :
int
m2;
public :
int m3;
};
void main()
{
CL1 ob1;
ob1.m1 = 10; // Error. private m1 cannot be accessed from outside the class.
ob1.m3 = 10; // Correct. Public m3 can be accessed from outside the class.
}
( 1 mark for correct difference.)
( 1 mark for correct example ) (= 2 marks)
5.2.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
What is a copy constructor? Illustrate with a suitable C++ example.
CBSE Sample Paper ( 2017-18)
What do you mean by Data Abstraction in OOPs? Explain its significance in programming
with a suitable example.
CBSE Sample Paper ( 2016-17)
What do you understand by Function overloading or Functionalpolymorphism? Explain with
suitable example.
CBSE Sample Paper ( 2015-16)
Differentiate between data abstraction and data hiding.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 105
CBSE Sample Paper ( 2014-15)
How encapsulation and abstraction are implemented in C++ language? Explain with an example.
CBSE Sample Paper ( 2013)
What do you understand by Data Encapsulation and Data Hiding? Also, give a suitable C++ code
to illustrate both.
CBSE Sample Paper ( 2012)
What do you understand by data encapsulation and data hiding?
What do you understand by polymorphism? Give suitable examples of the same/
5.2.1.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Explain Polymorphism in context of Object Oriented Programming. Also give a supporting
example in C++.
CBSE All India – 2018
Which function(s) out of the following can be considered as overloaded function(s) in
the same program ? Also, write the reason for not considering the other(s) as
overloaded function(s).
void Execute(char A,int B); // Function 1
void Execute(int A,char B); // Function 2
void Execute(int P=10);
// Function 3
void Execute();
// Function 4
int Execute(int A);
void Execute(int &K);
// Function 5
// Function 6
CBSE All India – 2017
Differentiate between protected and private members of a class in context ofObject Oriented
Programming. Also give a suitable example illustratingaccessibility/non-accessibility of each using
a class and an object in C++.
CBSE Delhi – 2017
Differentiate between private and public members of a class in context of ObjectOriented
Programming. Also give a suitable example illustrating accessibility/nonaccessibilityof each using
a class and an object in C++.
CBSE Compartment – 2017
Differentiate between Data Hiding and Data Encapsulation in context of ObjectOriented
Programming. Also give a suitable example illustrating the same in C++.
CBSE All India – 2016
Write any four important characteristics of Object Oriented Programming? Giveexample of any
one of the characteristics using C++.
CBSE Delhi – 2016
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 106
Differentiate between Constructor and Destructor functions giving suitableexample using a class in
C++. When does each of them execute?
CBSE All India – 2015
What is a copy constructor? Give a suitable example in C++ toillustrate with its definition within a
class and a declaration of anobject with the help of it.
CBSE Delhi – 2015
What is a copy constructor ? Give a suitable example in C++ to illustrate with itsdefinition within
a class and a declaration of an object with the help of it.
CBSE Delhi – 2014
Write 4 characteristics of a constructor function used in a class.
CBSE All India – 2013
Write any two differences between aconstructor and a destructor. Write the function headers for
constructor and destructor of a class called Member.
CBSE Compartment – 2013
What is the relationship between a class and an object? Illustrate with a suitable example.
5.2.1.5 Important Tips:


Please include all relevant points in your answer.
Whenever the question asks you to explain using an example give a C++ code example.
5.2.2 QUESTION 2 (b) Function Overloading and Constructors and
Destructors ( 2 Marks )
5.2.2.1 Revision Notes
Function Overloading
…….having multiple functions with the same name but differing in their signatures.
.........Either the number of parameters or data type of parameters may differ.
…….Implements the OOP feature of Polymorphism.
Constructor
…….function with the same name as the class name.
.......called automatically by the compiler during creation of a object.
…….provides initial values to the data members of the new object.
…….has no return data type not even void.
……..can take parameters
Destructor
.…..same name as the class name but preceeded by ~.
.....called automatically by the compiler when the lifetime of a class
object gets over.
……Returns resources held by the object getting destroyed.
…….has no return data type.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 107
…….Cannot be overloaded as it has no parameter list.
Copy Constructor
. ……parameterized constructor.
……..takes an object of the same class type as parameter.
……..the parameter is passed to it by reference ( to prevent infinite
calls to the copy constructor to be generated.)
….....called automatically by the compiler during creation of
a class object as a replica of an already existing class
object.
.…….uses values of the data members of the passed object to initialize
values of the data members of the newly created object.
Order of Invocation of Constructor/Destructor
Constructor of the base class invoked first followed by the derived class constructor. Destructors
are invoked in the reverse order.
Constructor must be defined in the public section otherwise you will not be able to define
objects of the class type outside the class. (except in friend functions).
Multiple Constructors
There can be many constructors in a class .
... called constructor overloading
... implements the OOP feature of polymorphism.
A statement that invokes the constructor is one that creates a class object. Example:
class A
{
public : A();
// Constr. 1
A(int);
// Constr. 2
A(int, char[]); // Constr. 3
A(A & );
//Constr. 4
};
- A ob1;
// invokes Constr. 1
- A ob2(10);
// invokes Constr. 2
- A ob3(20, "test");
// invokes Constr. 3
- A ob4(ob3);
// Invokes Constr 4
Types of Questions Asked:
• Identify and name the function
• State when it gets invoked
• State what function it performs
• Write the statement that will invoke it
• Complete the definition ( usually of a copy constructor or parameterized constructor )
• Which line number will result in execution of the function.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 108
•
•
How many times will it get executed?
Creation of an object when constructor is private
5.2.2.2 Sample Solved Questions:
Observe the following C++ code and answer the questions (i) and (ii). Assume all
necessary files are included:
2
class TEST
{
long TCode;
char TTitle[20];
float Score;
public:
TEST() //Member Function 1
{
TCode=100;strcpy(TTitle,”FIRST Test”);Score=0;
}
TEST(TEST &T) //Member Function 2
{
TCode=E.TCode+1;
strcpy(TTitle,T.TTitle);
Score=T.Score;
}
};
void main()
{
___________________ //Statement 1
___________________ //Statement 2
}
(i) Which Object Oriented Programming feature is illustrated by the Member Function 1
and Member Function 2 together in the class TEST?
Ans.
Polymorphism.
( 1 mark for correct answer )
(ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member
Function 2 respectively.
Ans.
TEST ob1;
TEST ob2 = ob1; or TEST ob2(ob1);
( ½ + ½ = 1 mark for correct answer )
5.2.2.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 109
Write the output of the following C++ code. Also,
write the name of feature of Object oriented
Programming used in the following program jointly
illustrated by the Function 1 to Function 4.
void My_fun ( ) // Function 1
{
for (int I=1 ; I<=50 ; I++) cout<< "-" ;
cout<<end1 ;
}
void My_fun (int N) // Function 2
{
for (int I=1 ; I<=N ; I++) cout<<"*" ;
cout<<end1 ;
}
void My_fun (int A, int B) // Function 3
{
for (int I=1. ;I<=B ;I++) cout<<A*I ;
cout<<end1 ;
}
void My_fun (char T, int N) // Function 4
{
for (int I=1 ; I<=N ; I++) cout<<T ;
cout<<end1;
}
void main ( )
{
int X=7, Y=4, Z=3;
char C='#' ;
My_fun (C,Y) ;
My_fun (X,Z) ;
}
CBSE Sample Paper ( 2017-18)
Answer the question (i) & (ii) after going through the following code. (assume all necessary header
files are included in program):-
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 110
(i) Give the name of the feature of OOP which is implemented by Function 1 & 2 together in the
above class Game.
(ii) Anuj made changes to the above class Game and made Function 3 private. Will he be able to
execute the Line 1 successfully given below? Justify.
void main()
{
Game ABC; //Line 1
}
CBSE Sample Paper 2016-17
Answer the questions(i) and (ii) after going through the following class:
class planet
{
char name[20];char distance[20];
public:
planet() //Function 1
{
strcpy(name, "Venus");
strcpy(distance,"38 million km");
}
void display(char na[],char d[]) //Function 2
{
cout<<na<<"has "<<d<<" distance from Earth"<<endl;
}
planet(char na[], char d[]) //Function 3
{
strcpy(name,na);
strcpy(distance,d);
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 111
}
~planet() //Function 4
{
cout<<"Planetarium time over!!!"<<endl;
}
};
I. What is Function 1 referred as? When will it be executed?
II. Write suitable C++ statement to invoke Function 2.
CBSE Sample Paper 2015-16
Answer the questions (i) and (ii) after going through the following class :
class Exam
{
intRollno;
charCname[25];
float Marks ;
public :
Exam( ) //Function 1
{
Rollno = 0 ;
Cname=””;
Marks=0.0;
}
Exam(intRno, char candname) //Function 2
{
Rollno = Rno ;
strcpy(Cname,candname);
}
~Exam( ) //Function 3
{
cout<< “Result will be intimated shortly” <<endl ;
}
void Display( ) //Function 4
{
cout<< “Roll no :”<<Rollno;
cout<<”Name :” <<Cname;
cout<<” Marks:”<<Marks;
}
};
(i)Which OOP concept does Function 1 and Function 2 implement. Explain?
(ii)What is Function 3 called? When will it be invoked?
CBSE Sample Paper 2014-15
Answer the questions (i) and (ii) after going through the following C++ class:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 112
class Stream
{
intStreamCode ; char Streamname[20];float fees;
public:
Stream( ) //Function 1
{
StreamCode=1; strcpy (Streamname,"DELHI"); fees=1000;
}
void display(float C) //Function 2
{
cout<<StreamCode<<":"<<Streamname<<":"<<fees<<endl;
}
~Stream( ) //Function 3
{
cout<<"End of Stream Object"<<endl;
}
Stream (intSC,char S[ ],float F) ; //Function 4
};
i) In Object Oriented Programming, what are Function 1 and Function 4 combined together
referred as? Write the definition of function 4.
ii) What is the difference between the following statements?
Stream S(11,”Science”,8700);
Stream S=Stream(11,”Science”,8700);
CBSE Sample Paper 2012
Answer the questions (i) and (ii) after going through the following C++ class:
class Conference
{
int Duration; // In hours
public :
Conference()
// Function 1
{
Duration = 8;
cout<< “Inauguration”<<endl;
}
~Conference() //Function 2
{
cout<< “Concluding Ceremony” <<endl;
}
void Session( int S= 1 )
// Function 3
{
cout<< “Session “ << S << “ is on “ <<endl;
}
Conference(int Duration)
// Function 4
{
Time = Duration;
cout<<”Inauguration” <<endl;
}
};
i) In Object Oriented Programming, what is Function2 referred as and when does it get invoked or
called?
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 113
ii) In Object Oriented Programming, which concept is illustrated by Function1 and Function 4
together? Write an example illustrating the calls to these two functions.
Answer the questions (i) and (ii) after going through the following C++ class:
class Match
{
int Time;
public: Match()
// Function 1
{
Time = 0;
cout<<”\nMatch Commences”<<endl;
}
void Details()
// Function 2
{
cout<< “Inter Section Basketball match” <<endl;
}
Match(int Duration )
// Function 3
{
Time = Duration;
cout<< “Another match begins now” <<endl;
}
Match( Match &M)
// Function 4
{
Time = M.Time;
cout<< “Like Previous Match” <<endl;
}
};
i) Which category of constructor does Function 4 belong to and what is the purpose of using it?
ii) Write statements that would call member Functions 1 and 3.
5.2.2.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.
class Point
{
int X,Y;
public:
Point(int I=10, int J=20)
//Function 1
{
X=J;
Y=I;
}
void Show()
//Function 2
{
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 114
cout<<"Points are"<<X<<"&"<<Y<<endl;
}
~Point()
{
cout<<"Points Erased"<<endl;
}
//Function 3
};
void main()
{
Point P(5);
P.Show();
}
(i)
For the class Point, what is Function 3 known as ? When is
it executed ?
(ii)
What is the output of the above code, on execution ?
CBSE All India – 2018
Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.
class FIRST
{
int Num1;
public:
void Display()
//Member Function 1
{
cout<<Num1<<endl;
}
};
class SECOND: public FIRST
{
int Num2;
public:
void Display()
//Member Function 2
{
cout<<Num2<<endl;
}
};
void main()
{
SECOND S;
__________________________; // Statement 1
__________________________; // Statement 2
}
(i)
Which Object Oriented Programming feature is illustrated by
the definitions of classes FIRST and SECOND ?
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 115
(ii)
Write Statement 1 and Statement 2 to execute Member Function 1
and Member Function 2 respectively using the object S.
CBSE All India – 2017
Observe the following C++ code and answer the questions (i) and (ii).
Note: Assume all necessary files are included.
class TEST
{
longTCode;
charTTitle[20];
float Score;
public:
TEST() //Member Function 1
{
TCode=100;strcpy(TTitle,”FIRST Test”);Score=0;
}
TEST(TEST &T) //Member Function 2
{
TCode=E.TCode+1;
strcpy(TTitle,T.TTitle);
Score=T.Score;
}
};
void main()
{
___________________ //Statement 1
___________________ //Statement 2
}
(i) Which Object Oriented Programming feature is illustrated by the Member Function 1 and
Member Function 2 together in the class TEST?
(ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member Function 2
respectively.
CBSE Delhi – 2017
Observe the following C++ code and answer the questions (i) and (ii).
Note: Assume all necessary files are included.
class EXAM
{
long Code;
charEName[20];
float Marks;
public:
EXAM() //Member Function 1
{
Code=100;strcpy(EName,"Noname");Marks=0;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 116
}
EXAM(EXAM &E) //Member Function 2
{
Code=E.Code+1;
strcpy(EName,E.EName);
Marks=E.Marks;
}
};
void main()
{
___________________ //Statement 1
___________________ //Statement 2
}
(i) Which Object Oriented Programming feature is illustrated by the Member Function 1 and
Member Function 2 together in the class EXAM?
(ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member Function 2
respectively.
CBSE Compartment- 2017
Observe the following C++ code and answer the questions (i) and (ii).
Note : Assume all necessary files are included.
class GAME
{
intPcode,Round,Score;
public:
GAME() //Member Function 1
{
Pcode=1;Round=0;Score=0;
}
GAME(GAME &G) //Member Function 2
{
Pcode=G.Pcode+1;
Round=G.Round+2;
Score=G.Score+10;
}
};
void main()
{
_____________ //Statement 1
_____________ //Statement 2
}
(i) Which Object Oriented Programming feature is illustrated by the Member Function 1 and
Member Function 2 together in the class GAME ?
(ii) Write Statement 1 and Statement 2 to execute Member Function 1 and Member Function 2
respectively.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 117
CBSE All India – 2016
Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files
are included:
class BOOK
{
long Code ;
char Title[20];
float Price;
public:
BOOK() //Member Function 1
{
cout<<”Bought”<<endl;
Code=10;strcpy(Title,”NoTitle”);Price=100;
}
BOOK(intC,char T[],float P) //Member Function 2
{
Code=C;
strcpy(Title,T);
Price=P;
}
void Update(float P) //Member Function 3
{
Price+=P;
}
void Display() //Member Function 4
{
cout<<Code<<”:”<<Title<<”:”<<Price<<endl;
}
~BOOK() //Member Function 5
{
cout<<”Book Discarded!”<<end1;
}
};
void main()
//Line 1
{
//Line 2
BOOK B,C(101,”Truth”,350};
//Line 3
for (int I=0;I<4;I++)
//Line 4
{
//Line 5
B.Update(50);C.Update(20);
//Line 6
B.Display();C.Display();
//Line 7
}
//Line 8
}
//Line 9
(i) Which specific concept of object oriented programming out of the following is illustrated by
Member Function 1 and Member Function 2 combined together?
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 118
● Data Encapsulation
● Polymorphism
● Inheritance
● Data Hiding
(ii) How many times the message ”Book Discarded!” will be displayed after executing the above
C++ code? Out of Line 1 to Line 9, which line is responsible to display the message ”Book
Discarded!”
CBSE Delhi – 2016
Differentiate between Constructor and Destructor functions giving suitable example using a class
in C++. When does each of them execute?
Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files
are included:
class FICTION
{
longFCode;
charFTitle[20];
floatFPrice;
public:
FICTION()
//Member Function 1
{
cout<<”Bought”<<endl;
FCode=100;strcpy(FTitle,”Noname”);FPrice=50;
}
FICTION(intC,char T[],float P) //Member Function 2
{
FCode=C;
strcpy(FTitle,T);
FPrice=P;
}
void Increase(float P)
//Member Function 3
{
FPrice+=P;
}
void Show()
//Member Function 4
{
cout<<FCode<<”:”<<FTitle<<”:”<<FPrice<<endl;
}
~FICTION() /
/Member Function 5
{
cout<<”Fiction removed!”<<end1;
}
};
void main()
//Line 1
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 119
{
//Line 2
FICTION F1,F2(101,”Dare”,75);
//Line 3
for (int I=0;I<4;I++)
//Line 4
{
//Line 5
F1.Increase(20);F2.Increase(15);
//Line 6
F1.Show();F2.Show();
//Line 7
}
//Line 8
}
//Line 9
(i) Which specific concept of object oriented programming out of the following is illustrated by
Member Function 1 and Member Function 2 combined together?
● Data Encapsulation
● Data Hiding
● Polymorphism
● Inheritance
(ii) How many times the message ”Fiction removed!” will be displayed after executing the above
C++ code? Out of Line 1 to Line 9, which line is responsible to display the message ”Fiction
removed!”?
CBSE All India – 2015
What is a copy constructor? Give a suitable example in C++ to illustrate with its definition within
a class and a declaration of an object with the help of it.
Observe the following C++ code and answer the questions (i) and (ii) :
class Passenger
{
long PNR;
char Name [20] ;
public:
Passenger()
//Function 1
{ cout<<"Ready"<<endl; }
void Book(long P,char N[])
//Function 2
{ PNR = P; strcpy(Name, N); }
void Print()
//Function 3
{ cout«PNR<< Name <<endl; }
~Passenger()
//Function 4
{ cout<<"Booking cancelled!"<<endl; }
};
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3
respectively in the following code:
void main()
{
Passenger P;
___________ //Line 1
___________ //Line 2
}//Ends here
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 120
(ii) Which function will be executed at }//Ends here? What is this function referred as ?
CBSE Delhi – 2015
What is a copy constructor ? Give a suitable example in C++ to illustrate with its definition within
a class and a declaration of an object with the help of it.
Observe the following C++ code and answer the questions (i) and (ii) :
classTraveller
{
long PNR;
charTName[20];
public :
Traveller()
//Function 1
{cout<<”Ready”<<end1;}
void Book(long P,char N[])
//Function 2
{PNR = P; strcpy(TName, N);}
void Print()
//Function 3
{cout<<PNR <<TName<<end1;}
~Traveller()
//Function 4
{cout<<”Booking cancelled!”<<end1;}
};
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3
respectively in the following code
void main()
{
Traveller T;
_________ //Line 1
_________ //Line 2
}//Stops here
(ii) Which function will be executed at }//Stops here ? What is this function referred as ?
CBSE All India – 2013
Write any 2 similarities between Constructor and Destructor. Write the function headers for
constructor and destructor of a class Flight.
Answer questions (i) and (ii) after going through the following class:
class Race
{
intCarNo, Track;
public :
Race();
// Function 1
Race(int CN);
// Function 2
Race(Race &R);
// Function 3
void Register();
// Function 4
void Drive();
// Function 5
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 121
};
void main()
{
Race R;
.
.
.
.
}
(i) Out of the following, which of the option is correct for calling Function 2?
Option 1 – Race T(30);
Option 2 – Race U(R);
(ii) Name the feature of object oriented programming which is illustrated by
Function1, Function2 and Function3 combined together.
CBSE Delhi – 2013
Write any 2 differences between Constructor and Destructor. Write the function headers for
constructor and destructor of a class Member.
Answer questions (i) and (ii) after going through the following class:
class Motor
{
intMotorNo, Track;
public :
Motor();
// Function 1
Motor(int MN);
// Function 2
Motor(Motor &M);
// Function 3
void Allocate();
// Function 4
void Move();
// Function 5
};
void main()
{
Motor M;
.
.
.
.
}
(i) Out of the following, which of the option is correct for calling Function 2?
Option 1 - Motor N ( M );
Option 2 – Motor P (10);
(ii) Name the feature of object oriented programming which is illustrated by Function1, Function2
and Function3 combined together.
CBSE Compartment- 2013
Answer questions (i) and (ii) after going through the following class:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 122
class Book
{
intBookNo;
charBookTitle[20];
public :
Book();
Book( Book &);
Book(int, char[]);
void Buy();
void Sell();
// Function 1
// Function 2
// Function 3
// Function 4
// Function 5
};
void main()
{
.
.
.
}
(i) Write statements in C++ to execute Function 3 and Function 4 inside the main function.
(ii) Name the feature of object oriented programming which is illustrated by Function1, Function2
and Function3 combined together.
CBSE Delhi – 2012
Answer questions (i) and (ii) after going through the following class:
class Tour
{
intLocationCode; char Location[20]; float Charges;
public :
Tour()
// Function 1
{
LocationCode = 1; strcpy( Location, “PURI”); Charges=1200;
}
voidTourPlan(float C)
// Function 2
{
cout<<PlaceCode<< “:”<<Place<< “:” << Charges <<endl;
Charge+=100;
}
Tour (int LC, char L[], float C)
// Function 3
{
LocationCode = LC; strcpy( Location, L); Charges=C;
}
~Tour()
// Function 4
{
cout<< “Tour Plan Cancelled” <<endl;
}
};
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 123
(i) In object oriented programming what are Function1 and Function3 combined together referred
as?
(ii) In object oriented programming which concept is illustrated by Function4? When is this
function called/invoked?
CBSE Compartment – 2012
Differentiate between Constructor and Destructor functions in a class. Give a suitable example in
C++ to illustrate the difference.
CBSE Compartment – 2011
Answer questions (i) and (ii) after going through the following class:
class School
{
int SID; char Dept[10];
public :
School()
// Function 1
{
SID = -1;
}
School(int ID, char D[])
// Function 2
{
SID = ID;
strcpy(Dept, D );
}
School ( School& S)
// Function 3
{
SID = S.ID;
strcpy(Dept, S.Dept );
}
void Display()
// Function 4
{
cout<< SID << “,” <<Dept<<endl;
}
};
(i) In function 3, parameters are passed by reference. Why?
(ii) Which property of object oriented programming is illustrated by Function 1, Function2 and
Function3 together? Write an example illustrating the calls for these functions.
CBSE Delhi – 2010
Answer questions (i) and (ii) after going through the following class:
class TEST
{
intRegno, Max, Min, Score;
public :
TEST()
// Function 1
{
Regno = 101; Max = 100; Min = 40; Score = 75;
}
TEST(intPregno, intPscore)
// Function 2
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 124
{
Regno = Pregno; Score = Pscore;
}
~TEST ( )
// Function 3
{
cout<< “TEST Over” <<endl;
}
void Display()
// Function 4
{
cout<<Regno<< “:” << Max << “:” << Min <<endl;
cout<< Score <<endl;
}
};
(i) What is function 3 specifically refereed as? When do you think function 3 will be
invoked/called?
(ii) As per object oriented programming which concept is illustrated by Function 1 and Function2
together?
CBSE Delhi– 2009
What is a copy constructor? Give an example in C++ to illustrate a copy constructor.
Answer questions (i) and (ii) after going through the following class:
class WORK
{
intWorkId; char WorkType;
public:
~WORK()
//Function 1
{ cout<<"Un-allocated"<<endl;}
void status()
//Function 2
{ cout<<WorkId<< “:” <<WorkType<<endl;}
WORK()
//Function 3
{ WorkId= 10; WorkType = ‘T’;}
WORK( WORK & W)
//Function 4
{ WorkId= W.WorkId + 12; WorkType = W.WorkType + 1;}
};
(i)
Which member function out of Function 1, Function2, Function3 and Function4
shown in the above definition of class WORK is called automatically when the
scope of an object gets over? Is it known as Constructor OR Destructor OR
Overloaded function OR Copy Constructor?
(ii)
WORK W;
// Statement 1
WORK Y ( W );
// Statement 2
Which member function out of Function 1, Function2, Function3 and Function4
shown in the above definition of class WORK will be called on execution of
statement 2? What is this function specifically known as out of Destructor OR Copy
Constructor OR Default Constructor?
CBSE Delhi – 2008
Answer questions (i) and (ii) after going through the following programs:
class Bazar
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 125
{
char Type[20];
char Product[20];
intQty;
float Price;
Bazar()
// Function 1
{
strcpy( Type, “Electronic” );
strcpy( Product, “Calculator”);
Qty = 10;
Price = 225;
}
public:
voidDisp()
// Function 4
{
cout<< Type << “-” << Product << “:” << Qty << “@” << Price<<endl;
}
};
void main()
{
Bazar B;
B.Disp();
}
(i) Will Statement1 initialize all the data members for object B with the values given in Function1
?( Yes or No ) Justify your answer suggesting the corrections to be made in the above code.
(ii) What shall be the possible output when the program gets executed? ( Assuming, if required –
the suggested corrections are made in the program )
5.2.2.5 Important Tips:
 While identifying a constructor remember to mention the type of Constructor(default,
parameterized etc.)
 Please be careful as to whether the question is asking you to define what a copy contructor
is or asking you to write the definition of the copy constructor function (function header
and body).
5.2.3 QUESTION 2 (c) Class Definition ( 4 Marks )
5.2.3.1 Revision Notes
Class Definition
• Use appropriate data types for members:
• A String means an array of characters
• long and long int are the same
• Functions that are performing division should return a float/double.
• Do not forget to terminate the class definition with a ;
• Remember that class member functions can directly access the class data members. You do
not have to pass them as parameters.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 126
•
•
If the data member is a string use strcpy for assignment and strcmpi for comparing. For
other data types ( even char ) use = for assignment and == for comparing.
Write public and not Public.
5.2.3.2 Sample Solved Questions:
Write the definition of a class GRAPH in C++ with following description: 4
Private Members
 XUnit // integer
 YUnit // integer
 Type // char array of size 20
 AssignType() /* Member function to assign value of Type based upon XUnit and
YUnit as follows: */
Condition
Type
XUnit = 0 Or YUnit = 0
None
XUnit is more than YUnit
Bar
XUnit is less than or equal
to YUnit
Line
Public Members
 InXY() /* Function to allow user to enter values of XUnit and YUnit and then
invoke AssignType() to assign value of Type */
 OutXY() //Function to display XUnit, YUnit and Type
Ans.
class GRAPH
{
int XUnit, YUnit;
char Type[20];
void AssignType();
public :
void InXY();
void OutXY();
};
void GRAPH::AssignType()
{
if (XUnit==0||YUnit==0)
strcpy(Type,"None");
else if (XUnit>YUnit)
strcpy (Type,"Bar");
else if (XUnit<= YUnit) // OR only else
strcpy(Type,"Line");
}
void GRAPH::InXY()
{
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 127
cin>>XUnit>>YUnit;
AssignType();
}
void GRAPH::OutXY()
{
cout<<XUnit<<YUnit<<Type<<endl;
}
(½ Mark for declaring data members correctly)
(1 Mark for defining AssignType() correctly)
(½ Mark for taking inputs of XUnit and YUnit in InXY() )
(½ Mark for invoking AssignType() inside InXY())
(½ Mark for defining OutXY() correctly)
(½ Mark for correctly closing class declaration with a semicolon ; )
NOTE:
● Marks to be awarded for defining the member functions inside or
outside the class
5.2.3.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Define a class Ele_Bill in C++ with the following descriptions:
Private members:
Cname of type character array
Pnumber of type long
No_of_units of type integer
Amount of type float.
Calc_Amount( ) This member function should calculate the
amount as No_of_units*Cost .
Amount can be calculated according to the following conditions:
No_of_unitsCost
First 50 units Free
Next 100 units 0.80 @ unit
Next 200 units 1.00 @ unit
Remaining units 1.20 @ unit
Public members:
* A function Accept( ) which allows user to enter Cname, Pnumber, No_of_units and invoke
function Calc_Amount().
* A function Display( ) to display the values of all the data members on the screen.
CBSE Sample Paper ( 2017-18)
Define a class Bill in OOP with the following specification:Private members:
1. Bill_no - type long(bill number)
2. Bill_period - type integer(number of months)
3. No_of_calls - type integer(number of mobile calls)
4. Payment_mode - type string(“online” or “offline”)
5. Amount - type float(amount of bill)
6. Calculate_Bill() function to calculate the amount of bill given as per the following conditions:
No_of_calls
Calculation Rate/call
(in rupees)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 128
<=500
1.0
501-1200
2.0
>1200
4.0
Also, the value of Amount should be reduced by 5% if Payment_mode is “online”.
Public members:
1. A member function New_Bill() that will accept the values for Bill_no, Bill_period, No_of_calls,
Payment_mode from the user and invoke Caluclate_Bill() to assign the value of Amount.
2. A member function Print_Bill() that will display all details of a Bill.
CBSE Sample Paper 2016-17
Define a class DanceAcademy in C++ with following description:
Private Members
● Enrollno of type int
● Name of type string
● Style of type string
● Fee of type float
● A member function chkfee( ) to assign the value of fee variable according to the style
entered by the user according to the criteria as given below:
Public Members
 A function enrollment() to allow users to enter values for Enrollno,Name, Style and call
function chkfee()to assign value of fee variable according to the Style entered by the user.
 A function display() to allow users to view the details of all the data members.
CBSE Sample Paper 2015-16
Define a class Candidate in C++ with the following specification :
Private Members :
A data members Rno(Registration Number) type long
A data member Cname of type string
A data members Agg_marks (Aggregate Marks) of type float
A data members Grade of type char
A member function setGrade () to find the grade as per the aggregate marks
obtained by the student. Equivalent aggregate marks range and the respective grade as shown
below.
Aggregate Marks
Grade
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 129
>=80
A
Less than 80 and >=65
B
Less than 65 and >=50
C
Less than 50
D
Public members:
A constructor to assign default values to data members:
Rno=0,Cname=”N.A”,Agg_marks=0.0
A function Getdata () to allow users to enter values for Rno. Cname, Agg_marks and call
functionsetGrade () to find the grade.
A function dispResult( ) to allow user to view the content of all the data members.
CBSE Sample Paper 2014-15
Define a class Customer with the following specifications.
Private Members :
Customer_no
integer
Customer_name
char (20)
Qty
integer
Price, TotalPrice, Discount, Netprice float
Member Functions:
Public members:
* A constructer to assign initial values of Customer_no as 111,Customer_name as “Leena”,
Quantity as 0 and Price, Discount and Netprice as 0.
*Input( ) – to read data members(Customer_no, Customer_name, Quantity and Price) call
Caldiscount().
* Caldiscount ( ) – To calculate Discount according to TotalPrice and NetPrice
TotalPrice = Price*Qty
TotalPrice>=50000 –
Discount 25% of TotalPrice
TotalPrice>=25000 and TotalPrice<50000 - Discount 15% of TotalPrice
TotalPrice<250000 Discount 10% of TotalPrice
Netprice= TotalPrice-Discount
*Show( ) – to display Customer details.
CBSE Sample Paper 2013
Define a class HandSet in C++ with following description:
Private members:
Make- of type string
Model- of type string
Price- of type long int
Rating- of type char
Public Members:
Function Read_Data to read an object of HandSet type.
Function Display() to display the details of an object of HandSet type.
Function RetPrice() to return the value of Price of an object of HandSet type.
CBSE Sample Paper 2012
Define a class CARRENTAL in C++ with the following description:
Private Members:
 CarID of type long int
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 130




AboutCar of type string
Cartype of type string
Rent of type float
A member function AssignRent() to assign the following values for Rent as per the given
Cartype.
Cartype Rent
Small
1000
Van
800
SUV
2500
Public Members:
 A function GetCar() to allow the suer to enter values for CarID, AboutCar, Cartype and call
function AssignRent() to assign Rent.
 A function SHOWCAR() to allow the user to view the content of all data members.
Define a class in C++ with the following description:
Private Members:
 A data member FlightNumber of type integer.
 A data member Destination of type string.
 A data member Distance of type float.
 A data member Fuel of type float.
 A member function CALFUEL() to calculate the value of Fuel as per the following criteria
Distance
Fuel
<=1000
500
more than 1000 and <=2000
1100
more than 2000
2200
Public Members:
 A function FEEDINFO() to allow the user to enter values for FlightNumber, Destination,
Distance and call function CALFUEL() to calculate the quantity of Fuel.
 A function SHOWINFO() to allow the user to view the content of all data members.
5.2.3.4 Questions From Previous Year Board Papers:
CBSE All India – 2018
Write the definition of a class CONTAINER in C++ with the following description :
Private Members
-
Radius, Height
Type
Volume
CalVolume()
Type
1
Ownership
// float
// int (1 for Cone,2 for Cylinder)
// float
// Member function to calculate
// volume as per the Type
Formula to calculate Volume
3.14*Radius*Height
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 131
2
3.14*Radius*Height/3
Public Members
- GetValues() // A function to allow user to enter value
// of Radius, Height and Type. Also, call
// function CalVolume() fromit
- ShowAll()
// A function to display Radius,Height,
// Type and Volume of Container
CBSE All India – 2017
Write the definition of a class BOX in C++ with following description:
Private Members
- BoxNumber
// data member of integer type
- Side
// data member of float type
- Area
// data member of float type
- ExecArea()
// Member function to calculate and assign
// Area as Side * Side
Public Members
- GetBox()
// A function to allow user to enter values of
// BoxNumber and Side. Also, this
// function should call ExecArea() to calculate
// Area
- ShowBox()
// A function to display BoxNumber, Side
// and Area
CBSE Delhi – 2017
Write the definition of a class RING in C++ with following description:
Private Members
- RingNumber
// data member of integer type
- Radius
// data member of float type
- Area
// data member of float type
- CalcArea()
// Member function to calculate and assign
// Area as 3.14 * Radius*Radius
Public Members
- GetArea()
// A function to allow user to enter values of
// RingNumber and Radius. Also, this
// function should call CalcArea() to calculate
// Area
- ShowArea()
// A function to display RingNumber, Radius
// and Area
CBSE Compartment – 2017
Write the definition of a class FRAME in C++ with following description :
Private Members
- FID
// data member of integer type
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 132
- Height
- Width
- Amount
- GetAmount()
Public Members
- GetDetail()
// data member of float type
// data member of float type
// data member of float type
// Member function to calculate and assign
// Amount as 10*Height*Width
// A function to allow user to enter values of
// FID, Height, Width. This Function should
// also call GetAmount() function to calculate
// Amount
// A function to display the
// values of all data members
- DispDetail()
CBSE All India – 2016
Write the definition of a class CITY in C++ with following description :
Private Members
- Ccode
// data member for city code ( an integer )
- CName
// data member for city name ( a string )
- Pop
// data member for population ( a long int )
- KM
// data member for Area Coverage ( a float )
- Density
// data member for population density ( a float )
- DenCal()
// Member function to calculate Density as Pop/KM
Public Members
- Record()
// A function to allow user to enter values of
// Ccode, CName, Pop, KM and call DenCal() function
- View()
// A function to display all the data members and also
// display a message “Highly populated city” if the Density
// is more than 10000
CBSE Delhi – 2016
Write the definition of a class METROPOLIS in C++ with following description:
Private Members
Mcode
//Data member for Code (an integer)
MName
//Data member for Name (a string)
MPop
//Data member for Population (a long int)
Area
//Data member for Area Coverage (a float)
PopDens
//Data member for Population Density (a float)
CalDen()
//A member function to calculate Density as PopDens/Area
Public Members
Enter()
//A function to allow user to enter values of
//Mcode,MName,MPop,Area and call CalDen() function
ViewALL()
//A function to display all the data members
//also display a message ”Highly Populated Area”
//if the Density is more than 12000
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 133
CBSE All India – 2015
Write the definition of a class Photo in C++ with following description:
Private Members
Pno
//Data member for Photo Number (an integer)
Category
//Data member for Photo Category (a string)
Exhibit
//Data member for Exhibition Gallery (a string)
FixExhibit
//A member function to assign Exhibition Gallery as per Category
//as shown in the following table
Category
Exhibit
Antique
Zaveri
Modern
Johnsen
Classic
Terenida
Public Members
Register()
//A function to allow user to enter values
//Pno,Category and call FixExhibit() function
ViewAll()/
/A function to display all the data members
CBSE Delhi – 2015
Write the definition of a class PIC in C++ with following description :
Private Members
– Pno
//Data member for Picture Number (an integer)
– Category
//Data member for Picture Category (a string)
– Location
//Data member for Exhibition Location (a string)
– FixLocation
//A member function to assign Exhibition Location as per category
//as shown in the following table
Category
Location
Classic
Amina
Modern
Jim Plaq
Antique
Ustad Khan
Public Members
– Enter()
//A function to allow user to enter values
//Pno, category and call FixLocation() function
– SeeAll()
//A function to display all the data members
CBSE Delhi – 2012
Declare a class called SUPPLY with the following descriptions:
Private members:
 Code of type int.
 FoodName of type string.
 Sticker of type string.
 FoodType of type string.
 A member function GeType() to assign the following values for FoodType as per
the given Sticker:
Sticker
FoodType
GREEN
Vegetarian
YELLOW
Contains Egg
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 134
RED
Non_Vegetarian
Public members:
A function FoodIn() to allow the user to enter values for Code, FoodName, Sticker and call
finctionGetType() to assign respective FoodType.
A function FoodOut() to allow the user to view the content of all data members.
CBSE Compartment – 2012
Declare a class called FLAT with the following descriptions:
Private members:
 Fno
// Data member for storing Flat No
 FCatg
// Data member for storing Flat Category
 FRate
// data member for storing flat rate per square feet
 Area
// Data member for storing Area covered.
Public members:
 FCost()
// A function to calculate and return cost of flat as follows:
FCatg
FCost
LIG
FRate * Area
MIG
FRate * 1.5 * Area
HIG
FRate * 3 * Area


Register()
// A function to enter value of Fno, FCatg, FRate and Area
Display()
// A function to display Fno, FCatg, FRate, Area and Cost ( Cost to
be displayed by calling the function FCost() )
CBSE All India – 2011
Declare a class called Applicant with the following descriptions:
Private members:
 A data member ANo( Admission Number) of type long).
 A data member Name of type string.
 A data member Agg( Aggregate Marks ) of type float.
 A data member Grade of type char.
 A member function GradeMe() to find the grade as per the aggregate marks
obtained by a student. Equivalent aggregate marks range and the respective grades
are shown as follows:
Aggregate Marks
Grade
>=80
A
less than 80 and >=65
B
less than 65 and >=50
C
less than 5
D
Public members:
A function ENTER() to allow the user to enter values for ANo, Name, Agg and call
function GradeMe() to assign the grade.
A function RESULT() to allow the user to view the contents of all the data members.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 135
CBSE Delhi – 2011
Declare a class called Candidate with the following descriptions:
Private members:
 A data member RNo( Registration Number) of type long).
 A data member Name of type string.
 A data member Score of type float.
 A data member Remarks of type string.
 A member function AssignRem() to assign Remarks as per the Score obtained by a
candidate. Score range and the respective remarks are shown as follows:
Score
Remarks
>=50
Selected
less than 50
Not selected
Public members:
A function ENTER() to allow the user to enter values for RNo, Name, Score and call
function AssignRem() to assign the remarks.
A function DISPLAY() to allow the user to view the contents of all the data members.
CBSE Compartment – 2011
Declare a class called EMPLOYEE with the following descriptions:
Private members:
 Employee Number(E_No) of type integer.
 Employee Name ( E_Name) of type string.
 No. of days present (Present) of type integer.
 Total Working days (Total) of type integer.
 A member function CALPER() to calculate and return the percentage attendance as
(Present/Total *100 )
Public members:
A function ENTER() to allow the user to enter values for E_No, Name, Present and Total.
A function DISPER() to allow the user to view the data of employees who are eligible to
get a special allowance, assuming that minimum % of attendance is required. Call CALPER()
function to calculate the percentage.
CBSE Delhi – 2010
Declare a class called ITEM with the following descriptions:
Private members:
Code of type integer ( Item Code )
Iname of type string ( Item Name )
Price of type float ( Price of each item )
Qty of type integer (Quantity of item in stock )
Offer of type float (Offer percentage on the item )
A member function GetOffer() to calculate Offer percentage as per the following rule:
if Qty <= 50 , Offer is 0
if 50 < Qty <= 100, Offer is 5
if Qty > 100, Offer is 10
Public members:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 136
A function GetStock() to allow the user to enter values for Code, Iname, Price, Qty and call
function GetOffer() to calculate the Offer..
A function ShowItem() to allow the user to view the contents of all the data members.
CBSE Delhi – 2008
Define a class called Garments in C++ with the following specifications:
Private members:
 GCode
of type string
 GType
of type string
 GSize
of type integer
 GFabric
of type string
 GPrice
of type float
 A function Assign() which calculates and assigns the value of GPrice as follows:
For the value of GFabric as “COTTON”
GType
GPrice (Rs)
TROUSER
1300
SHIRT
1100
For GFabric other than “COTTON” the above mentioned GPrice gets reduced by 10%.
Public Members:
 A constructor function to assign initial values of GCode, GType and GFabric with the word
“NOT ALLOTTED” and GSize and GPrice with 0.
 A function Input() to input the values of the data members GCode, GType, GSize and
GFabric and invoke the Assign() function.
 A function Display() which displays the content of all the data members for a garment.
CBSE Delhi – 2007
Define a class called Tour in C++ with the following specifications:
Private members:
 Tcode
of type string
 NoofAdults
of type integer
 NoofKids
of type integer
 Kilometers
of type integer
 TotalFare
of type float
Public Members:
 A constructor function to assign initial values as follows:
Tcode with the word “NULL”
NoofAdults as 0
NoofKids as 0
Kilometres as 0
TotalFare as 0
 A function AssignFare() which calculates and assigns the value of the data member
TotalFare as follows:
For each Adult
Fare (Rs)
For Kilometres
500
>= 1000
300
< 1000 &>= 500
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 137
200
< 500
For each kid the above fare will be 50% of the fare mentioned in the above table.
For example:
If Kilometres is 850, NoofAdults =2 and NoofKids = 3 then TotalFare should be calculated
as
NoofAdults * 300 + NoofKids * 150
i.e. 2*300 + 3 * 150 = 1050
 A function EnterTour() to input the values of the data members Tcode, NoofAdults,
NoofKids and Kilometres and invoke the AssignFare() function.
 A function ShowTour() which displays the content of all data members for a tour.
CBSE All India – 2006
Define a class named HOUSING in C++ with the following descriptions:
Private Members:
REG_NO
integer(Ranges 10 - 1000)
NAME
Array of characters (String)
TYPE
Character
COST
Float
Public Members:
 Function Read_Data() to read an object of HOUSING type.
 Function Display() to display the details of an object.
Function Draw_Nos() to choose and display the details of two houses selected randomly from an
array of 10 objects of type HOUSING. Use random() function to generate the registration nos. to
match with REG_NO from the array
CBSE Delhi – 2006
Define a class named ADMISSION in C++ with the following descriptions:
Private Members:
AD_NO
integer(Ranges 10 - 2000)
NAME
Array of characters (String)
CLASS
Character
FEES
Float
Public Members:
 Function Read_Data() to read an object of ADMISSION type.
 Function Display() to display the details of an object.
 Function Draw_Nos() to choose 2 students randomly and display the details. Use
random() function to generate the admission nos. to match with AD_NO.
CBSE Compartment – 2006
Define a class as follows:
Private Members:
HALL_NO
MOVIE_NAME
WEEK
WEEK_COLLECTION
Ownership
Integrity
integer
Array of characters (String)
integer (Total number of weeks the same movie is shown )
Float
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 138
TOTAL_COLLECTION
Float
Public Members:
 Function Read_Data() to read an object of MOVIE type.
 Function Display() to display the details of an object.
CBSE All India – 2005
Declare a class called Travel with the following descriptions:
Private members:
TravelCode
of type long
Place
of type character array(string)
No_of_travellers
of type integer
No_of_buses
of type integer
Public members:
A constructor to assign initial values of TravelCode as 201, Place as “Nainital”, No_of
_travellers as 10, Number of buses as 1.
A function NewTravel() which allows the user to enter TravelCode, Place and
No_of_travellers. Also assign the value of No_of_buses as per the following conditions:
No_of_travellers
No_of_buses
Less than 20
1
Equal to or more than 20 and less than 40
2
Equal to 40 or more than 40
3
A function ShowTravel() to display the content of all the data members on screen.
CBSE Delhi – 2005
Declare a class called TravelPlan with the following descriptions:
Private members:
PlanCode
of type long
Place
of type character array(string)
Number_of_travellers
of type integer
Number_of_buses
of type integer
Public members:
A constructor to assign initial values of PlanCode as 1001, Place as “Agra”, Number_of
_travellers as 5, Number of buses as 1.
A function NewPlan() which allows the user to enter PlanCode, Place and
Number_of_travellers. Also assign the value of Number_of_buses as per the following
conditions:
Number_of_travellers
Number_of_buses
Less than 20
1
Equal to or more than 20 and less than 40
2
Equal to 40 or more than 40
3
A function Showplan() to display the content of all the data members on screen.
CBSE Compartment – 2005
Declare a class called cricket with the following descriptions:
Private members:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 139
Target_score
of type integer
Overs_bowled
of type integer
Extra_time
of type integer
Penalty
of type integer
Cal-penalty() a member function to calculate penalty as follows:
ifExtra_time<= 10 , penalty = 1
ifExtra_time> 10 but <= 20, penalty = 2
otherwise, penalty = 5
Public members:
A function Extradata() to allow the user to enter values for Target_score, Overs_bowled,
Extra_time.
A function Dispdata() to allow the user to view the contents of all the data members.
CBSE All India – 2004
Declare a class called myfolder with the following specifications:
Private members of the class:
Filenames
an array of strings of size [10][25]
(to represent all the names of files inside myfolder)
Availspace
long
(to represent total number of bytes available in myfolder)
Usedspace
long
(to represent the total number of bytes in myfolder)
Public members of the class:
Newfileentry()
A function to accept values of Filenames, Availspace and
Usedspace from the user.
Retavailspace()
A function that returns the value of total kilobytes
available. ( 1 kilobyte = 1024 bytes)
Showfiles()
A function that displays the names of all the files in
myfolder.
CBSE Delhi – 2004
Declare a class Directory with the following specifications:
Private members of the class:
Docunames
an array of string of size[10[25]
( to represent all the names of Documents inside Directory).
Freespace
long
( to represent total number of bytes available in the Directory).
Occupied
long
( to represent total number of bytes used in Directory).
Public members of the class:
Newdocuentry()
function to accept values of Docunames, Freespace and Occupied
from the user.
Retfreespace()
function that returns the value of total Kilobytes available ( 1
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 140
kilobyte = 1024 bytes ).
Showfiles()
A function that displays the names of all the Documents in the
Directory.
 Function Update() to update the total collection and weekly collection once the week
changes. Total collection will be incremented by Weekly collection and Weekly
collection is made zero.
5.2.3.5 Important Tips:
• Use appropriate data types for members:
• A String means an array of characters
• long and long int are the same
• Functions that are performing division should return a float/double.
• Do not forget to terminate the class definition with a ;
• Remember that class member functions can directly access the class data members. You do
not have to pass them as parameters.
• If the data member is a string use strcpy for assignment and strcmpi for comparing. For
other data types ( even char ) use = for assignment and == for comparing.
• Write public and not Public.
5.2.4 QUESTION 2 (d) Inheritance ( 4 Marks )
5.2.4.1 Revision Notes
Basics of Inheritance
• When a derived class inherits from a base class it can inherit in 3 ways : privately,
protectedly, publicly
•
In private inheritance the protected and public members of the base class become private
members of the derived class.
•
In protected inheritance the protected and public members of the base class become
protected members of the derived class.
•
In public inheritance the protected members of the base class become protected members
of the derived class and the public members of the base class become public members of
the derived class .
•
The private members of a base class reach the derived class and are visible inside the
derived class and occupy space in derived class objects but are not accessible within the
derived class.
Type of questions typically asked :
(a) Define a derived class on the basis of a given base class.
Use the syntax
class derived : visibility-mode( public/protected/private) base
{// add all the new derived class data and methods here.
};
(b) Identify the type of inheritance
• When one base class lends features to one derived class …. single inheritance.
• When many base classes lend features to one derived class ..... multiple inheritance.
• When one base class lends features to many derived classes ..... hierarchical
inheritance.
• When one base class lends features to one derived classes that lends features to
another class.... multilevel inheritance.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 141
• mix of hierarchical and multiple…..hybrid inheritance.
(c) Name members that can be accessed from a member function of some class.
• A class member function can access all the data members and member functions
defined within the class - private, protected as well as public. It can also access
itself.
• If the class is a derived class then it's member function can access all the data
members and member functions defined within the class - private, protected as well
as public. It can also access all the protected and public members of all it's base
classes. This is because the public and protected members of the base class are
accessible within a derived class.
Look for the member function in the class in which it was originally defined, not in an
inherited class.
(d) Name members that can be accessed from an object of some class.
• Using an object of a class one can only access the public members of that class.
This includes any members that may have become public members of the class due
to inheritance.
• If the derived class is not inheriting using the public mode, the answer will include
only the public members of the derived class.
• If the derived class is inheriting from a base class using the public mode, the answer
will include public members of the derived class as well as public members of the
base class.
Be careful about the kind of members asked
– data or methods or both.
(e) Give the space in bytes occupied by an object of some class.
• To calculate the space occupied by a class object sum up the space occupied by all
data members of that class and data members of all classes that lie in the class’s
inheritance hierarchy.
(f) Give the order of invocation of constructors and destructors.
• For constructors : base classes first ( in the order in which they are written)…then
the derived classes.
• For destructors : reverse of constructor invocation order.
5.2.4.2 Sample Solved Questions:
Consider the following class State :
class State
{
protected :
int tp;
public :
State( ) { tp=0;}
void inctp( ) { tp++;};
int gettp(); { return tp; }
};
Write a code in C++ to publically derive another class ‘District’ with the following
additional members derived in the public visibility mode.
Data Members :
Dname string
Distance float
Population long int
Member functions :
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 142
DINPUT( ) : To enter Dname, Distance and population
DOUTPUT( ) : To display the data members on the screen.
Ans.
class District : public State
{
public :
char Dname[20];
float Distance;
long int Population;
void DINPUT( )
{
gets(Dname);
cin>>distance;
cin>>Population;
}
void DOUTPUT( )
{
cout<<Dname<<endl;
cout<<Distance<<endl;
cout<<population<<endl;
}
};
(1 Mark for correct syntax for derived class header)
(½ Mark for writing public : )
(½ Mark for correct declaration of data members Dname ,Distance and Population)
(1 Mark for defining the function DINPUT( ) )
(1 Mark for defining the function DOUTPUT( ) )
(c) Answer the questions (i) to (iv) based on the following:
class Ground
{
int Rooms;
protected:
void Put();
public:
void Get();
};
class Middle : private Ground
{
int Labs;
public:
void Take();
void Give();
};
class Top : public Middle
{
int Roof;
public:
void In();
void Out();
};
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
4
Excellence
Page 143
void main()
{
Top T;
}
(i) Which type of Inheritance out of the following is illustrated in the above example?
− Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
Ans.
Multilevel Inheritance.
( 1 mark for correct answer )
(ii) Write the names of all the members , which are directly accessible by the member
function Give() of class Middle .
Ans.
Data Members :
Labs
Member Functions : Put(), Get(), Take(),
Give() - optional
( 1 mark for correct answer )
(iii) Write the names of all the members , which are directly accessible by the member
function Out() of class Top .
Ans.
Data Members :
Roof
Member Functions : Take(), Give(), In(),
Out() - Optional
( 1 mark for correct answer )
(iv) Write the names of all the members , which are directly accessible by the object T of
class Top declared in the main() function.
Ans. Take(), Give(), In() , Out()
( 1 mark for correct answer )
5.2.4.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20, 2018-19)
Answer the questions (i) to (iv) based on the following:
class Faculty
{
intFCode;
protected:
char FName[20];
public:
Faculty();
void Enter();
void Show();
};
class Programme
{
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 144
int PID;
protected:
char Title[30];
public:
Programme();
void Commence();
void View();
};
class Schedule: public Programme, Faculty
{
int DD,MM,YYYY;
public:
Schedule();
void Start();
void View();
};
void main()
{
Schedule S; //Statement 1
___________ //Statement 2
}
(i)
(ii)
(iii)
(iv)
Write the names of all the member functions, which are directly accessible by the object S of
class Schedule as declared in main() function.
Write the names of all the members, which are directly accessible by the member
functionStart( ) of class Schedule.
Write Statement 2 to call function View( ) of class Programme from the object S of class
Schedule.
What will be the order of execution of the constructors, when the object S of class Schedule is
declared inside main()?
Consider the following class State :
class State
{
protected :
inttp;
public :
State( ) { tp=0;}
void inctp( ) { tp++;};
intgettp(); { return tp; }
};
Write a code in C++ to publically derive another class ‘District’ with the following additional
members derived in the public visibility mode.
Data Members :
Dname string
Distance float
Population long int
Member functions :
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 145
DINPUT( ) : To enter Dname, Distance and population
DOUTPUT( ) : To display the data members on the screen.
CBSE Sample Paper ( 2017-18)
Answer the question from (i) to (iv) based on the given below code(assume all necessary header
files are included in program):-
(i) Write name of the class whose constructor is invoked first on the creation of a new object of
class Country.
(ii) Write name of the data members which are accessible through the object of class Country.
(iii) List name of the members which are accessible through the member function “void
New_Country()”.
(iv) What will be the size(in bytes) of an object of class Country & State respectively.
CBSE Sample Paper ( 2016-17)
Answer the questions (i) to (iv) based on the following:
classindoor_sports
{
inti_id;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 146
chari_name[20];
chari_coach[20];
protected:
inti_rank,i_fee;
voidget_ifee();
public:
indoor_sports();
voidiEntry();
voidishow();
};
classoutdoor_sports
{
into_id;
charo_name[20];
charo_coach[20];
protected:
intorank,ofee;
voidget_ofee();
public:
outdoor_sports();
voidoEntry();
voidoshow();
};
classsports:publicindoor_sports,protectedoutdoor_sports
{
char rules[20];
public:
sports();
void registration();
voidshowdata();
};
(i) Name the type of inheritance illustrated in the above C++ code.
(ii) Write the names of all the members, which are accessible from the objects belonging to class
outdoor_sports.
(iii) Write the names of all the member functions, which are accessible from the member function
of class sports.
(iv) What will be the size of the object belonging to class indoor_sports?
CBSE Sample Paper ( 2015-16)
Give the following class definition answer the question that is follow:
class University
{
char name [20];
protected :
charvc[20];
public :
voidestd();
voidinputdata();
voidoutputdata();
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 147
class College : protected University
{
intregno;
protected
char principal()
public :
intno_of_students;
voidreaddata();
voiddispdata ( );
};
class Department : public College
{
char name[20];
char HOD[20];
public :
voidfetchdata(int);
voiddisplaydata( );
}
i). Name the base class and derived class of college.
ii) Name the data member(s) that can be accessed from function displaydata().
iii)What type of inheritance is depicted in the above class definition?
iv) What will be the size of an object (in bytes) of class Department?
CBSE Sample Paper ( 2014-15)
Answer the questions (i) to (iv) based on the following code: [4]
class AC
{
char Model[10];
charDate_of_purchase[10];
char Company[20];
public;:
AC( );
voidentercardetail( );
voidshowcardetail( );
};
class Accessories : protected AC
{
protected:
char Stabilizer[30];
charAC_cover[20];
public:
float Price;
Accessories( );
voidenteraccessoriesdetails( );
voidshowaccessoriesdetails( );
};
class Dealer : public Accessories
{
intNo_of_dealers;
chardealers_name[20];
intNo_of_products;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 148
public:
Dealer( );
voidenterdetails( );
voidshowdetails( );
};
(i) How many bytes will be required by an object of class Dealer and class Accessories?
(ii) Which type of inheritance is illustrated in the above c++ code? Write the base class and
derived class name of class Accessories.
(ii) Write names of all the members which are accessible from the objects of class Dealer.
(iv) Write names of all the members accessible from member functions of class Dealer.
CBSE Sample Paper ( 2013)
Consider the following class counter:
class counter
{
protected :
unsignedint count;
public :
counter()
{ count = 0; }
voidinc_count()
{ count++; }
intget_count()
{ return count; }
};
Write code in C++ to publically derive another class new_counter from class counter. Class
new_counter should have the following additional function members in the public visibility mode:
(i) A parameterized constructor to initialize the value of count to the value of parameter.
(ii) dec_count() to decrease the value of data member count by 1.
(iii) Reset() to set the value of data member count to 0.
5.2.4.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Answer the questions (i) to (iv) based on the following :
class Ground
{
int
Rooms;
protected:
void Put();
public:
void Get();
};
class Middle : private Ground
{
int
Labs;
public:
void Take();
void Give();
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 149
};
class Top : public Middle
{
int
Roof;
public:
void In();
void Out();
};
void main()
{
Top T;
}
(i)
Which type of Inheritance out of the following is illustrated in
the above example ?
Single Level Inheritance, Multilevel Inheritance,
Multiple Inheritance
(ii)
Write the names of all the members, which are directly
accessible by the member function Give() of class Middle.
(iii)
Write the names of all the members, which are directly
accessible by the member function Out() of class Top.
(iv)
Write the names of all the members, which are directly
accessible by the object T of class Top declared in the main()
function.
Consider the following class HeadQuarter
class HeadQuarter
{
int Code; char
Des[20];
protected :
char Address[40];
public:
void Get(){cin>>Code;gets(Des);gets(Address);}
void Put(){cout<<Code<<Des<<Address<<endl;}
};
Write a code in C++ to protectedly derive another class FrontOffice from the base
class HeadQuarter with following members.
Data Members
Location of type character of size 10
Budget of type double
Member Functions
A constructor function to assign Budget as 100000 Assign()
to allow user to enter Location and Budget Display() to
display Location and Budget
CBSE All India – 2017
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 150
Answer the questions (i) to (iv) based on the following :
class First
{
int X1;
protected:
float X2;
public:
First();
void Enter1(); void Display1();
};
class Second : private First
{
int Y1;
protected:
float Y2;
public:
Second();
void Enter2();
void Display();
};
class Third : public Second
{
int Z1;
public:
Third();
void Enter3();
void Display();
};
void main()
{
Third T; //Statement 1
___________________; //Statement 2
}
(i) Which type of Inheritance out of the following is illustratedin the above example ?
Single Level Inheritance, Multilevel Inheritance, MultipleInheritance
(ii) Write the names of all the member functions, which aredirectly accessible by the object T of
class Third as declaredin main() function.
(iii) Write Statement 2 to call function Display() of class Secondfrom the object T of class Third.
(iv) What will be the order of execution of the constructors, whenthe object T of class Third is
declared inside main() ?
CBSE Delhi – 2017
Answer the questions (i) to (iv) based on the following :4
class One
{
int A1;
protected:
float A2;
public:
One();
void Get1(); void Show1();
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 151
};
class Two : private One
{
int B1;
protected:
float B2;
public:
Two();
void Get2();
void Show();
};
Class Three : public Two
{
int C1;
public:
Three();
void Get3();
void Show();
};
void main()
{
Three T; //Statement 1
__________; //Statement 2
}
(i) Which type of Inheritance out of the following is illustrated in the aboveexample ?
– Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
(ii) Write the names of all the member functions, which are directly accessible bythe object T of
class Three as declared in main( ) function.
(iii) Write Statement 2 to call function Show( ) of class Two from the object T ofclass Three.
(iv) What will be the order of execution of the constructors, when the object T ofclass Three is
declared inside main ( ) ?
CBSE Compartment – 2017
Answer the questions (i) to (iv) based on the following :4
class DIGITAL
{
int ID;
protected:
float Amount;
int Seconds;
public:
DIGITAL();
void Register(); void Disp();
};
class PRINT
{
int PID;
protected:
float Amount;
intSQinch;
public:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 152
PRINT();
void Get();
void Print();
};
class MEDIA : Public PRINT, private DIGITAL
{
int MID;
public:
MEDIA();
void Enter();
void Print();
};
void main()
{
MEDIA M; //Statement 1
__________; //Statement 2
}
(i) Which type of Inheritance out of the following is illustrated in the aboveexample ?
– Single Level Inheritance, Multilevel Inheritance, Multiple Inheritance
(ii) Write the names of all the member functions, which are directly accessible bythe object M of
class MEDIA as declared in main( ) function.
(iii) What will be the order of execution of the constructors, when the object M ofclass MEDIA is
declared inside main ( ) ?
(iv) Write Statement 2 to call function Print( ) of class PRINT from the object Mof class MEDIA.
CBSE Delhi – 2016
Answer the questions (i) to (iv) based on the following :
class PRODUCT
{
int Code;
char Item[20];
protected:
float Qty;
public:
PRODUCT();
voidGetIn(); void Show();
};
class WHOLESALER
{
intWCode;
protected:
char Manager[20];
public:
WHOLESALER();
void Enter();
void Display();
};
class SHOWROOM : public PRODUCT, private WHOLESALER
{
char Name[20],City[20];
public:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 153
SHOWROOM();
void Input();
void View();
};
(i) Which type of Inheritance out of the following is illustrated in the aboveexample ?
– Single Level Inheritance
– Multi Level Inheritance
– Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible fromthe member
functions of class SHOWROOM.
(iii) Write the names of all the member functions, which are directly accessible byan object of
class SHOWROOM.
(iv) What will be the order of execution of the constructors, when an object ofclass SHOWROOM
is declared ?
CBSE All India – 2015
Answer the questions (i) to (iv) based on the following :4
class Interior
{
intOrderId;
char Address[20]; protected: float Advance; public: Interior(); void Book(); void View(); };
classPainting:public Interior { intWallArea,ColorCode;
protected:
char Type;
public:
Painting();
voidPBook();
voidPView();
};
class Billing : public Painting
{
float Charges;
void Calculate();
public:
Billing();
void Bill();
voidBillPrint();
};
(i) Which type of Inheritance out of the following is illustrated in the above example ?
– Single Level Inheritance
– Multi Level Inheritance
– Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible from the member
functions of class Painting.
(iii) Write the names of all the member functions, which are directly accessible from an object of
class Billing.
(iv) What will be the order of execution of the constructors, when an object of class Billing is
declared ?
CBSE Delhi – 2015
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 154
Answer the questions (i) to (iv) based on the following :4
class Exterior
{
intOrderId;
char Address[20];
protected:
float Advance;
public:
Exterior();
void Book(); void View();
};
classPaint:public Exterior
{
intWallArea,ColorCode;
protected:
char Type;
public:
Paint();
voidPBook();
voidPView();
};
class Bill : public Paint
{
float Charges;
void Calculate();
public :
Bill();
void Billing();
void Print();
};
(i) Which type of Inheritance out of the following is illustrated in the aboveexample ?
– Single Level Inheritance
– Multi Level Inheritance
– Multiple Inheritance
(ii) Write the names of all the data members, which are directly accessible fromthe member
functions of class Paint.
(iii) Write the names of all the member functions, which are directly accessiblefrom an object of
class Bill.
(iv) What will be the order of execution of the constructors, when an object ofclass Bill is declared
?
CBSE Delhi – 2014
Consider the following C++ code and answer the questions from (i) to (iv):
Class Campus
{
long Id;
char City[20];
protected:
char Country l2O];
public : Campus O ;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 155
void Register O ;
void Display O ;
);
class Dept : private campus
{
IongDCode[ 101 ;
char HOD [20] ;
protected :
double Budgets ;
public:
Dept O ;
void Enter O ;
void Show0 ;
);
class Applicant: public Dept
{
longRegNo;
char Name [20] ;
public:
Applicant O ;
void Enroll O ;
void View O ;
}
(i)
Which type of Inheritance is shown in the above example ?
(ii)
Write the ruunes of those member functions, which are directly accessedfrom the
objects of class Applicant.
(iii) Write the names of those data manbers, which can be directly accessiblefrom the
member functions of class Applicant'
(iv)
Is it possible to dircctly call function Display( ) of class University from anobject of
class Dept ? (Answer as Yes or No).
5.2.4.5 Important Tips:
 Since this is a choice question now, choose the easier question. Defining a derived class
given a base class fetches more marks compared to the question based on application of
inheritance concepts as no partial marking is done in the latter.
 Read carefully what the question is asking you for : data members or methods or both.
Write only what is asked.
5.3 QUESTION 3 ( Topic: Data Structures) : ( 14 Marks )
5.3.1 QUESTION 3 (a,b) Program based on 1D/2D Array ( 2 +3 = 5 Marks )
5.3.1.1 Revision Notes
•
•
Prototype of a function that takes a 1 D array and it's size as input parameter is :
void function1 ( int A[], int size );
In the function definition now size must be used wherever the array dimension is required.
Practice the following 1D programs:
• Linear Traversal ( condition on index or element )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 156
•
•
•
•
•
•
Binary search
Selection, Insertion, Selection Sort
Merging
Concatenation
Insertion, Deletion of an element
Exchanging alternate elements, left and right halfs
•
Prototype of a function that takes a 2 D array and it's row and column dimensions as input
parameters is :
void function1 ( int A[20][20], int rsize, int csize );
In the function definition now rsize must be used wherever the array row dimension is
required and csize shoule be used wherever the array column dimension is required. If
the array is a square matrix pass only one size as a parameter.
•
Practice the following 2D programs:
•
Sum of diagonals
•
Pattern printing
•
Transpose
•
Exchanging first and last row/columns
•
Printing sum of middle row/column elements
• Printing row/column elements in reverse.
5.3.1.2 Sample Solved Questions:
Write a user-defined function that takes a 2D float array A and its size N as input
parameters and replaces all diagonal elements with their double and the remaining elements
with their half. For example if the content of array A is :
2
33.0
13.0
92.0
99.0
3.0
12.0
22.0
10.0
5.0
The changed array should be
66.0
6.5
184.0
49.5
6.0
6.0
44.0
5.0
10.0
NOTE:
 DO NOT DISPLAY the Changed Array contents
 Do not use any other array to transfer the contents of array A.
Ans.
void change ( float A[][4], int N )
{
int r, c;
for ( r=0; r<N; r++ )
{
for ( c=0; c<N; c++ )
{
if ( r == c || r+c == N-1 )
{
A[r][c] = A[r][c] *2;
}
else
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 157
A[r][c] = A[r][c] / 2;
}
}
}
( ½ mark for correct function header )
( ½ mark for correct array traversal )
( ½ mark for correctly checking for diagonal entries and updating)
( ½ mark for correctly updating non diagonal entries)
( Total = 2 marks )
(b) Write code for a function void Convert(int T[], int N) in C++, which repositions all the
elements of the array by shifting each of them to one position before and by shifting the
first element to the last position.
3
For Example : if the content of the array ARR is
0
1
2
3
4
10
20
30
40
50
the changed content should become
0
20
1
30
2
40
3
50
4
10
Ans.
void Convert( int T[], int N )
{
int save = T[0];
for ( int I = 0; i< N-1; i++ )
{
T[i] = T[i+1];
}
T[N-1] = save;
}
( ½ mark for saving the first element )
( 1 mark for correct loop)
( 1 mark for correct shifting )
( ½ mark for correct updation of last element )
5.3.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20,)
Write a user-defined function EXTRA_ELE(int A[ ], int B[ ], int N) in C++ to find and display the
extra element in Array A. Array A contains all the elements of array B but one more element extra.
(Restriction: array elements are not in order)
Example If the elements of Array A is 14, 21, 5, 19, 8, 4, 23, 11
and the elements of Array B is 23, 8, 19, 4, 14, 11, 5
Then output will be 21
Write a user defined function Reverse(int A[],int n) which accepts an integer array and its size as
arguments(parameters) and reverse the array.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 158
Example : if the array is 10,20,30,40,50 then reversed array is 50,40,30,20,10
Write a user-defined function AddEnd4(int A[][4],intR,int C) in C++ to find and display the sum
of all the values, which are ending with 4 (i.e., unit place is 4).
Write a user defined function in C++ to find the sum of both left and right diagonal elements
from a two dimensional array.
CBSE Sample Paper ( 2016-17)
Write the definition of a function grace_score (int score [], int size) inC++, which should check all
the elements of the array and give anincrease of 5 to those scores which are less than 40.
Example: if an array of seven integers is as follows:
45, 35, 85, 80, 33, 27, 90
After executing the function, the array content should be changed as follows:
45, 40, 85, 80, 38, 32, 90
CBSE Board – 2016( Delhi )
Write the definition of a function FixPay(float Pay[], int N) in C++, which shouldmodify each
element of the array Pay having N elements, as per the followingrules:
Existing
Pay
to
be
Value of Pay
changed to
If less than
100000
If
>=100000
<20000
If
>=200000
and
Add 25% in the
existing value
Add 20% in the
existing value
Add 15% in the
existing value
CBSE Sample Paper ( 2016-17)
1. Write a user-defined function swap_row(int ARR[ ][3],intR,int C) in C++ to swap the first
row values with the last row values:
For example if the content of the array is:
10 20 30
40 50 60
70 80 90
Then after function call, the content of the array should be:
70 80 90
40 50 60
70 80 90
CBSE Sample Paper ( 2015-16)
2. Write a function NewMAT(int A[][],intr,int c ) in C++, which accepts a 2d array of integer
andits size as parameters and divides all those array elements by 6 which are not in the
range 60 to600(both values inclusive) in the 2d Array .
CBSE Sample Paper ( 2014-15)
3. Write a function in C++ to print the sum of all the non-negative elements present on both
the diagonal of a two dimensional array passed as the argument to the function.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 159
CBSE Sample Paper ( 2015-16)
Write a function to sort any array of n elements using insertion sort . Array should be passed
as argument to the function
CBSE Sample Paper ( 2014-15)
Write a function SORTSCORE() in C++ to sort an array of structure IPL in descending order of score
using selection sort .
Note : Assume the following definition of structure IPL.
struct IPL
{
int Score;
charTeamname[20];
};
CBSE Sample Paper ( 2016-17)
4. Write a user-defined function swap_row(int ARR[ ][3],intR,int C) in C++ to swap the first
row values with the last row values:
For example if the content of the array is:
10 20 30
40 50 60
70 80 90
Then after function call, the content of the array should be:
70 80 90
40 50 60
70 80 90
CBSE Sample Paper ( 2015-16)
5. Write a function NewMAT(int A[][],intr,int c ) in C++, which accepts a 2d array of integer
andits size as parameters and divides all those array elements by 6 which are not in the
range 60 to600(both values inclusive) in the 2d Array .
CBSE Sample Paper ( 2014-15)
6. Write a function in C++ to print the sum of all the non-negative elements present on both
the diagonal of a two dimensional array passed as the argument to the function.
5.3.1.4 Questions From Previous Year Board Papers:
CBSE Board – 2019
Write a user-defined function NoTwoThree(int Arr[], int N) in C++, which should
display the value of all such elements and their corresponding locations in the array Arr
(i.e. the array index), which are not multiples of 2 or 3. N represents the total number of
elements in the array Arr, to be checked.
Example : If the array Arr
Ownership
contains 0
1
25
8
Integrity
2
3
4
12 49
9
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 160
Then the function should display the output as : 25 at location 0
49 at location 3
CBSE Board – 2018
Write the definition of a function SumEO(int VALUES[], int N) in C++, which should
display the sum of even values and sum of odd values of the array separately.
Example : If the array VALUES contains
25 20
22 21 53
Then the functions should display the output as :
Sum of even values = 42 (i.e., 20+22)
Sum of odd values = 99 (i.e., 25+21+53)
CBSE Board – 2009 ( Delhi)
Write a function SORTPOINTS( ) in C++ to sort an array of structure Game in descending order
of Points using Bubble Sort.
Note: Assume the following definition of structure Game
struct Game
{
longPno; // Player Number
charPName[20];
long Points;
};
Sample content of the array (before sorting)
Pno
Pname
Points
103
RitikaKapur
3001
104
JohnPhilip
2819
101
RaziaAbbas
3451
105
TarunKumar
2971
Sample content of the array (after sorting)
Pno
Pname
Points
101
RaziaAbbas
3451
103
RitikaKapur
3001
105
TarunKumar
2971
104
JohnPhilip
2819
Suppose X, Y, Z are arrays of integers of size M, N, M+N respectively. The numbers in array X
and Y appear in descending order. Write a user defined function in C++ to produce a third array Z
by merging X and Y in descending order
CBSE Board – 2016( Delhi )
Write definition for a function SHOWMID(int P[][5],intR,int C) in C++ to display the elements of
middle row and middle column from a two dimensional array P having R number of rows and C
number of columns.
For example, if the content of array is as follows:
1
1
1
1
1
15
12
16
01
25
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 161
1
03
1
01
1
21
1
1
1
02
1
85
09
09
The function should display the following as output :
103 101 121 102 101
116 121 109
1
01
1
60
1
72
CBSE Board – 2016 (Outside Delhi)
Write the definition of a function FixSalary(float Salary[], int N) in C++, whichshould modify
each element of the array Salary having N elements, as per thefollowing rules:
Existing
Required
Salary Values
Modification in Value
If less than
100000
If
>=100000
<20000
If
>=200000
and
Add 35% in the
existing value
Add 30% in the
existing value
Add 20% in the
existing value
CBSE Board – 2015 ( Delhi )
Write a function REVCOL (intP[] [5], int N, int M) in C++ to display the content of a two
dimensional array, with each column content in reverse order.
Note: Array may contain any number of rows.
For example, if the content of array is as follows:
1
1
5
4
5
5
2
6
5
1
1
9
9
8
6
3
1
2
7
3
1
2
6
4
8
1
3
1
6
1
The function should display output as :
11 23 61 46 81
13 91 92 87 63
15 12 56 45 51
CBSE Board – 2015 (Outside Delhi)
Write a function REVROW(int P[ ][5],intN,int M) in C++ to display the content of a two
dimensional array, with each row content in reverse order.
For example, if the content of array is as follows :
1
1
5
4
5
5
2
6
5
1
1
9
9
8
6
3
1
2
7
3
1
2
6
4
8
1
3
1
6
1
The function should display output as
51 45 56 12 15
63 87 92 91 13
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 162
81 46 61 23 81
CBSE Board – 2014
Write a user defined function SumLast3(int A[][4], int N, int M) in C++ to find and display the
sum of all values which are ending with 3 i.e. units place is 3. For example, if the content of the
array is
3
1
9
3
3
2
9
3
1
9
2
the output should be 49
CBSE Board – 2013
Write a user defined function DispNTen(int L[][4], int R, int C) in C++ to find and display all the
numbers which are not divisible by 10.
For Example : If the content of the array is:
2
1
3
0
7
0
1
1
1
2
9
0
Then the output will be
17 12 19
CBSE Board – 2012
Write a function ALTERNATE( int A[][3], int N, int M) in C++ to display all alternate elements
from 2 dimensional array A ( starting from A[0][0] ).
For Example :
If the array is containing:
23
54
76
37
19
28
62
13
19
The output will be
23
76
19
62
19
CBSE Board – 2011
Write a COLSUM ( ) function in C++ to find sum of each column of aNxM matrix.
CBSE Board – 2010
Write a function intSKIPSUM(int A[ ] [3], intN,int M) in C++ to find and return the sum of
elements from all alternate elements of a two-dimensional array starting from A[0][0].
Hint:
If the following is the content of the array
A[0][0]
A[0][1]
A[0][2]
4
5
1
A[1][0]
A[1][1]
A[1][2]
2
8
7
A[2][0]
A[2][1]
A[2][2]
9
6
3
The function SKIPSUM() should add elements A[0][0], A[0][2], A[1][l], A[2][0]
and A[2][2].
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 163
CBSE Board – 2009
Define a function SWAPCOL( ) in C++ to swap (interchange) the first columnelements with the
last column elements, for a two dimensional integer arraypassed as the argument of the function.
Example: If the two dimensional array contains
2149
1377
5863
7212
After swapping of the content of 1st column and last column, it should be:
9142
7371
3865
2217
CBSE Board – 2007
Write a function in C++ which accepts a 2D array of integers and its size asarguments and displays
the elements of middle row and the elements of middle column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 3×3, 5×5, 7×7 etc...]
Example, if the array content is
354
769
218
Output through the function should be :
Middle Row : 7 6 9
Middle Column : 5 6 1
CBSE Board – 2014 ( Delhi)
1. Write code for a function oddEven(int S, int N) in C++, to add 5 in all the odd values and
10 in all the even values of the array S.
For Example : if the original content of the array S is
2
2
7
3
1
2
5
0
2
2
the modified content will be
2
7
3
1
2
5
0
2
2
2
CBSE Board – 2013 ( Delhi)
2. Write code for a function void Convert(int T[], int N) in C++, which repositions all the
elements of the array by shifting each of them to one position before and by shifting the
first element to the last position..
For Example : if the content of the array ARR is
2
2
7
3
1
2
5
0
2
2
the changed content should become
2
7
3
1
2
5
0
2
2
2
CBSE Board – 2012 ( Delhi)
3. Write a function SWAP2BEST(int ARR[], int Size) .in C++ to modify the content of the
array in such a way that the elements having which are multiples of 10 swap with the value
present in the very next position in the array.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 164
Example : if the content of the array ARR is
90, 56, 65, 20, 34, 54
the content of the array ARR should become
56, 90, 45, 34. 20, 54
CBSE Board – 2011 ( Delhi)
4. Write a Get1From2( ) function in C++ to transfer the content from two arrays FIRST[ ] and
SECOND[ ] to array ALL[ ]. The even places (0, 2, 4,…) of array ALL[] should get the
content from the array FIRST[ ] and odd places (1,3,5,…) of the array ALL [ ]should get
the content from the array SECOND[ ] .
Example:
If the FIRST[ ] array contains
30, 60, 90
And the SECOND[ ] array contains
10, 50, 80
The ALL[ ] array should contain
30, 10, 60, 50, 90, 80
CBSE Board – 2010 ( Delhi)
5. Write a function CHANGEO in C++, which accepts an array of integer andits size as
parameters and divide all those array elements by 7 which are divisible by 7 and multiply
other-array elements by 3.
CBSE Board – 2007 ( Delhi)
6. Write a function in C++ which accepts an integer array and its size.as argumentsand
replaces elements having even values with its half and elements having oddvalues with
twice its value. 4
Example : if an array of five elements initially contains the elements as
3, 4, 5, 16, 9
then the function should rearrange the content of the array as
6, 2, 10, 8, 18
CBSE Board – 2006( Delhi)
7. Write a function in C++ that accepts an integer array and it's size as arguments and assigns
the elements into a 2d array of integers in the following format:
If the array is 1,2,3,4,5,6
If the array is 1,2,3
The resultant 2D array is given below:
The resultant 2D array is given below:
1
0
0
0
0
0
1
0
0
1
2
0
0
0
0
1
2
0
1
2
3
0
0
0
1
2
3
1
2
3
4
0
0
1
2
3
4
5
0
1
2
3
4
5
6
CBSE Board – 2005 ( Delhi)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 165
8. Given two arrays of integers X and Y of sizes m and n respectively, write a function named
MERGE() which will produce a third array named Z, such that the following sequence is
followed:
(a) All odd numbers of X from left to right are copied into Z from left to right.
(b) All even numbers of X from left to right are copied into Z from right to left.
(c) All odd numbers of Y from left to right are copied into Z from left to right.
(d) All even numbers of Y from left to right are copied into Z from right to left.
CBSE Paper ( 2017)
7. Write the definition for a function ADDMIDROW(int MAT[][10], int R, int C) in C++,
which finds the sum of the middle row elements of the matrix MAT ( Assuming C
represents number of columns and R represents the number of rows, which is an odd
integer )
For example, if the content of array MAT having R as 3 and C as 5 is as follows:
1
2
3
4
5
2
1
3
4
5
3
4
1
2
5
The function should calculate the sum and display the following:
Sum of Middle Row : 15
5.3.1.5 Important Tips:


Please write the function header correctly. It carries marks.
Practice all standard array programs and understand array traversal well.
5.3.2 QUESTION 3 (c) Address Computation ( 3 Marks )
5.3.2.1 Revision Notes
ROW MAJOR :
General Formula:
Array is A[L1..U1][L2..U2]
m = U1 - L1 + 1
n = U2 - L2 + 1
Addr of A[i] [j] = B + W ( n * ( i - L1 ) + ( j - L2 ) )
Specific Formula:
Array is A[m][n]
Addr of A[i] [j] = B + W ( n * i + j )
COLUMN MAJOR:
General Formula:
Array is A[L1..U1][L2..U2]
m = U1 - L1 + 1
n = U2 - L2 + 1
Addr of A[i] [j] = B + W ( m* ( j - L2 ) + ( i - L1 ) )
Specific Formula:
Array is A[m][n]
Addr of A[i] [j] = B + W ( m * j + i )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 166
Elements stored along the row implies use row major.
Elements stored along the column implies use column major.
5.3.2.2 Sample Solved Questions:
An array A[15][25] is stored in the memory along the column with each of its element occupying 2
bytes. Find out the base address and the address of an element A[10][15], if the location A[5][6] is
stored at address 5000.
3
Ans.
Addr of A[i][j] = B + W* ( m*j + i ) …….(in column major storage)
Given : i = 5 , j = 6, W = 2, m = 15, Addr of A[5][6] = 5000
To Find : B
5000 = B + 2 * ( 15*6 + 5 )
5000 = B + 2*(95) = B+190
B = 5000 – 190 = 4810
Now, Addr of A[10][15] = B + 2 * ( 15 * 15 + 10 )
= 4810 + 2 * (235) = 4810 + 470 = 5280
( ½ mark for formula for column major)
( ½ mark for substituting values)
(1 mark for computation of correct value of B)
( 1 mark for computation of correct value of Addr of A[10][15] )
( Total = 3 marks )
5.3.2.3 Questions From Sample Papers:
CBSE Sample Paper – 2019
An array S[10] [30] is stored in the memory along the column with each of its element occupying
2 bytes. Find out the memory location of S[5][10], if element S[2][15] is stored at the location
8200.
An array A[30][10] is stored in the memory with each element requiring 4 bytes of storage ,if the
base address of A is 4500 ,Find out memory locations of A[12][8], if the content is stored along
the row.
CBSE Sample Paper – 2016-17
An array P[30][20] is stored along the column in the memory with each element requiring 2 bytes
of storage. If the base address of the array P is 26500, find out the location of P[20][10].
CBSE Sample Paper – 2015-16
An integer array A [30][40] is stored along the column in the memory. If the element A[20][25] is
stored at 50000, find out the location of A[25][30].
5.3.2.4 Questions From Previous Year Board Papers:
CBSE Board – 2019
Let us assume P[20][10] is a two-dimensional array, which is stored in the memory
along the row with each of its elements occupying 2 bytes, find the address of the
element P[10][5], if the address of the element P[5][2] is 25000.
Let us assume P[20][30] is a two-dimensional array, which is stored in the memory
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 167
along the column with each of its elements occupying 2 bytes. Find the address of
the element P[5][6], if the base address of the array is 25000.
CBSE Board – 2018
Let us assume Data[20][15] is a two-dimensional array, which is stored in the memory
along the row with each of its elements occupying 2 bytes. Find the address of the
element Data[10][5], if the element Data[15][10] is stored at the memory location
15000.
5.3.2.5 Important Tips:


Please write out and perform calculations. Do not perform calculations mentally.
Writing the formula used is a must. Do not directly substitute values.
5.3.4 QUESTION 3 (d) Stacks and Queues ( 3 Marks )
5.3.4.1 Revision Notes
Practice code for :
• Push and Pop in an array based stack.
• Push and Pop in a linked Stack.
• Insert and Delete in an array based queue.
• Insert and Delete in a Linked Queue
• Insert and Delete in a circular Queue
Give declaration of the stack and of top and declaration of the queue and front and rear if not
already given in the question.
5.3.4.2 Sample Solved Questions:
Write a user-defined function Pop(Book B[], int &T) , which pops the details of a Book, from the
static stack of Book B, at the location T (representing the Top end of the stack), where every Book of
the stack is represented by the following structure:
3
struct Book
{
int Bno;
char Bname[20];
};
Ans.
// Function to pop a book from the stack
void Pop(Book B[],int &T)
{
if(T!=-1) // OR if (T>=0) OR if (T>-1)
{
cout<<B[T].Bno<<B[T].Bname<<endl;
T--; // --T;
}
else
cout<<"Stack Empty";
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 168
}
OR
void Pop(Book B[],int &T)
{
if(T==-1) // OR if (T<0)
cout<<"Stack Empty";
else
{
cout<<B[T].Bno<<B[T].Bname<<endl;
T--; // --T;
}
}
OR
void Pop(Book B[],int &T)
{
if(T==0)
cout<<"Stack Empty";
else
{
T--; // --T;
cout<<B[T].Bno<<B[T].Bname<<endl;
}
}
( 1 mark for check for stack empty )
( 1 mark for updating of top )
( 1 mark for correct printing of deleted element)
( Total = 3 marks )
(d) Write the definition of a member function INSERT() for a class QUEUE in C++, to
insert an employee in a dynamically allocated Queue of employees considering the following
employee structure.
3
struct EMPLOYEE
{
int eno;
char ename[20];
EMPLOYEE *Next;
};
Ans.
EMPLOYEE *F = NULL; // Queue Front
EMPLOYEE *R = NULL; // Queue Rear
// Function to insert an element into the queue
void INSERT()
{
// Dynamically allocate memory for one employee
EMPLOYEE * p = new EMPLOYEE;
// If memory is not available, return after printing an error msg
if (p == NULL)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 169
{
cout<<"\nMemory allocation failure";
return;
}
// If memory was allocated, initialize the newly created object
// with data entered by the user
cout<<”\nEnter Employee no”;
cin >>p->eno;
cout <<”\nEnter Employee name”;
gets(p->ename);
p->Next = NULL;
// If the queue was originally empty make both front and rear
// point to this newly created and initialized object and return.
if (F == NULL)
{
F = R = p;
return;
}
// Otherwise, attach the newly created object to the rear of the
// queue and update rear so that it points to this object.
R->Next = p;
R = p;
}
( ½ mark for creating new element)
( ½ mark for initializing new element)
( 1 mark for attaching it to the queue when q is empty)
( 1 mark for attaching it to queue when q is not empty)
( Total = 3 Marks )
5.3.4.3 Questions From Sample Papers:
CBSE Sample Paper ( 2019-20)
Write the definition of a member function Ins_Player() for a class CQUEUE in C++, to add a Player in a
statically allocated circular queue of PLAYERs considering the following code is already written as a
part of the program:
struct Player
{
long Pid;
char Pname[20];
};
constint size=10;
class CQUEUE
{
Player Ar[size];
int Front, Rear;
public:
CQUEUE( )
{
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 170
Front = -1;
Rear = -1;
}
void Ins_Player(); // To add player in a static circular queue
void Del_Player(); // To remove player from a static circular queue
void Show_Player(); // To display static circular queue
};
Write a function in C++ to delete a node containing Books information ,from a dynamically
allocated stack of Books implemented with the help of the following structure:
struct Book
{
intBNo;
charBName[20];
Book *Next;
};
CBSE Sample Paper ( 2016-17)
Write the definition of a member function push() for a class Library in C++ to insert a book
information in a dynamically allocated stack of books considering the following code is
already written as a part of the program:
struct book
{
intbookid;
charbookname[20];
book *next;
};
class Library
{
book *top;
public:
Library()
{
top=NULL;
}
void push();
void pop();
voiddisp();
~Library();
};
CBSE Sample Paper ( 2015-16)
Write the definition of functions for the linked implemented queue containing passenger
informationas follows:
struct NODE
{
intTicketno;
charPName[20];
NODE * NEXT;
};
classQueueofbus
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 171
{
NODE *Rear, *Front;
public:
Queueofbus()
{
Rear = NULL;
Front = NULL;
}
void Insert();
void Delete();
~Queueofbus()
{ cout<<"Object destroyed"; }
};
CBSE Sample Paper ( 2014-15)
Write a function in C++ to perform Insert operation in a circular Queue containing Player’s
information (represented with the help of an array of structure PLAYER).
struct PLAYER
{
long PID; //Player ID
charPname[20]; //Player Name
};
CBSE Sample Paper ( 2013)
Write a function in C++ to perform Insert operation in a circular Queue containing Player’s
information (represented with the help of an array of structure PLAYER).
struct PLAYER
{
long PID; //Player ID
charPname[20]; //Player Name
};
CBSE Sample Paper ( 2012)
Write a function in C++ to perform Push operation in a dynamically allocated stack
containing real numbers.
CBSE Sample Paper ( 2011)
Write a function in C++ to perform Insert operation in a circular Queue containing Player’s
information (represented with the help of an array of structure PLAYER).
struct PLAYER
{
long PID; //Player ID
charPname[20]; //Player Name
};
5.3.4.4 Questions From Previous Year Board Papers:
CBSE Board – 2019
For the following structure of Books in C++
struct Book
{
int
Bno;
char Bname[20];
Book *Link;
};
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 172
Given that the following declaration of class BookStack in C++ represents a
dynamic stack of Books :
class BookStack
{
Book *Top; //Pointer with address of Topmost Book of Stack
public:
BookStack()
{
Top = NULL;
}
void Push(); //Function to push a Book into the
dynamic stack
void Pop();
//Function to pop a Book from the
dynamic stack
~BookStack();
};
Write the
definition
for
the
member
function
void
BookStack::Push(), that pushes the details of a Book into the dynamic stack of
BookStack.
CBSE Board – 2018
Write the definition of a member function AddPacket() for a class QUEUE in C++, to
remove/delete a Packet from a dynamically allocated QUEUE of Packets considering
the following code is already written as a part of the program.
struct Packet
{
int
PID;
char
Address[20];
Packet
*LINK;
};
CBSE Board – 2017 ( Delhi)
Write the definition of a member function ADDMEM( ) for a class QUEUE inC++, to add a
MEMBER in a dynamically allocated Queue of Membersconsidering the following code is
already written as a part of the program.
struct Member
{
int MNO;
char MNAME[20];
Member *Next;
};
Class QUEUE
{
Member *Rear,*Front;
public:
QUEUE(){Rear=NULL;Front=NULL;}
void ADDMEM();
void REMOVEMEM();
~QUEUE();
};
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 173
CBSE Board – 2017 ( AI)
Write the definition of a member function PUSHGIFT() for a classSTACK in C++, to add a
GIFT in a dynamically allocated stack ofGIFTs considering the following code is already
written as a part ofthe program :
struct GIFT
{
int GCODE; //Gift Code
char GDESC[20]; //Gift Description
GIFT *Link;
};
class STACK
{
Gift *TOP;
public:
STACK(){TOP=NULL;}
void PUSHGIFT();
void POPGIFT();
~STACK();
};
CBSE Board – 2017 ( Compartment)
Write the definition of a member function PUSHBOOK( ) in C++ to addinformation of
BOOL in a static stack implemented using an array of structureBOOK (definition of struct
BOOK is defined below for reference).
struct BOOK
{
int BNO;
char TITLE[20];
};
CBSE Board – 2016( Delhi)
Write the definition of a member function INSERT() for a class QUEUE in C++, to
insert an ITEM in a dynamically allocated Queue of items considering the following
code is already written as a part of the program.
struct ITEM
{
int INO; char INAME[20];
ITEM *Link;
};
class QUEUE
{
ITEM *R,*F;
public:
QUEUE(){R=NULL;F=NULL;}
void INSERT();
void DELETE();
~QUEUE();
};
CBSE Board – 2016 (AI)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 174
Write the definition of a member function DELETE() for a class QUEUE in C++, to
remove a product from a dynamically allocated Queue of products considering the
following code is already written as a part of the program.
struct PRODUCT
{
int PID; char PNAME[20];
PRODUCT *Next;
};
class QUEUE
{
PRODUCT *R,*F;
public:
QUEUE(){R=NULL;F=NULL;}
void INSERT();
void DELETE();
~QUEUE();
};
CBSE Board – 2015 ( Delhi)
Write the definition of a member function Pop( ) in C++, to delete a book from adynamic
stack of TEXTBOOKS considering the following code is alreadyincluded in the program.
struct TEXTBOOKS
{
char ISBN[20];
char TITLE[80];
TEXTBOOKS *Link;
};
class STACK
{
TEXTBOOKS *Top;
public:
STACK(){Top=NULL;}
void Push();
void Pop();
~STACK();
};
CBSE Board – 2015 ( AI)
Write the definition of a member function PUSH( ) in C++, to add a new book in a dynamic
stack of BOOKS considering the following code is already included in the program : 4
struct BOOKS {
char ISBN[20], TITLE[80];
BOOKS *Link;
};
class STACK
{
BOOKS *Top;
public:
STACK(){Top=NULL;}
void PUSH();
void POP();
~STACK();
};
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 175
CBSE Board – 2014( Delhi )
Write a function POPBOOK( ) in C++ to perform delete operation from aDynamic Stack,
which contains Bno and Title. Consider the following definitionof NODE, while writing your
C++ code.
struct. NODE
{
intBno,
char Title [20] ;
NODE *Link;
};
CBSE Board – 2014 ( AI )
Write a function PUSHBOOK( ) in C++ to perform insertoperation on a Dynamic Stack,
which contains Book_no andBook_Title. Consider the following definition of NODE,
whilewriting your C++ code.
struct NODE
{
intBook_No;
charBook_Title[20];
NODE *Next;
};
CBSE Board – 2014 ( Compartment )
Define member function delque() to perform delete operation on alinked queue where each
node has the following structure :
struct node
{
char name[20]
int marks;
node *link;
};
class queue
{
node *front,*rear;
public:
queue() {front=rear=NULL;
}
voiddelque();
};
CBSE Board – 2013
Write a function QINSERT( ) in C++ to perform insert operation on a linked Queue which
contains Client no and Client Name. Consider the following definition of NODE, in the code
for QINSERT().
struct NODE
{
longintCno;
charCname[20];
NODE *Next;
};
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 176
CBSE Board – 2013 ( Compartment )
Give the necessary declaration for linked implemented queue containing player information (
as defined in the following definition of node ). Also write a user defined function in C++ to
delete one players information from the queue.
struct NODE
{
intPlayerno;
charPlayername[20];
NODE *Link;
};
CBSE Board – 2012
Write a function in C++ to perform insert operation in a static circular Queue containing
books information ( represented with the help of an array of structure BOOK).
struct BOOK
{
longAccno;
char Title20];
};
CBSE Board – 2011
Write a function in C++ to perform Insert: operation on a dynamically allocated Queue
containing Passenger details as given in the following definition of NODE.
struct NODE
{
longPno; //passenger Number
charPname[20] ; //passenger Name
NODE *Link.;
};
CBSE Board – 2010
Write a complete program in c++ to implement a dynamically allocated Stack containing
names of Countries.
CBSE Board – 2009
Write a function QUEINS( ) in C++ to insert an element in a dynamically allocated Queue
containing nodes of the following given structure:
struct Node
{
intPId; // Product Id
charPname[20];
NODE *Next;
};
CBSE Board – 2007
Write a function in C++ to delete a node containing customer’s information, from a
dynamically allocated Queue of Customers implemented with the help of the following
structure :
struct Customer
{
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 177
intCNo;
charCName[20];
Customer *Link;
};
CBSE Board – 2006
class queue
{
int data [10];
int front, rear;
public:
queue ( ) (front= -1; rear= -1;)
void add( ); //to add an element into the queue
void remove( ); //to remove an element from the queue
void Delete(int ITEM); //To delete all elements which are equal to ITEM
};
Complete the class with all function definitions for a circular array Queue. Use another
queue to transfer data temporarily.
Write a function in C++ to perform Push operation on a dynamically allocated stack
containing real number.
5.3.4.5 Important Tips:
•

Read the question carefully and check if it is an array based data structure or a linked data
structure and answer accordingly.
This is a choice question. Please select the easier question to attempt.
5.3.5 QUESTION 3 (e) Infix Postfix Expressions ( 2 Marks )
5.3.5.1 Revision Notes
Infix and Postfix
• Check if the question requires translation of infix to postfix or evaluation of postfix.
• Order of prcedence is
• ^
>
*, /
>
+, • Not >
And >
Or
• You can push an operator on the stack only when its precedence is strictly greater than the
precedence of the stack top.
• Be careful of the order of evaluation of popped out operands.
5.3.5.2 Sample Solved Questions:
Convert the following infix expressions to postfix using a stack and show the
contents of the stack at each step:
(True OR False) AND NOT False AND True
Ans.
Expr
Action
Element
(
Push
True
Print
Ownership
Integrity
Stack
Result
(
(
True
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
2
Page 178
OR
False
)
AND
NOT
False
AND
True
End of
expr
Push
Print
Pop & print
till (
Push
Push
Print
Pop, Pop,
Push
Print
Pop & print
till stack
empty
( OR
( OR
8
True False
True False OR
AND
AND NOT
AND NOT
AND
True False OR
True False OR
True False OR False
True False OR False NOT AND
AND
True False OR False NOT AND True
True False OR False NOT AND True AND
( 1 mark for correct stack contents at each step )
( 1 mark for correct answer )
( No marks to be given for the answer if the steps are incorrect )
( Total = 2 marks )
(e) Evaluate the following postfix expression using a stack and show the contents of the
stack at each step:
2
50,36,9,/,5,2,^,*,20,/,Ans.
Expression Action
Stack
Result
Element
50
Push
50
36
Push
50,36
9
Push
50,36,9
/
Pop 9. Pop 36. Evaluate
50,4
36/9 = 4. Push 4.
5
Push
50,4,5
2
Push
50,4,5,2
^
Pop 2, Pop 5. Evaluate
50,4,25
5^2=25. Push 25
*
Pop 25, Pop 4. Evaluate
50,100
4^25=100. Push 100
20
Push
50,100,20
/
Pop 20, Pop 100. Evaluate 50,5
100/20=5. Push 5
Pop 5, Pop 50. Evaluate
45
50-5=45. Push 45
End of expr Pop & print the result from
45
the stack.
(Result)
( 1 mark for correct stack contents at each step )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 179
( 1 mark for correct answer )
( or 1 mark for correctly evaluating up to 2 operators )
( No marks to be given for the answer if the steps are incorrect )
( Total = 2 marks )
5.3.5.3 Questions From Sample Papers:
CBSE Sample Paper– 2018
Evaluate the following POSTFIX expression. Show the status of Stack after execution of each
operation separately:
TRUE, FALSE, OR, NOT, TRUE, FALSE, AND, OR
CBSE Sample Paper– 2017
Evaluate the following POSTFIX expression. Show the status of Stack after execution of each
operation separately:
45, 45, +, 32, 20, 10, /, -,*
5.3.5.4 Questions From Previous Year Board Papers:
CBSE Board – 2019
Evaluate the following Postfix expression, showing the stack contents :
250,45,9,/,5,+,20,*,OR
Convert the following Infix expression to its equivalent Postfix expression, showing the
stack contents for each step of conversion :
A+B*C^D-E
CBSE Board – 2018
Convert the following Infix expression to its equivalent Postfix expression, showing the
stack contents for each step of conversion :
U * V + (W – Z) / X
CBSE Board – 2017
Convert the following Infix expression to its equivalent Postfix expression, showing the stack
contents for each step of conversion.
2
P+(Q–R)*S/T
CBSE Board – 2016
Convert the following Infix expression to its equivalent Postfix expression, showing the stack
contents for each step of conversion.
2
A/(B+C)*D–E
5.3.5.5 Important Tips:



This is a choice question. Please select the easier question to attempt.
Pop out operands from the stack in the correct order.
Rememeber that an operator can be pushed into the stack only if it has a greater
precedence.
5.4 QUESTION 4 ( Topic: Data File Handling) : ( 6 Marks )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 180
5.4.1 QUESTION 4 (a) Text File Handling ( 2 Marks )
5.4.1.1 Revision Notes
Statement to open file for reading is :
ifstream ifile ( “Textfile.dat” );
Statement to open file for writing is :
ofstream ofile ( “Textfile.dat”);
Statement to read a character from the file into a character variable ch is :
ifile.get ( ch );
Statement to read a line from the file into a character array line of size SIZE is :
ifile.getline ( line, SIZE );
Statement to read a word from the file into a character array word of size SIZE is :
ifile >> word;
Statement to write a character ch into the file is :
ofile.put ( ch );
Statement to write a line stored in a character array line into the file is :
ofile.write ( line, strlen( line ));
Statement to close a file is :
ifile.close();
5.4.1.2 Sample Solved Questions:
Polina Raj has used a text editing software to type some text in an article. After saving the article
as MYNOTES.TXT, she realized that she has wrongly typed alphabet K in place of alphabet C
everywhere in the article.
Write a function definition for PURETEXT() in C++ that would display the corrected version of
the entire article of the file MYNOTES.TXT with all the alphabets “K” to be displayed as an
alphabet “C” on screen.
2
Note : Assuming that MYNOTES.TXT does not contain any C alphabet otherwise.
Example :
If Polina has stored the following content in the file MYNOTES.TXT :
I OWN A KUTE LITTLE KAR.
I KARE FOR IT AS MY KHILD.
The function PURETEXT() should display the following content :
I OWN A CUTE LITTLE CAR.
I CARE FOR IT AS MY CHILD.
Ans.
void PURETEXT()
{
ifstream ifile("MYNOTES.txt");
if(!ifile)
{
cout<<"\n Error in open";
return;
}
char ch;
while(1)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 181
{
ifile.get(ch);
if(ifile.eof())
{
break;
}
if (ch == ‘K’)
cout<<”C”;
else
cout << ch;
}
ifile.close();
}
( ½ mark for opening the files in appropriate mode)
( ½ mark for reading each character)
( ½ mark for comparing with ‘K’ and printing ‘C’)
( ½ mark for printing other characters)
( Total = 2 marks.)
5.4.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2016-17)
Write a user defined function word_count() in C++ to count how many words are present in a text
file named “opinion.txt”.
For example, if the file opinion.txt contains following text:
Co-education system is necessary for a balanced society. With co-education system, Girls
and Boys may develop a feeling of mutual respect towards each other.
The function should display the following:
Total number of words present in the text file are: 24
CBSE Sample Paper ( 2015-16)
Write a function RevText() to read a text file “ Input.txt “ and Print only word starting with ‘I’ in
reverse order .
Example: If value in text file is: INDIA IS MY COUNTRY
Output will be: AIDNI SI MY COUNTRY
CBSE Sample Paper ( 2014-15)
Write a function in C++ to count the number of lines starting with a digit in a text file
“DIARY.TXT”.
5.4.1.4 Questions From Previous Year Board Papers:
CBSE Board – 2019
A text file named MESSAGE.TXT contains some text. Another text file named
SMS.TXT needs to be created such that it would store only the first 150 characters
from the file MESSAGE.TXT. Write a user-defined function LongToShort() in C++
that would perform the above task of creating SMS.TXT from the already existing file
MESSAGE.TXT.
OR
A text file named CONTENTS.TXT contains some text. Write a user-defined function
LongWords() in C++ which displays all such words of the file whose length is
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 182
more than 9 alphabets. For example : if the file CONTENTS.TXT contains :
"Conditional statements of C++ programming language are if and switch"
Then the function LongWords() should display the output as :
Conditional
statements
programming
CBSE Board – 2018
A text file named MATTER.TXT contains some text, which needs to be displayed such
that every next character is separated by a symbol ‘#’.
Write a function definition for HashDisplay() in C++ that would display the entire content
of the file MATTER.TXT in the desired format.
Example :
If the file MATTER.TXT has the following content stored in it :
THE WORLD IS ROUND
The function HashDisplay() should display the following content :
T#H#E# #W#O#R#L#D# #I#S# #R#O#U#N#D#
CBSE Board – 2016
Write function definition for WORD4CHAR() in C++ to read the content of a text file FUN.TXT ,
and display all those words, which has four characters in it
Example: If the content of the file fun.TXT is as follows:
When I was a small child, I used to play in the garden
with my grand mom. Those days were amazingly funful
and I remember all the moments of that time
The function WORD4CHAR() should display the following:
When used play with days were that time
CBSE Board – 2015
Write function definition for SUCCESS( ) in C++ to read the content of a text file STORY.TXT,
count the presence of word STORY and display the number of occurrence of this word. Note:
– The word STORY should be an independent word
– Ignore type cases (i.e. lower/upper case)
Example: If the content of the file STORY.TXT is as follows:
Success shows others that we can do it. It is possible to achieve success with hard work.
Lot of money does not mean SUCCESS.
The function SUCCESS( ) should display the following:
3
CBSE Board – 2014
Write a function EUCount ( ) in C++, which should read each character of a text file IMP.TXT,
should count and display the occurrence of alphabets E and U (including small cases e and u too).
CBSE Board – 2013
Write a function CountYouMe() in C++ which reads the contents of a text file story.txt and counts
the words You and Me (not case sensitive).
For example, if the file contains:
You are my best friend.
You and me make a good team.
The function should display the output as
Count for You: 2
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 183
Count for Me: 1
CBSE Board – 2012
Write a function in C++ to read the content of a text file “DELHI.TXT” and display all those lines
on screen,which are either starting with ‘D’ or starting with ‘M’.
CBSE Board – 2004
Assuming that a text file named FIRST.TXT contains some text written into it, write a function
named vowelwords( ), that reads the file FIRST.TXT and creates a new file
named SECOND.TXT, to contain only those words from the file FIRST.TXT which start with start
with a lowercase vowel (i.e. with ‘a’, ’e’, ’I’, ‘o’, ‘u’).
For example if the file FIRST.TXT contains
Carry umbrella and overcoat when it rains
Then the file SECOND.TXT shall contain:
umbrella and overcoat it
CBSE Board – 2002
Write a C++ program, which initializes a string variable to the content “Time is a great teacher but
unfortunately it kills all its pupils. Berlioz” and outputs the string one character at a time to the
disk file OUT.TXT.You have to include all the header files if required.
5.4.1.5 Important Tips:


Please write the syntax of the open, getline/get/>>, write/put, close functions correctly.
Majority of the marks are for these commands.
Read the question carefully and determine if it requires you to read line by line, character
by character or word by word before attempting the question.
5.4.2 QUESTION 4 (b) Binary File Handling ( 3 Marks )
5.4.2.1 Revision Notes
Statement to open file for reading is :
ifstream ifile ( “Binfile.dat”, ios::binary );
Statement to open file for writing is :
ofstream ofile ( “Binfile.dat”, ios::binary );
Statement to read a file record into an object ob is :
ifile.read ( (char * ) &ob, sizeof(ob) );
Statement to write the contents of an object ob into the file is :
ofile.write ( (char * ) &ob, sizeof(ob) );
Statement to close a file is :
ifile.close();
5.4.2.2 Sample Solved Questions:
Given a binary file APPLY.DAT, containing records of the following class type:
class Applicant
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 184
{
char
char
int
A_Rno[10];
A_Name[30];
A_Score;
public:
void Enrol()
{
gets(A_Rno); gets(A_Name); cin>>A_Score;
}
void Status()
{
cout<<setw(12)<<A_Rno;
cout<<setw(32)<<A_Name;
cout<<setw(3)<<A_Score<<endl;
}
int returnscore()
{
return A_Score;
}
void updatescore(int incr)
{
A_Score + = incr;
}
};
Write a function in C++ that reads the contents of file APPLY.DAT and increases by 10
the Ascore of those students whose A_Score is below 70.
3
Ans. void increase()
{
fstream file("APPLY.DAT", ios::binary|ios::in|ios::out);
if(!file)
{
cout<<"\n Error in open";
return;
}
Applicant A;
int recno = 0;
while(1)
{
file.read( ( char *) &A, sizeof(A) );
if(file.eof())
{
break;
}
if (A.returnscore() < 70 )
{
A.updatescore(10);
file.seekp(recno*sizeof(A));
file.write( (char *)&A, sizeof(A) );
}
recno++;
}
file.close();
}
( ½ mark for opening the files in appropriate mode)
( ½ mark for reading each record)
( 1 mark for checking and updating score)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 185
( ½ mark for correct seekp)
( ½ mark for correct write)
5.4.2.3 Questions From Sample Papers:
5.4.2.4 Questions From Previous Year Board Papers:
Write a function in C++ to search and display details, whose destination is “Cochin” from binary
file “Bus.Dat”. Assuming the binary file is containing the objects of the following class:
class BUS
{
intBno; // Bus Number
char From[20]; // Bus Starting Point
char To[20]; // Bus Destination
public:
char * StartFrom ( ); { return From; }
char * EndTo( ); { return To; }
void input() { cin>>Bno>>; gets(From); get(To); }
void show( ) { cout<<Bno<< “:”<<From << “:” <<To<<endl; }
};
Given a binary file APPLY.DAT, containing records of the following class type:
class Applicant
{ char A_Rno[10];
char A_Name[30];
int
A_Score;
public:
voidEnrol()
{
gets(A_Rno); gets(A_Name); cin>>A_Score;
}
void Status()
{
cout<<setw(12)<<A_Rno;
cout<<setw(32)<<A_Name;
cout<<setw(3)<<A_Score<<endl;
}
intreturnscore()
{
returnA_Score;
}
};
Write a function in C++ that reads the contents of file APPLY.DAT and displays the details of
those students whose A_Score is below 70.
Consider the following class declaration:
class person
{ protected :
char name[40];
int
age;
public:
voidgetdata(){
cout<< “Enter name:”; cin>> name;
cout<< “Enter age:”; cin>>age;
}
voidshowdata(){
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 186
cout<< “\nName:” << name;
cout<< “\nAge:” << age;
}
};
Assume that a file “Person.dat” stores records of the type person. Write a program in C++ that
prints the total number of records of the type person in the file “Person.dat”.
A binary file “EMPLOYEE.DAT” containing EMPNO(employee number), WRATE(hourly wage
rate), NOH(number of hours worked/week) fields. Write a C++ function to read each record,
compute weekly wage as WRATE*NOH and display EMPNO, WRATE, NOH, WRATE*NOH.
Assuming the class DRINKS defined below, write C++ functions to do the following:
(a) Write the objects of DRINKS to a binary file.
(b) Read the objects of DRINKS from binary file and display them on screen when DNAME
has value “INDY COLA”.
class DRINKS
{
int
DCODE;
char DNAME[13];
// name of the drink
int
DSIZE;
// size in litres
float DPRICE;
public :
void getdrinks() { cin>> DCODE>>DNAME>>DSIZE>>DPRICE;}
void showdrinks()
{ cout<<DCODE<<DNAME<<DSIZE<<DPRICE<<endl;}
char *getname() {return DNAME;}
};
Consider the following class declaration:
class employee
{
int
code;
char name[20];
float salary;
public : void input() {cin>> code >> name >> salary}
void show() { cout<< code << name << salary <<endl;}
float retsal() { return salary;}
};
Give function definitions to do the following:
(i)
Write the objects of employee to a binary file.
(ii)
Read the objects of employee from a binary file and display all objects on the screen
where salary is between Rs.10,000 and Rs. 20,000.
Write a function in C++ to search and display details, whose destination is “Chandigarh”from
binary file “Flight.Dat”. Assuming the binary file is containing the objects of the following class:
class FLIGHT
{
intFno; // Flight Number
char From[20]; // Flight Starting Point
char To[20]; // Flight Destination
public:
char * GetFrom ( ); { return from; }
char * GetTo( ); { return To; }
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 187
void input() { cin>>Fno>>; gets(From); get(To); }
void show( ) { cout<<Fno<< “:”<<From << “:” <<To<<endl; }
};
5.4.2.5 Important Tips:

Please write the syntax of the open, read, write, close functions correctly. Majority of the
marks are for these commands.
5.4.3 QUESTION 4 (c) Theory/Output ( 1 Mark )
5.4.3.1 Revision Notes
Command to move the file pointer to the end of the file
File.seekp( 0, ios::end);
Command to psition the file pointer at the beginning of the nth record
File.seekp( (n – 1 ) * sizeof (classobj ) );
Command to count the number of records in a binary file
File.seekg( 0, ios::end);
int n = File.tellg();
int records = n / sizeof( classobj );
Remember that each read command automatically moves the file pointer to the beginning of
the next record.
In a typical file handling loop for modification that looks like this : ( Note that recordsRead++
has been done at the beginning of the loop )
int recordsRead = 0, found = 0;
while(!found && File .read((char*) & i , sizeof (i)))
{
recordsRead++;
if(i . getStudent_no( ) = = y )
{
i . change_mark( );
_________________________//Missing statement 1
_________________________//Missing statement 2
found = 1;
}
}
Statement 1 would be : File.seekp( ( recordsRead – 1 ) * sizeof(i) );
Statement 2 would be : File.write( ( char * ) &i, sizeof(i) );
In a typical file handling loop for modification that looks like this : : ( Note that recordsRead++
has been done at the end of the loop )
int recordsRead = 0, found = 0;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 188
while(!found && File .read((char*) & i , sizeof (i)))
{
if(i . getStudent_no( ) = = y )
{
i . change_mark( );
_________________________//Missing statement 1
_________________________//Missing statement 2
found = 1;
}
recordsRead++;
}
Statement 1 would be : File.seekp( recordsRead * sizeof(i) );
Statement 2 would be : File.write( ( char * ) &i, sizeof(i) );
If recordsRead has not been given
int found = 0;
while(!found && File .read((char*) & i , sizeof (i)))
{
if(i . getStudent_no( ) = = y )
{
i . change_mark( );
_________________________//Missing statement 1
_________________________//Missing statement 2
found = 1;
}
}
Statement 1 would be : File.seekp( -1 * sizeof(i), ios::cur );
Statement 2 would be : File.write( ( char * ) &i, sizeof(i) );
5.4.3.2 Sample Solved Questions:
Find the output of the following C++ code considering that the binary file
PRODUCT.DAT exists on the hard disk with a list of data of 500 products.
class PRODUCT
{
int PCode;char PName[20];
public:
void Entry();void Disp();
};
void main()
{
fstream In;
In.open("PRODUCT.DAT",ios::binary|ios::in);
PRODUCT P;
In.seekg(0,ios::end);
cout<<"Total Count: "<<In.tellg()/sizeof(P)<<endl;
In.seekg(70*sizeof(P));
In.read((char*)&P, sizeof(P));
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
1
Page 189
In.read((char*)&P, sizeof(P));
cout<<"At Product:"<<In.tellg()/sizeof(P) + 1;
In.close();
}
Ans. Total Count:500
At Product: 73
(½ Mark for each correct value of In.tellg()/sizeof(P) as 500 and
73 respectively)
OR
Differentiate between ios::app and ios::ate modes.
1
Ans. ios:: app means start reading or writing at end of file. Thus, though the file
pointer is at the beginning of the file during file open every read / write moves it to
eof. Hence records can only be added at the end of the file beyond the existing
records.
ios:: ate moves the file pointer to eof on open. Later, however, the file pointer can be moved
elsewhere using seekp() or seekg() and oen can write/read anywhere.
( 1 Mark for the correct difference)
5.4.3.3 Questions From Sample Papers:
5.4.3.4 Questions From Previous Year Board Papers:
CBSE Board -2019
Find the output of the following C++ code considering that the binary file
STOCK.DAT exists on the hard disk with the following
5 records for the class
STOCK containing Name and Price.
Name
Price
Rice
110
Wheat
60
Cheese
200
Pulses
170
Sauce
150
void main()
{ fstream File
File.open("STOCK.DAT",ios::binary|ios::in); Stock S;
for (int I=1; I<=2; I++)
{
File.seekg((2*I-1)*sizeof(S));
File.read((char*)&S, sizeof(S));
cout<<"Read : "<<File.tellg()/sizeof(S)<<endl;
}
File.close();
}
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 190
CBSE Board -2018
Find the output of the following C++ code considering that the binary file
SCHOOLS.DAT exists on the hard disk with the following records of
10 schools of the class SCHOOLS as declared in
the previous question (4 b).
SCode
SName
NOT
1001
Brains School
100
1003
Child Life School
115
1002
Care Share School
300
1006
Educate for Life School
50
1005
Guru Shishya Sadan
195
1004
Holy Education School
140
1010
Play School
95
1008
Innovate Excel School
300
1011
Premier Education School
200
1012
Uplifted Minds School
100
void main()
{
fstream SFIN; SFIN.open("SCHOOLS.DAT",ios::binary|ios::in);
SCHOOLS S;
SFIN.seekg(5*sizeof(S));
SFIN.read((char*)&S, sizeof(S));
S.Display();
cout<<"Record :"<<SFIN.tellg()/sizeof(S) + 1<<endl; SFIN.close();
}
5.4.3.5 Important Tips:


Do a manual code walkthrough to figure out the output.
It is better to attempt the theory question in case you know the answer as chances of
making an error in an output question are more.
5.5 QUESTION 5 ( Topic: Data Base Management System) : ( 8 Marks )
5.5.1 QUESTION 5 (a) DBMSTheory ( 2 Marks )
5.5.1.1 Revision Notes
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 191
Concept of Candidate Key, Primary Key , Alternate Key
CANDIDATE KEY
 The set of all possible non null and unique column(s) of a relation/table that can
be used for uniquely identifying a row of the relation/table.
 A table can have many candidate keys.
 One of the candidate keys is designated as a Primary Key.
PRIMARY KEY
 A non null and unique column(s) of a relation/table which is used for uniquely
identifying a row/tuple of the relation/table.
 A table can have only one Primary Key.
 The Primary key can have only one attribute ( e.g. admission no ) or multiple
attributes ( first name, last name ).
ALTERNATE KEY
 The set of all possible non null unique column(s) of a relation/table that can be
used but are not used for uniquely identifying a row/tuple of the relation/table.
 An alternate key is the candidate key that is not the Primary key.
 A table can have multiple alternate keys.
 Example of Candidate Key, Primary Key , Alternate Key

Student Table
Admn_no
Name
Roll_no
Marks
1001
Piyush
1
85
1002
Nirmal
2
92
1003
Priyanshi
3
85
 Consider a student table that holds information about students of a class in a school.
 The columns Admn_no, Name, Roll_no are all unique and non null. These constitute the
Candidate Keys.
 We select the Admn_no column to uniquely identify rows of this table. This is the Primary
Key.
 The remaining columns Name and Roll_no are the alternate keys.
 Note that the column is not a key at all as entries in this column are not unique.
Concept of Foreign Key:
 A column of a table which derives its values from the primary key column of another table
i.e. a column of a table that is a primary key of another table.
 A Foreign key is for linking together tables and implements referential integrity.
Referential Integrity is the property of a relational database which ensures that no entry in
a foreign key column of a table can be made unless it matches a primary key value in the
corresponding column of the related table.
 One table can have multiple foreign keys.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 192
Table A
Admn_no
Name
Rollno
Marks
1001
Piyush
1
85
1002
Nirmal
2
92
Table B
SportsId
Game
Incharge
s1
Hockey
1001
s2
Tennis
1001
s3
Judo
1002
The column Incharge is the foreign key in Table B. It derives its values from the primary key
column Admn_no of Table A.
Concept of Degree and Cardinality:
DEGREE
 Total number of columns of a table / total number of attributes of a relation.
CARDINALITY:
 Total number of rows of a table/ total number of tuples in a relation.
Student Table
Admn_no
Name
Roll_no
Marks
1001
Piyush
1
85
1002
Nirmal
2
92
1003
Priyanshi
3
85
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 193
The degree of the student table = 4
The cardinality of the student table = 3
Concept of Cartesian Product:
 The Cartesian product of two relations A and B is obtained by joining each row of A
with every row of B and is represented by AXB.
 Degree of AXB = degree of A + degree of B.
 Cardinality of A X B = Cardinality of A X Cardinality of B.
Table A
Admn_no
Name
Rollno
Marks
1001
Piyush
1
85
1002
Nirmal
2
92
Table B
Admn_no
Game
1001
Hockey
1002
Tennis
Table A X B
Admn_no
Name
Rollno
Marks
Admn_no
Game
1001
Piyush
1
85
1001
Hockey
1002
Nirmal
2
92
1001
Hockey
1001
Piyush
1
85
1002
Tennis
1002
Nirmal
2
92
1002
Tennis
Concept of Union:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 194
 The union of 2 union compatible relations A and B ( A union B) is the set of all tuples t
such that t belongs to either A or B or both.
Table A
Admn_no
Name
Rollno
Marks
1001
Piyush
1
85
1002
Nirmal
2
92
1003
Gunjan
3
85
Table B
Admn_no
Name
Rollno
Marks
1004
Madhu
1
75
1005
Pihu
2
99
Admn_no
Name
Rollno
Marks
1001
Piyush
1
85
1002
Nirmal
2
92
1003
Gunjan
3
85
1004
Madhu
1
75
1005
Pihu
2
99
Table A U B
Concept of Selection and Projection:
SELECTION
 A horizontal subset of a table.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 195
 A subset of tuples within the relation that satisfy a specific condition.
PROJECTION
 A vertical subset of a table.
 A subset obtained by selecting specified attributes in a specified left-to-right order.
Student Table
Admn_no
Name
Roll_no
Marks
1001
Piyush
1
80
1002
Nirmal
2
92
1003
Priyanshi
3
85
Select * from Student where Marks >= 85;
Select Name, Roll_no from Student ;
produces a selection
produces a projection
SQL, DDL and DML:
SQL
Structured Query Language.
DDL
Data Definition Language.
DDL commands allow us to define and manipulate the structure of data stored in a database.
Include commands for creating/defining, altering the definition or deleting the definition of
database objects like tables, views or indexes.
Examples of DDL commands: Create table, Alter Table, Drop Table, Create Index, Alter Index,
Drop Index, Create View, Drop View etc.
DML
stands for Data Manipulation Language.
DML commands allow us to work with data stored inside the database.
Include commands for:
inserting new information.
modifying existing information.
deleting stored information.
querying stored information.
Examples of DML commands are : Insert, Delete, Update, Select
5.5.1.2 Sample Solved Questions:
Observe the table ‘Club’ given below:
Member_id
M002
Ownership
Club
Member_Name
Address
Nisha
Gurgaon
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
2
Age
19
Excellence
Fee
3500
Page 196
M003
M004
Niharika
Sachin
New Delhi
Faridabad
21
18
2100
3500
i. What is the cardinality and degree of the above given table?
Ans. Cardinality = 3, Degree = 5
( ½ + ½ = 1 Mark )
ii. If a new column contact_no has been added and three more members have joined the
club then how these changes will affect the degree and cardinality of the above given table.
Ans. Cardinality = 6, Degree = 6
( ½ + ½ = 1 Mark )
5.5.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
Differentiate between DDL & DML. Identify DDL & DML commands from the following:(UPDATE, SELECT, ALTER, DROP)
CBSE Sample Paper ( 2016-17)
Observe the table ‘Club’ given below:
Club
Member_id
Member_Name
Address
Age
Fee
M002
Nisha
Gurgaon
19
3500
M003
Niharika
NewDelhi
21
2100
M004
Sachin
Faridabad
18
3500
i. What is the cardinality and degree of the above given table?
ii. If a new column contact_no has been added and three more members have joined the club then
how these changes will affect the degree and cardinality of the above given table.
CBSE Sample Paper ( 2015-16)
Differentiate between cardinality and degree of a table with the help of an example.
CBSE Sample Paper ( 2014-15)
Define degree and cardinality. Based upon given table write degree and cardinality.
PATIENTS
PatNo
PatName
Dept
DocID
1
Leena
ENT
100
2
Surpreeth
Ortho
200
3
Madhu
ENT
100
4
Neha
ENT
100
5
Deepak
Ortho
200
CBSE Sample Paper ( 2013)
Observe the following Table and answer the parts (i) and (ii) accordingly
Table : Member
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 197
MNo
101
102
102
109
113
Name
Pen
Pencil
Eraser
Sharpner
Clips
Qty
102
201
90
90
900
PurchaseDate
12-12-2011
21-02-2012
09-08-2010
31-08-2012
08-08-2011
(i) In the above table, can we take Mno as Primary Key? (Answer as [YES/NO] only). Justify your
answer with a valid reason.
(ii) What is the degree and the cardinality of the above table?
CBSE Sample Paper ( 2012)
What do you understand by degree and cardinality of a table?
What do you understand by union and Cartesian product operations performed upon two relations?
5.5.1.4 Questions From Previous Year Board Papers:
CBSE Paper 2017 ( All India )
Observe the following table MEMBER carefully and write the name of the RDBMS operation out
of (i) SELECTION (ii) PROJECTION (iii) UNION (iv) CARTESIAN PRODUCT, which has
been used to produce the output as shown in RESULT. Also, find the Degree and
Cardinality of the RESULT :
CBSE Paper 2017 ( Delhi )
Observe the following table CANDIDATE carefully and write the name of the RDBMS operation
out of (i) SELECTION (ii) PROJECTION (iii) UNION (iv) CARTESIAN PRODUCT, which has
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 198
been used to produce the output as shown in RESULT. Also, find the Degree and Cardinality of
the RESULT.
CBSE Paper 2016 ( All India )
Observe the following PARTICIPANTS and EVENTS tables carefully and write the name of the
RDBMS operation which will be used to produce the output as shown in RESULT ? Also, find the
Degree and Cardinality of the result.
CBSE Paper 2016 ( Delhi )
Observe the following STUDENTS and EVENTS tables carefully and write the name of the
RDBMS operation which will be used to produce the output as shown in LIST ? Also, find the
Degree and Cardinality of the LIST.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 199
CBSE Paper 2015 ( All India)
Observe the following table carefully and write the names of the most appropriate columns, which
can be considered as (i) candidate keys and (ii) primary key:
Code Item
Qty
Price
Transaction
Date
1Plastic Folder 14"
1
3
2014-12-14
001
00
400
1Pen Stand Standard
2
4
2015-01-31
004
00
500
1Stapler Mini
2
1
2015-02-28
005
50
200
1Punching Machine Small
2
1
2015-03-12
009
00
400
1Stapler Big
1
1
2015-02-02
003
00
500
CBSE Paper 2015 ( Delhi )
Observe the following table carefully and write the names of the most appropriate columns, which
can be considered as (i) candidate keys and (ii) primary key.
Id
Product
Qty Price
TransactionDate
101
Plastic Folder 12"
100
3400
2014-12-14
104
Pen Stand Standard
200
4500
2015-01-31
105
Stapler Medium
250
1200
2015-02-28
109
Punching
Machine
200
1400
2015-03-12
Big
103
Stapler Mini
100
1500
2015-02-02
CBSE Paper 2014 ( All India )
Explain the concept of Cartesian Product between two tables, with the help of appropriate
example.
CBSE Paper 2014 ( Delhi )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 200
Explain the concept of Union between two tables, with the help of appropriate example.
CBSE Paper 2013 ( Delhi )
What is the difference between degree and cardinality of a table? What is the degree and
cardinality of the following table?
Eno
Name
Salary
101
John Fedrick
45000
103
Raya Mazumdar
50600
CBSE Paper 2012 ( Delhi )
Give a suitable example of a table with sample data to illustrate Primary and Alternate Keys in it.
CBSE Paper 2011 ( Delhi )
What do you understand by Union & Cartesian Product operations in relational algebra?
CBSE Paper 2010 ( Delhi )
What do you understand by Candidate Keys in a table? Give a suitable example of Candidate Keys
from a table containing some meaningful data.
CBSE Paper 2009 ( Delhi )
What are candidate keys in a table? Give a suitable example of candidate keys in a table.
CBSE Paper 2007 ( Delhi )
What is the importance of a Primary Key in a table ? Explain with a suitable example.
CBSE Paper 2006 ( Delhi )
What is an Alternate Key?
5.5.1.5 Important Tips:


The Concept of degree and cardinality is important.
The concept of keys and of Cartesian product is aloso important.
5.5.2 QUESTION 5 (b) SQL Queries and Outputs ( 6 Marks )
5.5.2.1 Revision Notes
SQL Queries
CREATE DATABASE COMMAND
CREATE DATABASE DB1;
USE COMMAND
USE DB1;
CREATE TABLE COMMAND
CREATE TABLE STUDENT
(
ADMNO
CHAR(5),
NAME
VARCHAR(20),
MARKS
INT(3),
DOJ
DATE,
STIPEND
DECIMAL(7,2)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 201
);
* You should know the difference between char and varchar
DESCRIBE COMMAND
DESC STUDENT;
ALTER TABLE COMMAND
/* Add a new Column Grade of type char(1) */
ALTER TABLE STUDENT
ADD GRADE CHAR(1);
/* Delete a Column Grade*/
ALTER TABLE STUDENT
DROP GRADE;
/* Change the data type of a Column Grade from char(1) to char(2) */
ALTER TABLE STUDENT
MODIFY GRADE CHAR(2);
/* Change the name of a Column from Grade to Grade1 */
ALTER TABLE STUDENT
MODIFY GRADE GRADE1 CHAR(2);
TABLE : Student
Sname
Sclass
Ssec
WK1
WK2
HYR
WK3
WK4
FIN
Grade
SELECTING ALL COLUMNS
/* Display all rows and all columns of the table Student */
SELECT *
FROM Student;
REORDERING COLUMNS IN QUERY RESULT
/* Display all rows and all columns of the table Student but the Grade should be displayed before
the marks data */
SELECT Sname, Sclass, Ssec, Grade, WK1, WK2, HYR,
WK3, WK4, FIN
FROM Student;
SELECTING SPECIFIC COLUMNS
/* Display only the student name and the final marks of all students from the table Student */
SELECT Sname, FIN
FROM Student;
DEFINING AND USING COLUMN ALIAS
/* Display only the student name and the final marks of all students from the table Student. The
student name column should show the heading NAME and the final marks column should show the
heading FINAL MARKS */
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 202
SELECT Sname as "NAME" , FIN as "FINAL MARKS"
FROM Student;
USING ARITHMETIC OPERATORS
/* Display the name and percentage obtained in the 1st weekly test for all students from the Student
table */
SELECT Sname, WK1 * 4 "WK1 PERCENT"
FROM Student;
PUTTING TEXT IN A QUERY OUTPUT
/* Display student data in the following format - <Sname> has scored <WK1> marks out of 25 in
Weekly 1 exam */
SELECT Sname, ' has scored ' , WK1 , ' marks out of 25 in
WK1 exam'
FROM Student;
ELIMINATION OF DUPLICATE ROWS WITH THE DISTINCT
/* Display distinct sections ( i.e. without repetition ) that occur in the Student Table */
SELECT DISTINCT Ssec
FROM Student;
LIMITING ROWS DURING SELECTION WITH THE WHERE CLAUSE
• Using the where clause one can display only certain rows that satisfy a given
condition.
• The condition can be specified in different ways as is shown :
USING COMPARISON OPERATORS
The following relational operators can be used:<, <=, >, >=, = , <>
/* Display the names and marks in HYR of all students who have scored more than 50 in HYR */
SELECT Sname, HYR
FROM Student
WHERE HYR > 50;
USING BETWEEN OPERATOR
/* Display the names and marks in HYR of all students who have scored between 50 and 60 in
HYR */
SELECT Sname, HYR
FROM Student
WHERE HYR between 50 and 60;
/* Display the names and marks in HYR of all students who have not scored between 50 and 60 in
HYR */
SELECT Sname, HYR
FROM Student
WHERE HYR not between 50 and 60;
USING IN OPERATOR
/* Display the names and final marks of all students who are in section A or in section B */
SELECT Sname, FIN FROM Student
WHERE Ssec in ('A', 'B');
/* Display the names and final marks of all students who are neither in section A nor in section B
*/
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 203
SELECT Sname, FIN FROM Student
WHERE Ssec not in ('A', 'B');
USING LIKE OPERATOR
/* Display the names and marks in HYR of all students whose name begins with the letter A */
SELECT Sname, HYR FROM Student
WHERE Sname like 'A%';
/* Display the names and marks in HYR of all students whose name ends with the letter A */
SELECT Sname, HYR FROM Student
WHERE Sname like '%A';
USING LIKE OPERATOR
/* Display the names and HYR marks of students whose name ends with letter A */
SELECT Sname, HYR
FROM Student
WHERE Sname like '%A';
/* Display the names and HYR marks of students whose name contains letter A */
SELECT Sname, HYR
FROM Student
WHERE Sname like '%A%';
/* Display the names and marks in HYR of all students whose name has 5 characters, the third
being A */
SELECT Sname, HYR
FROM Student
WHERE Sname like '_ _ A _ _';
/* Display the names and marks in HYR of all students whose name contains R as first letter and
P as third letter */
SELECT Sname, HYR
FROM Student
WHERE Sname like 'R _ P%';
USING IS NULL AND NOT IS NULL
/* Display the names of all students for whom marks have not been entered for HYR*/
SELECT Sname
FROM Student
WHERE HYR IS NULL;
/* Display the names of all students for whom marks have been entered for HYR*/
SELECT Sname
FROM Student
WHERE HYR IS NOT NULL;
• Note that if any value in a calculation is a NULL , the result is also a NULL.
• All aggregate functions ( except Count(*) ) ignore NULL values.
COMBINING CONDITIONS USING THE LOGICALOPERATORS
Logical Operators NOT, AND, OR can be used to combine multiple search conditions.
Precedence is NOT, AND, OR /
* Display the names of all students for whom marks have not been entered for HYR and marks in
final exceed 60*/
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 204
SELECT Sname
FROM Student
WHERE HYR IS NOT NULL
AND FIN > 60;
SORTING IN ASCENDING/DESCENDING ORDER
/* Display all records of the Student table in alphabetical order of names */
SELECT *
FROM Student
ORDER BY Sname ASC; ( ASC can be omitted also )
/* Display all records of the Student table in reverse alphabetical order of names */
SELECT *
FROM Student
ORDER BY Sname DESC;
GROUP BY CLAUSE:
 The group by clause allows us to divide the table rows into groups based on the values of a
column which is named by the group by clause and then display information about each
group.
 When the group by clause is used, the corresponding select clause can use only the group
by field and aggregate functions.
HAVING CLAUSE:
 The having clause is only used in conjunction with the group by clause.
 It allows us to put conditions on groups ( just as the where clause allows us to put
conditions on rows of an ungrouped table). Only data pertaining to the groups that satisfy
the condition is then displayed.
 Whenever a condition involves an aggregate function we use the having clause.
/* Display the maximum final marks obtained by students of each section. Only display data for
those sections in which the maximum value of FIN exceeds 80 */
SELECT SSEC, MAX(FIN)
FROM STUDENT
GROUP BY SSEC
HAVING MAX(FIN) > 80;
AGGREGATE FUNCTIONS
/* Display the highest marks in FIN scored by any student */
SELECT MAX(FIN)
FROM Student;
/* Display the lowest marks in FIN scored by any student */
SELECT MIN(FIN)
FROM Student;
/* Display the average marks in FIN scored by any student */
SELECT AVG(FIN)
FROM Student;
/* Display the sum of marks in FIN scored by all students */
SELECT SUM(FIN)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 205
FROM Student;
/* Display the total count of records in the student table*/
SELECT COUNT(*)
FROM Student;
DIFFERENCE BETWEEN COUNT(*) AND COUNT(COLUMN NAME ):
Count( Column_name ) counts the total number of non NULL values in the column
Column_name. In other words, it does not count NULL values.
Count(*) counts all the values including any NULL values. In other words, it does not ignore the
NULL values.
Thus, if the Student table has a total of 60 rows out of which 5 rows contain a NULL in the FIN
column then
/* Display the total number of rows in the student table */
SELECT COUNT(*) FROM Student;
Will return the value 60.
/* Display the total number of students for whom marks have been entered in FIN from the student
table */
SELECT COUNT(FIN)
FROM Student;
Will return the value 55.
JOINS IN MYSQL:
 Joins are used to query and obtain data from two or more TABLES.
 Normally tables are joined on the basis of a common column which generally is a primary
key of one table and foreign key of the other.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 206
/* Display PatNo, PatName and corresponding DocName for each patient */
SELECT PATNO, PATNAME, DOCNAME
FROM PATIENTS, DOCTORS
WHERE PATIENTS.DOCID = DOCTORS,DOCID;
5.5.2.2 Sample Solved Questions:
b) Consider the following tables TEACHER and SALARY.
TEACHER
ID
Name
Dept
Sex
Experience
101
Siddharth
Computer
M
12
104
Raghav
Physics
M
5
107
Naman
Chemistry
M
10
114
Nupur
Computer
F
3
109
Janvi
Physics
F
9
105
Rama
Account
M
10
117
James
Computer
F
3
111
Bonoy
Account
F
12
130
Samuel
Computer
M
15
SALARY
ID
Basic
Allowance
DA
101
12000
1000
300
104
23000
2300
500
107
32000
4000
500
114
12000
5200
1000
109
42000
1700
200
105
18900
1690
300
130
21700
2600
300
Write SQL queries for parts (i) to (iv).
4
i)
Display Name and DA of all staff who are in “Account” department having more
than 10 years experience.
Ans. SELECT Name, DA
FROM TEACHER A, SALARY B
WHERE A.ID = B.ID
and Dept = “Account” and Experience > 10;
( ½ Mark for the SELECT FROM clause
½ Mark for the WHERE clause = 1 Mark. )
ii)
Display the average salary of all the staff working in “Physics” department. Here
salary means Basic + Allowance + DA.
Ans. SELECT AVG(Basic + Allowance + DA)
FROM TEACHER A, SALARY B
WHERE A.ID = B.ID
and Dept = “Physics” ;
( ½ Mark for the SELECT FROM clause
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 207
½ Mark for the WHERE clause = 1 Mark. )
iii)
Display the name and department of all teachers whose names contain the letter ‘a’.
Ans. SELECT Name, Dept
FROM TEACHER
WHEREName like ‘%a%”;
( ½ Mark for the SELECT FROM clause
½ Mark for the WHERE clause = 1 Mark. )
iv)
For each department display the maximum and minimum experience years.
Ans. SELECT Dept, MAX(Experience), MIN(Experience)
FROM TEACHER
GROUP BY Dept;
( ½ Mark for the SELECT FROM clause
½ Mark for the GROUP BY clause = 1 Mark. )
Give outputs for parts (v) and (vi).
v)
SELECT NAME, DEPT, BASIC FROM TEACHER, SALARY
WHERE DEPT =”COMPUTER” AND TEACHER.ID = SALARY.ID;
2
Ans.
vi)
Name
Dept
Siddharth
Computer
Nupur
Computer
Samuel
Computer
( 1 Mark for the correct Output )
SELECT NAME, DA, BASIC FROM TEACHER A, SALARY B
WHERE BASIC> 20000 AND A.ID=B.ID;
Ans.
Name
DA
Basic
Raghav
500
23000
Naman
500
32000
Janvi
200
42000
Samuel
300
21700
( 1 Mark for the correct Output )
Basic
12000
12000
21700
5.5.2.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
Consider the following relation MobileMaster & MobileStock:-
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 208
Write the SQL query for questions from (i) to (iv) & write the output of SQL command for
questions from (v) to (viii) given below:(i) Display the Mobile company, name & price in descending order of their manufacturing date,
(ii) List the details of mobile whose name starts with „S‟ or ends with „a‟,
(iii) Display the Mobile supplier & quantity of all mobiles except „MB003‟,
(iv) List showing the name of mobile company having price between 3000 & 5000,
(v) SELECT M_Id, SUM(M_Qty) FROM MobileStock GROUP BY M_Id;
(vi) SELECT MAX(M_Date), MIN(M_Date) FROM MobileMaster;
(vii) SELECT M1.M_Id, M1.M_Name, M2.M_Qty, M2.M_Supplier FROM MobileMaster M1,
MobileStock M2 WHERE M1.M_Id=M2.M_Id AND M2.M_Qty>=300;
(viii) SELECT AVG(M_Price) FROM MobileMaster;
CBSE Sample Paper ( 2016-17)
Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on the tables
‘Watches’ and ‘Sale’ given below.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 209
(i)
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
(viii)
To display all the details of those watches whose name ends with ‘Time’
To display watch’s name and price of those watches which have price range in
between 5000-15000.
To display total quantity in store of Unisex type watches.
To display watch name and their quantity sold in first quarter.
Select max(price), min(qty_store) from watches;
Select quarter, sum(qty_sold) from sale group by quarter;
Select watch_name,price,type from watches w, sale s where w..watchid!=s.watchid;
Select watch_name, qty_store, sum(qty_sold), qty_store - sum(qty_sold) “Stock”
from watches w, sale s where w.watchid=s.watchid group by s.watchid;
CBSE Sample Paper ( 2015-16)
Consider the following tables FACULTY and COURSES. Write SQL commands for the
statements (i) to (v) and give outputs for SQL queries (vi) to (vii)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 210
(i)
(ii)
(iii)
(iv)
(v)
(vi)
To display details of those Faculties whose salary is greater than 12000.
To display the details of courses whose fees is in the range of 15000 to 50000 (both
values included).
To increase the fees of all courses by 500 of “System Design” Course.
To display details of those courses which are taught by ‘Sulekha’ in descending
order of courses.
Select COUNT(DISTINCT F_ID) from COURSES;
Select MIN(Salary) from FACULTY,COURSES where COURSES.F_ID =
FACULTY.F_ID;
CBSE Sample Paper ( 2014-15)
Write SQL commands for the queries (i) to (iv) and output for (v) & (viii) based
on a table COMPANY and CUSTOMER
Table : COMPANY
CID
NAME
CITY
PRODUCTNAME
111
SONY
DELHI
TV
222
NOKIA
MUMBAI
MOBILE
333
ONIDA
DELHI
TV
444
SONY
MUMBAI
MOBILE
555
BLACKBERRY
MADRAS
MOBILE
666
DELL
DELHI
LAPTOP
CUSTID
101
102
103
104
NAME
Rohan
Sharma
Deepak
Kumar
Mohan
Kumar
Sahil
Bansal
Table : CUSTOMER
PRICE
QTY
70000
20
CID
222
50000
10
666
30000
5
111
35000
3
333
(i) To display those company name which are having prize less than 30000.
(ii) To display the name of the companies in reverse alphabetical order.
(iii) To increase the prize by 1000 for those customer whose name starts with ‘S’ (iv) To add one
more column totalprice with decimal(10,2) to the table customer
(v) SELECT COUNT(*) ,CITY FROM COMPANY GROUP BY CITY;
(vi) SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10 ;
(vii) SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE “%r%;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 211
(viii) SELECT PRODUCTNAME,CITY, PRICE FROM COMPANY,CUSTOMER WHERE
COMPANY.CID=CUSTOMER.CID AND PRODUCTNAME=”MOBILE”;
CBSE Sample Paper ( 2013)
Consider the following tables SUBJECT and TEACHER and answer (b), (c), (d) and (e) parts of
this question:
Table : TEACHER
Code
Title
Marks_
Marks_
Theory
Prac
301
English
100
0
041
Maths
100
0
083
Comput
70
30
er Sc
042
Physics
70
30
043
Chemist
70
30
ry
Table : SUBJECT
Name
P. Jain
R. Nagpal
Supatra
Shabnam
Rashika
Vidushi
Yash
TCode
1
2
3
4
5
6
7
Sub_Code
301
301
041
083
042
041
043
(b) Write SQL commands for the flowing statements:
(i) To display the names of all the subjects for which practical marks are 0.
(ii) To display the total number of teachers in each subject separately.
(iii) To display the names of all the teachers in the ascending order of the Sub_Code.
(iv) To display each subject’s details along with Total_Marks in each subject from the table
SUBJECT. (Total_Marks = Marks_Theory + Marks_Practical).
(c) Write SQL statement to display each teacher’s name along with his/her respective subject name
from the tables TEACHER and SUBJECT.
(d) Give the output of the following SQL queries:
(i) SELECT DISTINCT(Marks_Theory) from SUBJECT;
(ii) SELECT TCode, Name from Teacher where Sub_Code like ‘0%’;
5.5.2.4 Questions From Previous Year Board Papers:
CBSE All India – 2017
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on
the tables.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 212
(vii)
To display all details from the table MEMBER in descending order of
ISSUEDATE.
(viii) To display the DCODE and DTITLE of all Folk Type DVDs from the table DVD.
(ix)
To display the DTYPE and number of DVDs in each DTYPE from the table DVD.
(x)
To display all NAME and ISSUEDATE of those members from the table
MEMBER who have DVDs issued (i.e., ISSUEDATE) in the year 2017.
(xi)
SELECT MIN(ISSUEDATE) FROM MEMBER;
(xii) SELECT DISTINCT DTYPE FROM DVD;
(xiii) SELECT D.DCODE, NAME, DTITLE
FROM DVD D, MEMBER M WHERE D.DCODE=M.DCODE;
(xiv) SELECT DTITLE FROM DVD
WHERE DTYPE NOT IN ("Folk", "Classical");
CBSE Delhi 2017
Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on
the tables.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 213
(i)
(ii)
(iii)
(iv)
(v)
(vi)
(vii)
(viii)
To display all details from table MEMBER in descending order of ISSUEDATE.
(To display the BNO and BNAME of all Fiction Type books from the table BOOK.
To display the TYPE and number of books in each TYPE from the table BOOK.
To display all MNAME and ISSUEDATE of those members from table MEMBER
who have books issued (i.e. ISSUEDATE) in the year 2017.
SELECT MAX(ISSUEDATE) FROM MEMBER;
SELECT DISTINCT TYPE FROM BOOK;
SELECT A.CODE,BNAME,MNO,MNAME
FROM BOOK A, MEMBER B WHERE A.CODE=B.CODE;
SELECT BNAME FROM BOOK
WHERE TYPE NOT IN ("FICTION","COMIC");
CBSE Delhi 2016
Observe the following STUDENTS and EVENTS tables carefully and write the name of the
RDBMS operation which will be used to produce the output as shown in LIST ? Also, find the
Degree and Cardinality of the LIST.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 214
CBSE All India 2014
Answer questions (a) and (b) on the basis of the following tables STORE and ITEM.
TABLE SHOPPE
ID
SName
Area
S001
ABC
Cp
Computronics
S002
All
Infotech
GK2
Media
S003
Tech Shoppe
CP
S004
Geeks
Tecno
Nehru Place
Soft
S005
Hitech
Tech
Nehru Place
Store
TABLE ACCESSORIES
No
Name
Price
ID
A01
Mother
12000
S001
Board
A02
Hard
5000
S001
Disk
A03
Keyboa
500
S002
rd
A04
Mouse
300
S001
A05
Mother
13000
S002
Board
A06
Keyboa
400
S003
rd
A07
LCD
6000
S004
A08
LCD
5500
S005
A09
Mouse
350
S005
A10
Hard
4500
S003
Disk
(a) Write SQL queries for (i) to (iv):
(i)
To display Name and Price of all the accessories in ascending order of their Price.
(ii)
To display ID and SName of all shoppe located in Nehru Place.
(iii)
To display Minimum and Maximum Price of each Nameof accessories.
(iv)
To display Name, Price of all accessories and their respective SName where they
are available.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 215
(b) Write the output of the following SQL commands (i) to (iv) :
(i)
SELECT DISTINCT Name FROM ACCESSORIES WHERE Price >= 500;
(ii)
SELECT Area, COUNT(*) FROM SHOPPE GROUP BY Area;
(iii)
SELECT COUNT( DISTINCT Area ) FROM SHOPPE;
(iv)
SELECT Name, Price * 0.05 DISCOUNT FROM ACCESSORIES WHERE SNo
IN ( ‘S002’, ‘S003’ );
CBSE Delhi 2014
Answer questions (a) and (b) on the basis of the following tables STORE and ITEM.
TABLE STORE
SNo
SName
Area
S01
ABC
GK II
Computronics
S02
All
Infotech
CP
Media
S03
Tech Shoppe
Nehru Place
S04
Geeks
Tecno
Nehru Place
Soft
S05
Hitech
Tech
CP
Store
TABLE ITEM
INo
IName
Price
SNo
T01
Mother
12000
S01
Board
T02
Hard
5000
S01
Disk
T03
Keyboa
500
S02
rd
T04
Mouse
300
S01
T05
Mother
13000
S02
Board
T06
Keyboa
400
S03
rd
T07
LCD
6000
S04
T08
LCD
5500
S05
T09
Mouse
350
S05
T10
Hard
4500
S03
Disk
(c) Write SQL queries for (i) to (iv):
(ix)
To display IName and Price of all the items in ascending order of their Price.
(x)
To display SNo and SName of all store located in CP.
(xi)
To display Minimum and Maximum Price of each IName from the table ITEM.
(xii) To display IName, Price of all items and their respective SName where they are
available.
(d) Write the output of the following SQL commands (i) to (iv) :
(i)
SELECT DISTINCT IName FROM ITEM WHERE Price >= 5000;
(ii)
SELECT Area, COUNT(*) FROM STORE GROUP BY Area;
(iii)
SELECT COUNT( DISTINCT Area ) FROM STORE;
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 216
(iv)
SELECT IName, Price * 0.05 DISCOUNT FROM ITEM WHERE SNo IN ( ‘S02’,
‘S03’ );
5.5.2.5 Important Tips:


Begin each SQL clause on a new line. This will help you avoid missing some clauses.
Always leave a blank line between queries.
5.6 QUESTION 6 ( Topic: Boolean Algebra) : ( 8 Marks )
5.6.1 QUESTION 6 (a) Laws of Boolean Algebra ( 2 Marks )
5.6.1.1 Revision Notes
You must be able to identify all laws.
BOOLEAN LAW
STATEMENT
Closure property
If A and B are two boolean variables/constants then A.B, A+B, A’ and B’ are
also Boolean.
Commutative Law
A+B = B+A
A.B=B.A
Associative Law
(A+B) +C = A+(B+C)
(A.B).C=A.(B.C)
Distributive Law
A.(B+C) = A.B +A.C
A+(B.C) = (A+B).(A+C)
Idempotent Law
A+A = A
A.A = A
Involution Law
( A’) ‘ = A
Absorption law
A + A.B = A
A.(A+B)=A
A+A’.B = A+B
A.(A’ + B) = A.B
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 217
Dominance law
1+A=1
0.A = 0
Inverse/Complement
arity Law
A+A’ = 1
A.A’ = 0
Identity law
0+A = A
1.A = A
De MORGANS
LAWS
(break the bar:
change the sign)
( A + B )’ = A’ + B’
(A.B)’=A’.B’
Duality Theorem
Starting with a Boolean relation, we can derive another Boolean relation
from it called its dual by:
 Changing each OR to an AND
 Changing each AND to an OR
 Changing a 1 to a 0 and
 Changing a 0 to a 1.
If the original Boolean relation is a valid equation that always holds true i.e.
represents a Boolean law , then the dual shall also always hold true i.e. the
dual is also a Boolean law.
5.6.1.2 Sample Solved Questions:
State the De-Morgans laws. Verify using a truth table.
2
Ans. For all boolean variables A and B
( A + B )’ = A’.B’
( A.B )’ = A’ + B’
i.e. the complement of the sum is equal to the product of the individual complements and the
complement of the product is equal to the sum of the individual complements.
In simple words…. break the line , change the sign.
A
B
A’
B’
(A+B)’
A’.B’
0
1
1
1
1
0
1
1
0
0
0
0
0
0
1
0
0
1
1
0
0
0
0
1
Since the columns for (A+B)’ and A’.B’ are the same , hence the first law is proven.
A
B
A’
B’
(A.B)’
A’+B’
0
1
1
1
1
0
1
1
0
1
1
0
0
0
1
1
1
1
1
0
0
0
0
1
Since the columns for (A.B)’ and A’+B’ are the same , hence the second law is proven.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 218
( ½ mark each for stating each law.)
( ½ mark each for each truth table proof.)
5.6.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
State & prove De-Morgan’s law using truth table.
CBSE Sample Paper ( 2016-17)
Correct the following boolean statements:
1. X+1 = X
2. (A')'=A'
3. A+A'=0
4. (A+B)' = A.B
CBSE Sample Paper ( 2015-16)
State and Verify Absorption law algebraically.
5.6.1.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
State any one Distributive Law of Boolean Algebra and verify it using truth table.
CBSE All India – 2018
State any one Absorption Law of Boolean Algebra and verify it using truth table.
CBSE All India – 2017
State DeMorgans Laws of Boolean Algebra and verify them using truth table.
CBSE Delhi – 2017
State Distributive Laws of Boolean Algebra and verify them using truth table.
5.6.1.5 Important Tips:
o You must be able to prove all laws using a truth table.
o
You must know the algebraic proofs of the following laws :
 Idempotent Law
 Absorption Law
 De Morgans Laws.
5.6.2 QUESTION 6 (b) Logic Circuits ( 2 Marks )
5.6.2.1 Revision Notes
You must know the symbolic and diagrammatic representations
for all the logic gates and know their behavior.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 219
You are either given an equation and asked to draw the corresponding circuit diagram or given a
circuit diagram and asked to write the equation.
AND Gate :
Produces a 1 as an output only when both its inputs are a 1.
Represented by A.B
OR Gate :
Produces a 0 as an output only when both its inputs are a 0
Represented by A+B
NOT Gate :
Produces a 1 as an output when its inputs is a 0 and a 0 as output when its input is a 1.
Represented by A’
NAND Gate :
Produces a 0 as an output only when both its inputs are a 1
Represented by (A.B)’
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 220
NOR Gate :
Produces a 1 as an output only when both its inputs are a 0
Represented by (A+B)’
XOR Gate :
Produces a 1 as an output only when there are odd number iof 1 in input
Represented by AB
XNOR Gate :
Produces a 1 as an output only when there are even number of 1 in input
Represented by (AB)’
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 221
5.6.2.2 Sample Solved Questions:
Draw the Logic Circuit of the following Boolean Expression:
((U + V’).(U + W)). (V + W’)
Ans.
2
( 2 marks for the correct circuit diagram )
5.6.2.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
Draw the equivalent logic circuit diagram of the following Boolean expression:(A’ + B).C’
CBSE Sample Paper ( 2016-17)
Draw the equivalent logic circuit for the following Boolean expression:
(A.B)+C
CBSE Sample Paper ( 2015-16)
Draw a logic circuit for the following Boolean expression:
A.B+C.D’.
5.6.2.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Draw the Logic Circuit of the following Boolean Expression :
A’.B’ + A.C
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 222
CBSE All India – 2018
Draw the Logic Circuit of the following Boolean Expression :
(U’+ V).(V’ + W’)
CBSE All India – 2017
Draw the Logic Circuit of the following Boolean Expression using only NOR Gates :
(A+B).(C+D)
CBSE Delhi – 2017
Draw the Logic Circuit of the following Boolean Expression using only NAND Gates :
X.Y + Y.Z
5.6.2.5 Important Tips:

Be careful to use the correct gate diagram.
5.6.3 QUESTION 6 (c) POS and SOP ( 1 Mark )
5.6.1.1 Revision Notes
Question Type 1 :
Write the POS/SOP equation based on a given truth table
A
B
C
F
0
0
0
0
0
0
1
1
0
1
0
0
A+B’+C
0
1
1
0
A+B’+C’
1
0
0
0
A’+B+C
1
0
1
1
A.B’.C
1
1
0
1
A.B.C’
1
1
1
1
A.B.C
SOP equation :
Ownership
Min Terms
Max Terms
A+B+C
A’.B’.C
F = A’.B’.C + A.B’.C + A.B.C’ + A.B.C
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 223
POS equation : F =(A+B+C).(A+B’+C).(A+B’+C’).(A’+B+C)
Question Type 2 :
Convert the given Boolean expression into the equivalent canonical SOP form.
(X’ + Y + Z’).(X’ + Y + Z ). ( X’ + Y’ + Z ). (X’ + Y’ + Z’ )
The given equation has been given in the POS form. Each term in this equation is a maxterm
corresponding to a row of the truth table as shown:
Maxterm
Corresponds to
(X’ + Y + Z’)
101 ( 5)
(X’ + Y + Z )
100 (4)
( X’ + Y’ + Z )
110 (6)
(X’ + Y’ + Z’ )
111
(7)
Therefore, the truth table looks like this :
A
B
C
F
Min Terms
0
0
0
1
X’.Y’.Z’
0
0
1
1
X’.Y’.Z
0
1
0
1
X’.Y.Z’
0
1
1
1
X’.Y.Z
1
0
0
0
X’+Y+Z
1
0
1
0
X’+Y+Z’
1
1
0
0
X+Y+Z’
1
1
1
0
X’+Y’+Z’
The required SOP equation is:
Ownership
Integrity
Max Terms
F = X’.Y’.Z’ + X’.Y’.Z + X’.Y.Z’ + X’.Y.Z
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 224
Question Type 3 :
Write equivalent canonical POS form of equation for F ( X, Y, Z ) = ∑ ( 0,2,4, 5 )
Since 3 variables are involved the truth table will have 8 rows and the rows will represent numbers
from 0 to 7.
Since the rows corresponding to the numbers 0, 2, 4, 5 have 1’s so the rows corresponding to the
numbers 1,3,6,7 must have 0’s.
So the equation in the canonical POS form is F (X, Y, Z) = ∏ ( 1,3,6,7)
Question Type 4 :
Express P + Q’R in POS form
Method 1 :
P+ Q’.R
= ( P + Q’). ( P + R )
…………. ( Distributive Law )
= ( P + Q’ + 0 ). ( P + R + 0 )
…………. ( 0 = identity element )
= ( P + Q’ + R.R’). (P + R = Q.Q’ )
……..…… ( Inverse Law )
= ( P + Q’ + R ). ( P + Q’ + R’). (P + R + Q ).(P + R + Q’)
……. ……(Distributive Law)
= ( P + Q’ + R ). ( P + Q’ + R’ ). ( P + Q + R )
……..….. ( Idempotent law. )
…………..(.Remove duplicates)
Method 2 :
Draw the truth table corresponding to P+Q’.R
P
Q
R
Q’
Q’.R
P+Q’.R
0
0
0
1
0
0
0
0
1
1
1
1
0
1
0
0
0
0
0
1
1
0
0
0
1
0
0
1
0
1
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 225
1
0
1
1
1
1
1
1
0
0
0
1
1
1
1
0
0
1
The required POS equation from the truth table is :
F = (P+Q+R).(P+Q’+R).(P+Q’+R’)
5.6.1.2 Sample Solved Questions:
c) Write the POS form of the Boolean function F(P,Q,R) = Σ(0,2,3,5).
1
Ans. F = π(1,4,6,7)
( 1 mark for the correct answer )
5.6.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
Write the SOP form for the Boolean Function F(X,Y,Z) represented by the given truth table:X
Y
Z
F
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
CBSE Sample Paper ( 2016-17)
Write the POS form of a Boolean Function F, which is represented in a truth tale as follows:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 226
CBSE Sample Paper ( 2015-16)
Write the SOP form of a Boolean function F, which is represented in a truth table as follows:
A
B
C
F
0
0
0
0
0
0
1
1
0
1
0
1
0
1
1
0
1
0
0
1
1
0
1
1
1
1
0
0
1
1
1
0
5.6.1.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Derive a Canonical POS expression for a Boolean function F, represented by the
following truth table :
X
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
1
F(X,Y,Z)
1
0
1
0
1
1
0
0
CBSE All India – 2018
Derive a Canonical POS expression for a Boolean function FN, represented by the following
truth table : 1
X
0
0
0
0
1
1
1
1
Y
0
0
1
1
0
0
1
1
Z
0
1
0
1
0
1
0
1
FN(X,Y,Z)
1
1
0
0
1
0
0
1
CBSE All India – 2017
Derive a Canonical POS expression for a Boolean function G, represented by the following truth
table :
X
Y
Z
G(X,Y,Z)
0
0
0
0
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 227
0
0
0
1
1
1
1
0
1
1
0
0
1
1
1
0
1
0
1
0
1
0
1
0
1
1
0
1
CBSE Delhi – 2017
Derive a Canonical SOP expression for a Boolean function F, represented by the following truth
table :
U
V
W
F(U,V,W)
0
0
0
1
0
0
1
0
0
1
0
1
0
1
1
1
1
0
0
0
1
0
1
0
1
1
0
1
1
1
1
0
5.6.1.5 Important Tips:

Use the same variable names as given in the question. Marks are deducted for using
incorrect variable names.
5.6.4 QUESTION 6 (d) KMap ( 3 Marks )
5.6.4.1 Revision Notes
Steps involved in solving a problem using a 4 variable KMap:
1. Draw the KMap.
2. Number the squares. correctly
3. Label the rows and the columns correctly.
4. Mark a 1 in the squares corresponding to minterms that have a 1 in the output.
5. Enclose the 1’s in groups in a manner that you maximize the size of the groups and
minimize the number of groups.
• Groups can contain 1(singleton), 2 (pair),4 ( quad),8(octet) i.e. powers of 2.
• Include the largest number of 1’s in a group. Encircle octets first, then quads, then
pairs and finally single 1s.
• While making the groups, the map can be rolled i.e. you can consider that the left
edges of the map are touching the right edges and the top edges of the map are
touching the bottom edges.
• Overlapping of groups is allowed i.e. a 1 can be a part of more than one group as
long as overlapping groups include non common 1s i.e. redundant groups should
not be formed.
6. Some correct ways of grouping 1’s are shown below:
7. 7. Finally write the product term corresponding to each group and OR all the terms
together. Remember that a
 1 cell group will yield a 4-variable product term.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 228
 2 cell group will yield a 3-variable product term.
 4 cell group will yield a 2-variable product term.
 8 cell group will yield a 1-variable product term.
 16 cell group will yield a value of 1 for the expression.
8. The product term for each group is obtained by taking the product of only those variables
that do not change as we move across the group in the horizontal and vertical direction. The
variables that change from complemented to un complemented form or vice versa are
eliminated.
5.6.4.2 Sample Solved Questions:
Reduce the following Boolean equation using a K-Map.
F(A, B, C, D) =  ( 0,1,2,3,4,10,11)
3
Ans.
CD
AB
00
01
1
0
00
01
1
10
11
1
3
2
1
1
4
5
7
6
12
13
15
14
8
9
1
11
10
11
1
10
1
F= A’B’ + A’C’D’ + B’C
(½ mark for drawing K-Map and correctly plotting 1s in the given cells)
( ½ mark each for 3 groupings)
(1 mark for writing final expression in reduced/minimal form)
(Note:
● Deduct ½ mark if wrong variable names are used )
5.6.4.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
Reduce the following Boolean expression using K-Map:F(U,V,W,Z)= π(0,2,5,7,12,13,15)
CBSE Sample Paper ( 2016-17)
Reduce the following Boolean Expression using K Map:
F(A,B,C,D) = ∑(0,1,3,5,6,7,9,11,13,14,15)
CBSE Sample Paper ( 2015-16)
Obtain a simplified from for a Boolean expression:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 229
F (U, V, W, Z) = II (0, 1, 3, 5, 6, 7, 15)
5.6.4.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Reduce the following Boolean Expression to its simplest form using K-Map :
F(P,Q,R,S) = π(0 , 1 , 3 , 5 , 6 , 7 , 10 , 14 , 1 )
CBSE All India – 2018
Reduce the following Boolean Expression to its simplest form using K-Map :
G (U,V, Z ,W) = π (3,5,6,7,11,12,13,15)
CBSE All India – 2017
Reduce the following Boolean Expression to its simplest form using K-Map :
E (U,V, Z ,W) = π(2 , 3 , 6 , 8 , 9 , 10 , 11 , 12 , 13 )
CBSE Delhi – 2017
Reduce the following Boolean Expression to its simplest form using K-Map :
F(X,Y,Z,W) = S(0,1,2,3,4,5,10,11,14)
5.6.4.5 Important Tips:



Read carefully to check if it is a summation or product K Map.
Fill in 1s in case of summation and 0 in case of product in your grid.
Use the same variable names as given in the question. Marks are deducted for using
incorrect variable names.
5.7 QUESTION 7 ( Topic: Networking) : ( 10 Marks )
5.7.1 QUESTION 7 (a,b,c,d) Networking Theory ( 1/2 Markers = 6 Marks )
5.7.1.1 Revision Notes
Internet
 The Internet is a huge network of networks spanning across countries. Thus, it is an
organization of numerous computers that can all communicate with each other. Moreover,
these computers are all interconnected by many paths.
 Works on a Client Server Model. Some machines on the network store information and run
software to provide or serve this information. These are called Servers. Other machines run
software to access or view information stored on the servers and are called Clients.
 It is a truly international network. It is not run by one particular government or commercial
agency. Instead it is the combined effort of every organization that has a computer connected
to the Internet.
 Vinton Cerf, the first chairman of the INWG ( Inter Networking Working Group) that is a body
that sets standards for the growth of the Internet, is known as the "Father of the Internet".
 The underlying protocol used for communication on the Internet is TCP/IP.
ARPANET : History of the Internet:
 The U.S. department of Defense created the ARPANET in 1969, (Advanced Research Projects
Agency Network) - a network for researchers involved in the development of military warfare.
 With the passage of time this network was opened to educational institutions and commercial
institutes.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 230

In India, Internet was started in November 1988 by VSNL (Videsh Sanchar Nigam Limited) in
Mumbai.
INTERSPACE…The future of the Internet
 The Interspace is the future of the Internet.
 It is a new information infrastructure capable of serving widely distributed communities that
the Internet is fast evolving into.
 Today most online information is stored in archival centers containing large collections that
have been indexed by trained professionals. In the future independent communities will
develop and maintain their own collections rather than transferring them to a central archive.
So small collections maintained and indexed by individual communities will contain most
online information. The information retrieval system would be more powerful as it would
move beyond searching individual repositories to analyzing heterogeneous data across sources
and subjects. Thus, concept navigation would be the key feature of the Interspace.
 The Interspace will thus:
 Directly support interaction with abstraction.
 Analyze and correlate knowledge across multiple sources and subjects.
 Offer distributed services to transfer concepts across domains.
 Support searching knowledge collections maintained and indexed by specialized
communities and residing directly on users personal machines.
DIFFERENT WAYS OF SENDING DATA ACROSS A NETWORK : SWITCHING
TECHNIQUES
SWITCHING TECHNIQUE
 A switching technique is a data communication technique i.e. refers to the technique using
which data is passed from a sender computer to a receiving computer.
CIRCUIT SWITCHING
 A complete physical channel or connection between the source and the destination
computer is first established.
 This channel is then dedicated with the same speed throughout the data transfer and
remains unavailable until released.
MESSAGE SWITCHING



No physical signal path is established in advance.
Discrete entities called messages are transmitted. The sender includes a destination address
and the message is conveyed as a complete entity.
Relays called switching offices act as buffers in the transfer.
PACKET SWITCHING



No physical signal path is established.
Messages are broken down into smaller units called packets having well defined formats.
Each packet has housekeeping information including the packet number so that the
message can be reassembled at the other end.
 Packets are forwarded using store and forward mechanism.
Data Communication Terminology –
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 231
NOISE :
 External disturbance that tends to distort a signal.
ATTENUATION :
 Measure of how much the strength of a signal has reduced in passing through a medium. It
is generally proportional to the distance covered.
BANDWIDTH :
 In computer networks, bandwidth is used as a synonym for data transfer rate - the amount
of data that can be carried from one point to another in a given time period (usually a
second). Network bandwidth is usually expressed in bits per second (bps) or multiples of it
( Kbps, Mbps, Gbps, Tbps etc).
 Bandwidth is also the range of frequencies -- the difference between the highest-frequency
signal component and the lowest-frequency signal component -- an electronic signal uses
on a given transmission medium. Like the frequency of a signal, bandwidth is measured
in Hz i.e. hertz (cycles per second) or multiples of it ( KHz, MHz etc. ). E.g. a typical voice
signal has a bandwidth of approx. 3 KHz. Greater the bandwidth of a communication
system, greater is the capacity and hence greater is the amount of data that can be
transmitted over a period of time.
TRANSMISSION MEDIA
 The medium over which data travels from one computer to another in a network is called a
channel or transmission medium.
 It may refer to the entire physical medium or to one of the several carrier frequencies
transmitted simultaneously within the line.
 Transmission medium may be guided ( i.e. wired ) or unguided ( i.e. wireless ).
 Each computer on a network is also called a node or workstation. Thus, transmission media
is used to interconnect nodes together.
 On the basis of speed transmission media can be categorized as :
o Narrowband – Slow and used for telegraph lines and low speed terminals.
o Voiceband – Used for ordinary telephone communication.
o Broadband – Fastest and used for transmitting large volumes of data at high speeds.
Wired Technologies/ Guided Media –
TWISTED PAIR
 A twisted pair cable consists of four twisted pairs covered in an outer shield. Each twisted
pair consists of two insulated copper wires twisted around each other. These pairs are
colour coded.
 The twisting of wires reduces crosstalk which is the bleeding of a signal from one wire to
another. Crosstalk can corrupt the signal and cause network errors. In addition the twisting
also protects the signal from external interference which effects bothe wires and creates
unwanted signals.
 An RJ-45 ( Registered Jack – 45 ) connector is used to connect this cable to a computer.
 It is the most widely used cable for creating small networks.
 It can carry data up to a distance of 100m at a stretch.
 Its data transfer rate varies from 10 Mbps to 10 Gbps.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 232




It is generally used for telephone communications in offices and in modern Ethernet
networks. For telephone conversations a voice grade medium ( VGM) cable is used while
for LAN applications a higher quality cable known as Data Grade Medium ( DGM ) is
used.
It is of two types :
o UTP ( Unshielded Twisted Pair )
o STP ( Shielded Twisted Pair )
The major advantage of a twisted pair cable is that it is easy to install as it is flexible and
of low weight and is the cheapest.
The major disadvantage of a twisted pair is it’s low bandwidth, bad noise immunity and
high attenuation.
UTP
STP
Stands for Unshielded Twisted Pair.
Individual pairs in the cable are not
shielded. There is only an outer shield
covering all pairs.
Low noise immunity.
It is thin ( external diameter approx 0.43 cm
) and flexible and therefore offeres ease of
installation.
Cheaper
Stands for Shielded Twisted Pair
Each pair in the cable is individually
shielded. An outer shield then covers all the
pairs.
Better immunity against internal and
external electromagnetic interferences.
As compared to UTP it is difficult to install.
Expensive than UTP.
CO-AXIAL CABLES
 A coaxial cable consists of two conductors that share a common axis. The inner conductor
is a straight, stiff copper wire. This is surrounded by an insulating material. The insulator is
encased by the second cylindrical conductor, often as a closely woven braided mesh. The
outer conductor is covered in a protective plastic sheath. The inner core carries the signal
and the outer conductor provides the ground.
 The advantages of a coaxial cable are as follows:
 It has a higher bandwidth (400Mbps) and can be used for broadband communication.
 It can carry data for a larger distance ( 185m – 500m ) at a stretch.
 Has better noise immunity i.e. is less susceptible to electromagnetic fields.
 Cheap though more expensive than the twisted pair.
 The disadvantages of a coaxial fibre are as follows:
 It is bulkier and less flexible as compared to a twisted pair.
 Due to its thickness ( 1 cm diameter ), it is difficult to install as compared to the
twisted pair cable.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 233


 Bandwidth is still not very high.
 Attenuation also present.
 It is easy to tap.
 It is more expensive than Ethernet cable.
Coaxial cables are widely used in cable TV networks.
Two common types of coaxial cables are :
 Thicknet: Thicker and maximum segment length can be 500m.
 Thinnet : Thinner and maximum segment length can be 185m.
OPTICAL FIBRE
 Consist of thin strands of glass or glass like fiber about the thickness of a human hair. They
are arranged in bundles of hundreds and thousands and are protected by the cable’s outer
covering called the jacket.
 Data is transmitted in the form of light signals. Light from a source (LED or LDs) at one
end travels via the fiber to a detector (photodiode) at the other end. Light travels inside the
fiber by the process of total internal reflection. Data is modulated onto a light beam using
frequency modulation.
 Each optical fiber has the following parts:
 Core : It is the thin glass rod at the center through which light travels.
 Cladding : It is the outer optical material surrounding the core that reflects the light
back into the core.
 Buffer coating : It is the plastic coating that protects the cable from damage and
moisture.
 The major advantages of the optical fiber cable are as follows:
 It can carry data over very large distance at a stretch.
 It has a very high bandwidth ( rates of more than 100 Gbps possible)
 It is completely immune to noise i.e. not susceptible to electromagnetic fields.
 It is difficult to tap and so better data security is possible.
 Highly suitable for harsh industry environments.
 The major disadvantages of the optical fiber cable are as follows:
 It is very fragile and so difficult to install. Especially skilled people are required to
install optical fiber cables.
 It is the most expensive cable.
 It is difficult to tap and this poses a problem when legal tapping is required..
 Connecting two fibres together or connecting the light source with the cable is a
difficult process. Hence, connection loss is a common problem.
 Light can reach the receiver out of phase.
 Fibre optic cables can be of two types:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 234


Single Node Fibre optic cables: Support a segment length of 2 Km and bandwidth upto
100 Mbps.
Multi Node Fibre optic cables: Support a segment length of 100 Km and bandwidth of
2 Gbps.
Ethernet Cable
 A LAN was developed by Xerox Corporation in 1976 at the Palo Alto Research Centre. This
LAN connected over 100 Personal workstations on a 1 Km cable at 2.94 Mbps. It used a bus
topology and regulated traffic using CSMA/CD. This LAN was called the "Ethernet". ( The
term was coined because of an earlier (incorrect) belief that electromagnetic radiation
propagated over a medium called luminiferous ether).
 Ethernet refers to a specific product that implements the IEEE 802.3 standard for a 1-persistent
(i.e. the sender continuously senses the channel if it finds it busy) CSMA/CD LAN. Normally
the standard is for speeds varying from 1 to 10 Mbps on various media but the most popular is
a 10 Mbps baseband system using 50ohm coaxial cable.
 An Ethernet card is a card that is used in a computer for interfacing it to an Ethernet LAN. In
other words, it is a special card that has to be inserted in computers that are part of an Ethernet
LAN.
 The Ethernet card contains the following connectors:
(a) The RJ45 ( Registered Jack 45) connector for connecting to a twisted pair.
(b) The BNC (Bayone- Neill- Cocelman) connector for connecting to a coaxial cable.
(c) The AUI (Attachment Unit Interface) which can connect to a twited pair, a coaxial fibre or
fibre optic cables.
Wireless Technologies –
Blue Tooth
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 235









Bluetooth technology uses radio waves in the frequency range of 2.402 GHz to 2.480 GHz.
Bluetooth wireless technology is a short-range communications technology ( approx. 10 m
) intended to replace the cables connecting portable and/or fixed devices while maintaining
high levels of security.
Line of sight between communicating devices is not required.
Blue tooth can connect upto 8 devices simultaneously. Bluetooth uses a technique called
spread-spectrum frequency hopping that makes it rare for more than one device to be
transmitting on the same frequency at the same time. Thus Bluetooth devices do not
interfere with one another.
Data transfer rate is slow- up to 1 Mbps.
The key features of Bluetooth technology are robustness, low power, and low cost.
Blue tooth creates personal area networks (PANs) or piconet with high levels of security
that may fill a room or may encompass no more distance than that between the cell phone
on a belt-clip and the headset on your head.
The walls in your house won't stop a Bluetooth signal, making the standard useful for
controlling several devices in different rooms.
Originally invented by telecoms vendor Ericsson in 1994 today Bluetooth is managed by
the Bluetooth Special Interest Group.
Infrared
 Infrared waves have a frequency range of 300 GHz to 400 THz. They are so called as they
have a frequency range of just less than that of red light. InfraRed refers to light waves of a
lower frequency than human eyes can receive and interpret.
 These waves are used for short range ( approx. 5m ) communication. Performance drops
with longer distances.
 Infrared is used in most television remote control systems. Cordless phones and intrusion
detectors are also some devices that use infrared.
 Infrared communications are fairly reliable and don't cost very much to build into a device.
(advantage)
 Infrared waves have the drawback that they do not pass through solid objects. This can be a
plus point too as infrared system in one room will not interfere with a similar system in
adjacent rooms. (advantage + disadvantage)
 Infrared is a "line of sight" technology. For example, you have to point the remote control
at the television or DVD player to make things happen. This also means that information
passed to one device is not leaked to another. Because infrared transmitters and receivers
have to be lined up with each other, interference between devices is uncommon.
 Infrared is almost always a "one to one" technology. You can send data between your
desktop computer and your laptop computer, but not your laptop computer and your PDA
at the same time.. The one-to-one nature of infrared communications is useful in that you
can make sure a message goes only to the intended recipient, even in a room full of infrared
receivers.
 No government license is required for their use. (advantage)
 It is sensitive to fog and other atmospheric conditions ( disadvantage ).
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 236
Microwave
 Microwaves have a frequency range of 300 MHz to 300 GHz.
 Permits data transmission rates of 16 Gbps.
 Microwaves travel in straight lines ( line of sight transmission ) through air or space
without any wire or cable.
 They cannot penetrate any solid objects.
 For long distance communication high towers are built and signals are sent through
directional parabolic antennas placed on top of these towers and are received by similar
antennas. The distance between the towers depends on factors like the wave frequency and
the height of the towers.
 Since the waves travel in straight lines the sending and receiving antennas have to be
aligned with each other.
 Advantages:
o Free from land acquisition rights. Wired media often require formalities like getting
permission to dig the land for cabling.
o Building a 100m high tower is sometimes a cheaper option than digging a 100km
trench, laying a cable in it and closing it again.
o Wireless transmission has an advantage as ground cables can be broken say by
rodents or by overzealous gardeners digging in their backyards.
o Offers ease of communication over difficult terrain.
 Disadvantages:
o The transmission is in straight lines so the transmitting and receiving antennas need
to be properly aligned.
o Signals cannot cover a wider area because the earth’s curvature, mountains and
other structures often block line of sight. Repeaters are required every 25 to 30 km
which increase the cost..Installation and maintenance is also expensive.
o Affected by thunderstorms and other atmospheric phenomenon.
o Signals from a single antenna may split up and propagate by slightly different paths
to the receiving antenna. When these out of phase signals recombine, they interfere
reducing signal strength.
Radio
Link
 Radio waves have a frequency range of 3 KHz to 3 GHz.
 These are used for communication over distances ranging from a few meters (in walkie
talkies) up to covering an entire city.
 Cordless phones, AM and FM radio broadcast, garage door openers etc. are examples of
radio wave transmission.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 237








These waves are easy to generate, can travel long distances and can penetrate buildings
easily. That is why they are widely used for communication, both indoors and outdoors.
Radio waves are omni-directional i.e. spread in all directions. So the transmitting and the
receiving antennas need not be aligned. (advantage)
They offer ease of communication over difficult terrain. (advantage)
They are relatively inexpensive than wired media. (advantage)
Their transmission can be interfered by motors and other electrical equipment and weather
effects like rain, thunder storm etc. (disadvantage)
Permission from concerned authorities is required for use of radio wave transmission.
(disadvantage)
Less secure mode of transmission. (disadvantage).
Radio waves can travel through long distances in all directions. Also they can easily pass
through obstacles like a building. So they can be used for both indoor and outdoor
communication.
Satellite Link;
 Communication with the help of satellites.
 A number of communication satellites are placed in stationary orbits above the earth's
surface. These accept data/signals transmitted from a earth station on a specific frequency,
amplify them and retransmit them to another earth station. These satellites have multiple
independent reception and transmitting devices called transponders.
 Transmission from the earth to a satellite is known as an uplink. Transmission from the
satellite to the earth is known as downlink. Frequency used for the uplink varies from 1.6
GHz to 30.0 GHz and that for downlink varies from 1.5 GHz to 20.0 GHz. Downlink
frequency is always lower than the uplink frequency.
 Satellites can be used for very long distance wireless communication which may range
from intercity to intercontinental. The problem of blockage of line of sight due to the
earth’s curvature taken care of. (advantage)
 However, satellite system is very expensive. (disadvantage)
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 238

Communication satellites are normally owned by governments or by government approved
organizations of various countries and thus satellite communication requires legal
permissions. (disadvantage)
 Transmission is affected by weather conditions like rain, thunderstorm etc. (
disadvantage).
 Since signals sent to a satellite are broadcasted to all receivers, necessary security measures
have to be taken to prevent unauthorized tampering of data ( disadvantage ).
MODEM
 Modem stands for Modulator/ Demodulator.
 It is a device that generally connects a computer to a telephone line.
 It converts digital signals into analog(modulation) and vice versa (demodulation).
 The process of conversion of digital data into analog is called modulation. An analog wave
generally has 3 characteristics- amplitude, frequency, phase. Digital data is encoded on an
analog sine wave by varying one of these three characteristics. (The analog wave that carries
the digital data is called a carrier wave).If the amplitude of the carrier wave is modified with
respect to the input digital data it is called amplitude modulation. If the phase of the carrier
wave is modified with respect to the input digital data it is called phase modulation. If the
frequency of the carrier wave is modified with respect to the input digital data it is called
frequency modulation.
ETHERNET CARD
 A LAN was developed by Xerox Corporation in 1976 at the Palo Alto Research Centre. This
LAN connected over 100 Personal workstations on a 1 Km cable at 2.94 Mbps. It used a bus
topology and regulated traffic using CSMA/CD. This LAN was called the "Ethernet". ( The
term was coined because of an earlier (incorrect) belief that electromagnetic radiation
propagated over a medium called luminiferous ether).
 Ethernet refers to a specific product that implements the IEEE 802.3 standard for a 1-persistent
(i.e. the sender continuously senses the channel if it finds it busy) CSMA/CD LAN. Normally
the standard is for speeds varying from 1 to 10 Mbps on various media but the most popular is
a 10 Mbps baseband system using 50ohm coaxial cable.
 An Ethernet card is a card that is used in a computer for interfacing it to an Ethernet LAN. In
other words, it is a special card that has to be inserted in computers that are part of an Ethernet
LAN.
 It is also called a Network Interface Card ( NIC ).
 The Ethernet card contains the following connectors:
o The RJ45 ( Registered Jack 45) connector for connecting to a twisted pair.
o The BNC (Bayone- Neill- Cocelman) connector for connecting to a coaxial cable.
o The AUI (Attachment Unit Interface) which can connect to a twited pair, a coaxial fibre or
fibre optic cables.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 239
RJ45 CONNECTOR
 Stands for Registered Jack 45 connector.
 It is an 8 wire connector.
 It is used for connecting computers to an Ethernet LAN.
 It is similar to the RJ11 connector that connects to a telephone but has 8 wires instead of 4.
HUB
 A Hub is a hardware device that is used to connect several computers together.
 Simply put, a Hub is a distribution point.
 A hub has many ports and these ports are connected to the computers that are to be
interconnected. A hub uses broadcast i.e. it replicates whatever it receives on one port onto all
other ports.
 There are two types of Hubs - Active Hubs and Passive Hubs.
 Active Hub :
o It is a powered distribution point i.e. it uses power.
o It electrically amplifies the signal as it moves.
o The maximum distance covered is about 2000 ft.
o It can be cascaded to connect 8 connections to which passive hubs, file servers or another
active hub can be connected.
 Passive Hub :
o It is a passive distribution point i.e. it does not use power.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 240
o It passes the signal from one computer to another without change.
o The maximum distance covered is about 300 ft.
o It can connect up to 4 nodes within a very short distance.
SWITCH
 A switch is also used to interconnect computers together.
 Unlike a Hub, a switch keeps a record of the MAC addresses of the devices that are connected
to its ports. When a switch receives a data packet it forwards the packet directly to the recipient
device by looking up the MAC address.
 A switch is used to segment networks into different sub networks called subnets to prevent
traffic overloading.
 A switch keeps traffic between two devices from getting in the way of other devices using the
same network. Hence, it makes the most efficient use of the available bandwidth.
REPEATER
 A repeater is a physical relay i.e. works at the physical level of the OSI model.
 It links segments of a single LAN.
 It amplifies all incoming signals before retransmitting them.
GATEWAY
 A network connector (device used to connect two networks) that operates at i.e. connects at the
application layer of the OSI model.
 Simply put, it is a network point that acts as an entrance to another network.
 A gateway performs protocol conversion as it can connect networks having different protocol
families (e.g. it could connect to a network that does not use the OSI model at all).
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 241

A gateway could be used to connect your LAN to the internet. Thus, it needs to be securely
configured.
ROUTER
 A router is a network relay i.e. it connects two networks at the network layer of the OSI model.
 It connects two LANs that are physically as well as logically different.
 Routers are intelligent devices. They can route packets over multiple communication paths.
WIFI CARD
 Wireless Internet card. Allows us to connect to the internet without the use of cables.
NETWORK TOPOLOGIES
WHAT IS A TOPOLOGY?
 Topology refers to the manner in which nodes/workstations in a network are
interconnected.
COMMON TOPLOGIES
 Star
 Bus
 Ring
 Tree
 Graph
 Fully Connected
THE BUS TOPOLOGY


In bus topology all the nodes are connected to a main cable called backbone. If any node
has to send some information to any other node, it sends the signal to the backbone. The
signal travels through the entire length of the backbone and is received by the node for
which it is intended.
A small device called terminator is attached at each end of the backbone. When the signal
reaches the end of backbone, it is absorbed by the terminator and the backbone gets free to
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 242








carry another signal. This prevents the reflection of signal back on the cable and hence
eliminates the chances of signal interference.
This topology is easy to install as it has a simple wiring layout. ( advantage )
It requires less cable length and hence it is cost effective. ( advantage )
Easy to extend. Nodes can easily be added or removed. ( advantage )
Failure of a node does not affect the network. ( advantage )
In case of cable (backbone) or terminator fault, the entire network breaks down. (
disadvantage )
Fault diagnosis is difficult. ( disadvantage )
At a time only one node can transmit data. ( disadvantage )
Collisions can occur and must be handled properly.( disadvantage )
THE STAR TOPOLOGY
 In star topology each node is directly connected to a central hub/switch. If any node has to
send some information to any other node, it sends the signal to the hub/switch. This signal
is then broadcast (in case of a hub) to all the nodes but is accepted by the intended node(s).
In the case of a switch the signal is sent only to the intended node(s).
 It is more efficient topology as compared to bus topology. ( advantage )
 It is easy to install( advantage )
 It is easy to diagnose the fault in Star topology. ( advantage )
 It is easy to expand depending on the specifications of central hub/switch( advantage )
 Failure of any node (except the central node) does not affect the network. ( advantage )
 Failure of central hub/switch leads to failure of entire network( disadvantage )
 There is undue burden on the central node at times of heavy traffic.
 It requires more cable length as compared to bus topology. ( disadvantage )
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 243
Star Topology
THE RING TOPOLOGY
 In this topology computers are connected in a closed loop.
 Each node is connected to two neighboring nodes. Data is accepted from one of the
neighboring nodes and transmitted onwards to another. Therefore data travels in one
direction only.
 Advantages :
o Short cable lengths required
 Disadvantages:
o If any node on the network crashes the whole network crashes.
o Fault diagnosis is difficult as there is no centralized control.
THE TREE TOPOLOGY
 Tree topology is a combination of bus and star topologies.
 It is used to combine multiple star topology networks. All the stars are connected together
like a bus.
 This bus-star hybrid approach supports future expandability of the network( advantage )
 Even if one network (star) fails, the other networks remain connected and working.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 244


If the bus fails individual star networks can function but cannot communicate with each
other.
As more and more nodes and segments are added maintainability may become difficult.
THE GRAPH TOPOLOGY
 Nodes connected in an arbitrary manner
THE FULLY CONNECTED TOPOLOGY
 Each node has a connection to every other node in the network.
TYPES OF NETWORKS
BASIS FOR CLASSIFICATION:
 Networks are classified based on geographical spread i.e. the area over which the
interconnected nodes of the network are spread.
 Networks are classified as: LAN, MAN, WAN, PAN.
LAN








Stands for Local Area Network.
A small computer network confined to a localized area (e.g. an office, building or
factory).
It can cover an area of a few meters to a few kilometers.radius.
Sometimes one building can contain multiple LANs and sometimes a single LAN can
span a group of nearby buildings.
Main purpose of a LAN is sharing of resources.
There usually is complete ownership by a single organization.
Since the distance between the nodes is limited, data rate is high and error rates are low.
A LAN can be setup using wired media or may be wireless. A wireless LAN is known
as WLAN.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 245
MAN
 Stands for Metropolitan Area Network.
 Network spread over an entire city (e.g. a cable T.V. network). Often formed by
interconnecting a number of LANs and individual computers.
 It can cover an area of a few kilometers to a few hundred kilometers ( 5-50km diameter).
 Examples are a network of schools or banks or government offices.
 All types of communication media can be used for setting up a MAN though it usually uses
high speed connections using optical fibre.
 A MAN is typically owned and operated by a single entity such as a government body or a
large corporation or by a consortium of users or a single network provider who sells the
service to the users..
 Data rate lower and error rates higher as compared to a LAN.
WAN



Stands for Wide Area Network.
Network spread over countries (e.g. the Internet).
Can cover an area of over hundreds of kilometers.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 246



PAN




Examples are a network of ATMs, Banks, National Government Offices, international
organizations etc.
All types of communication media can be used for setting up a MAN.
Data rate lower and error rates higher as compared to a MAN.
Stands for Personal Area Network.
It is the interconnection of information technology devices within the range of an
individual person, typically within a range of 10 meters.
For example, a person traveling with a laptop, a personal digital assistant (PDA), and a
portable printer could interconnect them without having to plug anything in, using some
form of wireless technology. This kind of personal area network could also be
interconnected without wires to the Internet or other networks.
PAN is a technology that could enable wearable computer devices to communicate
with other nearby computers and exchange digital information using the electrical
conductivity of the human body as a data network. For example, two people each
wearing business card-size transmitters and receivers conceivably could exchange
information by shaking hands.
TCP/IP:
 Stands for Transmission Control Protocol/ Internet Protocol.
 It is a set of protocols widely used on the Internet used to allow computers to share
resources across a network.
 These protocols support a number of applications like files transfer, remote login and
electronic mail between users on different host computers on the network.
 TCP/IP uses the client/server mode of communication in which a computer user (a client)
makes a request and the server provides the requested service such as sending a Web page.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 247





Also TCP/IP communication is primarily point-to-point transmission of data which
means each communication is from one computer in the network to another computer.
TCP/IP and the higher-level applications that use it are collectively said to be "stateless"
because each client request is considered a new request unrelated to any previous one.
Till the time complete message or all packets in a message have been delivered, the
connection between the two computers remains intact but after that the transmission path is
available freely. So unlike ordinary phone conversations that require a dedicated
connection for the entire call duration, no dedicated connection is required. This makes the
network paths freely available for everyone to use.
TCP :
o The Transmission Control Protocol(TCP) breaks the data into packets that the
network can handle efficiently.
o It manages the assembling of a message or file into smaller packets that are
transmitted over the Internet.
o It verifies all the packets when they arrive at the destination computer and then
reassembles them in proper order.
o Data can be lost in the intermediate network. So TCP adds support to detect
errors or lost data and to trigger retransmission until the data is correctly and
completely received.
IP :
o The Internet Protocol(IP)handles the address part of each packet so that it
reaches to the right destination.
o It gives a distinct address (called IP address) to each data packet.
o Each gateway computer on the network checks this address to see where to forward
the message.
o Even though some packets from the same message are routed differently than others,
they'll be reassembled at the destination.
FTP:
 Stands for File Transfer Protocol.
 It is a Protocol in the Internet Suite which allows a user on any computer to get files
from another computer or to send files to another computer.
 It can transfer files of any type (ASCII or binary), but the mode has to be set in the FTP
client. If you attempt to transfer a binary file (such as a program or music file) while in text
mode, the transferred file becomes unusable.
 It is an application protocol that uses the Internet's TCP/IP protocols.
 FTP is based on Client/Server principle. By giving the ftp command with any remote
address, the file transfer can be initiated. In any FTP interface, clients identify the FTP
server either by its IP address (such as 192.168.0.1) or by its host name (such as
ftp.about.com).
 It is an efficient means to send and receive files from a remote host.
 FTP establishes two connections between the hosts. One connection is used for data
transfer and the other for control information. The control connection remains connected
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 248






during the entire interactive FTP session while the data connection is opened and closed for
each file transfer.
As a user, you can use FTP with a simple command from the Windows MS-DOS Prompt
window or with a commercial program that offers a graphical user interface.
You can even download programs by making FTP requests through your web browser.
By logging on to an FTP server, you can delete, rename, move, or copy files at a server.
However, publicly available files are easily accessed using anonymous FTP. In such a case
you need not formally sign-in to the FTP server to make a file transfer, instead you may be
simply asked to enter your email address.
But if you are using a private FTP server, you must sign in with a user name and password
to initiate the exchange of data.
Basic FTP support is usually provided as part of a suite of programs that come with
TCP/IP. However, any FTP client program with a graphical user interface usually has to be
downloaded from the company that makes it.
PPP :
 Stands for Point-to-Point Protocol.
 It is a protocol for direct communication between two computers using a serial
interface, typically a personal computer connected by phone line to a server.
 Most Internet service providers (ISPs) use PPP for customer dial-up access to
the Internet.
 PPP is used over many types of physical networks including cellular telephone, serial
cable, phone line, trunk line, specialized radio links, and fiber optic links.
 It is a data link protocol.
 It is a layered protocol.
 Has replaced the older Serial Line Internet Protocol (SLIP).
 Essentially, it encapsulates and packages your computer's TCP/IP packets into PPP frames
and then forwards them to the server over serial transmission lines such as telephone lines,
ISDN etc.
 PPP defines the format of frame to be exchanged between devices on one or multiple links
and also defines the authenticity of the two devices. It supports various authentication
schemes such as Password Authentication Protocol(PAP) and Challenge
Handshake Authentication protocol (CHAP).
Remote Login (Telnet):
 It is a protocol that is used for logging in (gaining access to the resources of) a computer
that is remote (far away) while giving the impression that you are locally connected to the
computer.
 It gives the user the opportunity to be on one computer system and do work on another,
which may be anywhere across the globe.
 It is helpful when you need to use specific applications or data located at a particular host
computer.
 Telnet clients are available for all major operating systems viz. Mac OS X, Windows,
Unix, and Linux.
 The command to start a telnet session is : telnet hostname where hostname is the name of
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 249

the remote computer to which you wish to connect. In most cases, you'll need to have an
account on that system but can also log in as guest or public without having an account.
Telnet provides a fast error free connection
INTERNET WIRELESS/MOBILE COMMUNICATION PROTOCOLS:
WIRELESS VERSUS MOBILE COMPUTING:
 When transmission is done without the use of wires it is called wireless transmission.
 In mobile communication the transmitting equipment is not fixed or restricted to one place. It
can move i.e is mobile. Thus, the computing device is not continuously connected to the base
or central network. A PDA, a cell phone or a Laptop are all examples of mobile devices.
GSM
 Stands for Global System for Mobile Communication.
 It is an International standard for Mobile communication. Around 70% of the mobile handset
market is of GSM mobiles. If you travel in Europe and many other parts of the world, GSM is
the only type of cellular service available.
 Cell phone users can buy one phone that will work anywhere where the standard is
supported. To connect to different service providers in different countries GSM users simply
need to switch SIM cards.
 Initially GSM was an acronym for 'Groupe Special Mobile' - a group formed by CEPT (
Conference of European Posts and Telegraphs) in 1982 to research the merits of a European
standard for mobile communication. It became commercial in 1991.
 GSM is a digital system that uses narrowband TDMA technology i.e. splits a frequency into
time slots and then allocates these slots to multiple calls. As many as 8 simultaneous calls can
be supported on the same radio frequency. This is possible because voice data that has been
converted to digital info is compressed so that it takes up significantly less transmission space.
 Some useful features provided by GSM are:
 Use of encryption to make phone calls more secure.
 Data networking.
 SMS for text messages, paging.
 Call forwarding.
 Facsimile services.
CDMA
 Stands for Code Division Multiple Access.
 It is a digital cellular technology.
 Uses spread spectrum techniques to transfer data. The entire frequency range ( full spectrum
) is used by each channel/user. Each users signal is spread over the entire bandwidth by a
unique spreading code. At the receiver end, that same unique code is used to recover the
signal.
GPRS
 Stands for General Packet Radio Services.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 250





GPRS is a packet-based wireless communication service that promises data rates from 56 up
to 114 Kbps and continuous connection to the Internet for mobile phone and computer users.
The higher data rates allow users to take part in video conferences and interact with
multimedia Web sites and similar applications using mobile handheld devices as well as
notebook computers.
The packet architecture also means that users pay only for the data itself rather than for the
airtime used to establish a connection and download data.
GPRS is based on Global System for Mobile (GSM) communication and complements existing
services such circuit-switched cellular phone connections and the Short Message Service
(SMS).
GPRS is often called a 2.5G technology because it is a GSM operator's first step toward third
generation (3G) and a first step in wireless data services.
WLL
 Stands for Wireless in Local Loop.
 It is a system that connects subscribers to the PSTN using radio signals.
 It allows you to have a totally shared packet switched access instead of a circuit switched
connection on a telephone network.
 Mobile telephony is primarily meant for people on the move and so a modest voice quality
and low bit data rates are acceptable and no fax or modem support is required.
WiLL is meant to serve subscribers at homes or offices. Therefore, the telephone
provided must satisfy the following:
 It must be at least as good as a wired phone.
 Its voice quality must be high -- a subscriber carrying out long conversation must
not be irritated with quality.
 One must be able to use speakerphones, cordless phones and parallel phones.
 The telephone must support fax and modem communications and should be
connectable to a Public Call Office.
 Ability to provide at least medium rate Internet access is a must.
 Further, the traffic supported should be reasonably high.
 Besides, ability to support a large number of subscribers in an urban area (large
teledensity) with a limited frequency spectrum is required.
 Finally, for the systems to be of use in developing countries, the cost of providing
this wireless access should be less than that required for wired telephone. Air-time
charges are totally unacceptable.
MOBILE COMMUNICATION TECHNOLOGIES
1G
 First generation cellular system emerged in early eighties.
 These were analog FDMA ( Frequency Division Multiple Access) systems.
 They used 400 and/or 900 MHz frequency spectrum to provide analog voice connection to
mobile users.
2G
 The second generation mobile systems emerged In late 80's.
 These systems were digital and mostly used TDMA ( Time Division Multiple Access).
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 251


GSM was the most prominent amongst these.
Initially designed for 900 MHz operation, the systems are now available in 1800 MHz and
1900 MHz.
3G
 Stands for Third generation wireless.
 3G is based on W-CDMA ( Wide Code Division Multiple Access ).
 It has benefits such as a broad bandwidth, high speed communication and roaming capability.
It is currently capable of speeds upto 384 Kbps but aims at speeds greater than 2 Mbps.
 Marks a shift from voice centric services to multimedia (video, voice, data, fax) oriented
services. 3G phones are turning phones into multimedia players making it possible to
download music and video clips easily. High speed mobile Internet access is now possible.
 3G has the capability to unify existing cellular standards such as GSM, CDMA, TDMA, EDGE
(Enhanced Data Rates for Global Evolution) etc.
 It will be costly and technologically challenging to upgrade to 3G technology.
 Japan is a leader in 3G technology
4G
 Stands for Fourth generation wireless.
 Succeeds the 3G technology and so offers much faster access as compared to 3G. It is
supposed to be 4 to 10 times faster than 3G networks.
 4G technologies include HSPA+ 21/42 ( High Speed Packet Access ), WiMAX, and LTE. Sprint
uses WiMax technology for its 4G network, while Verizon Wireless uses a technology called
Long Term Evolution, or LTE.
 4G is ideally suited for services which demand more capacity like video streaming, mapping and
social networking sites.
ELECTRONIC MAIL PROTOCOLS:
SMTP:
 Stands for Simple Mail Transfer Protocol.
 It is a protocol used for transferring e-mail across the Internet.
 The actual mail transfer is done through Message Transfer Agents (MTA) which are
present both on the client and the server.
 SMTP is a reliable and easy to set up protocol.
 SMTP allows the server to break up different parts of a message into categories the other
server can understand. Any email message has a sender, a recipient or sometimes multiple
recipients, a message body, and usually a title heading. Once a message goes out on the
internet, everything is turned into strings of text. This text is separated by code words or
numbers that identify the purpose of each section of an email. SMTP provides those codes,
and email server software is designed to interpret these codes.
 SMTP also sets up communication rules between servers. Every server has its own
way to identify itself, define the mode of communication that they will follow, check for
errors and handle them. In a typical SMTP transaction, a server will identify itself, and
announce the kind of operation it is trying to perform. The other server will authorize the
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 252



operation, and the message will be sent. If the recipient address is wrong, or if there is
some other problem, the receiving server may reply with some error message.
SMTP has a major disadvantage that it is relatively easy to send a message with a fake
sender address. This results in spread of many email-based viruses. Someone may receive a
message that they think is coming from a friend, when someone else is actually sending it.
Although attempts are being made to overcome this disadvantage but it still causes some
problems.
Most servers these days actually use a slightly updated version of the SMTP protocol called
ESMTP (Extended Simple Mail Transfer Protocol). This was created to allow transmission
of multimedia through email. When someone sends a picture or music file through their
email program, ESMTP communication codes are used to identify the kind of data being
transferred.
Mutipurpose Internet Mail Extension(MIME) is a supplementary protocol that allows non
ASCII data to be sent through SMTP. Please note that MIME is not a protocol and cannot
replace SMTP.
POP3:
 Stands for the Post Office Protocol 3. (third version of the protocol)
 It is a standard protocol for receiving e-mails.
 It is an application-layer Internet standard protocol used by local e-mail clients to
retrieve e-mail from a remote server over a TCP/IP connection.
 POP3 is designed to delete mail on the server as soon as the user has downloaded it.
However, some implementations allow users or an administrator to specify that mail be
saved for some period of time. POP can be thought of as a "store-and-forward" service.
 Supported by most webmail services such as Hotmail, Gmail and Yahoo! Mail.
 The conventional port number for POP3 is 110.
PROTOCOLS FOR CHAT AND VIDEO CONFERENCING
CHAT:




A real time informal communication over the Internet is chatting.
A chat program is software which is required for chatting over the internet. AOL Instant
Messenger, Campfire, Internet Messenger, MSN Messenger are some commonly used chat
programs.
In order to chat, the user should have an account on a chatting program.
A phone call is a voice based chat while online chat is textual conversation.
Internet Relay Chat (IRC)



IRC is the protocol used for chatting.
It provides chatting between a group or between two individuals.
It was developed by Jarkko Oikarinen in Finland in the late 1980s.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 253

It is based on client/server model. The IRC client sends and receives messages to and
from an IRC server. The IRC server transports the message from one client to another. The
IRC server is linked to many other servers to form an IRC network.
 IRC server identifies every user through a unique nickname. Each user is assigned a unique
channel in case multiple discussions are taking place.
VOIP:




VoIP stands for Voice over Internet Protocol.
It is a method for taking analog audio signals, like the kind you hear when you talk on
the phone, and turning them into digital data that can be transmitted over the Internet.
Thus, it enables the transfer of voice using packet switched network.
This method of making phone calls is much cheaper than convectional way because the
service of Telecommunication Company is not used. In fact, VoIP can turn a standard
Internet connection into a way to place free phone calls.
There are three different methods of VoIP service in common use today:
o ATA –
 ATA stands for analog-to-digital converted.
 It is used to connect the telephone device to the computer.
 It takes the analog signals from the phone and converts them to digital
signals. These digital signals can then be transmitted over the internet.
 Some providers also are bundling ATAs free with their service.
o IP phones –
 IP phones appear much like an ordinary telephone or cordless phone.
 They are directly connected to the router or the LAN.
 They have all the hardware and software necessary right onboard to handle
the IP call.
 IP Phones are sometimes called VoIP telephones, SIP phones or Soft
phones.
o Computer-to-computer –
 It is the most easy and simplest way to use VoIP. The basic hardware
requirements are as follows:
 Computer
 Internet
 Speakers
 Microphone
 The only cost involved with computer - to- computer VoIP is the monthly
ISP fee.
WIRELESS TECHNOLOGIES
WIFI




WiFi stands for Wireless Fidelity.
WiFi is the wireless way to handle networking.
It is also known as 802.11 networking and wireless networking.
The big advantage of WiFi is its simplicity. You can connect computers anywhere in your
home or office without the need for wires.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 254







The computers connect to the network using radio signals, and computers can be up to 100
feet – 300ft apart.
A person with a WiFi device can connect to the internet or Local area network using an
access point, provided that the device should be in the range of that Wireless access point.
Wireless access point (WAP) connects a group of wireless devices to an adjacent wired
LAN. The region covered by one or several Wireless access points is called a hotspot.
WiFi radios that work with the 802.11b and 802.11g standards transmit at 2.4 GHz, while
those that comply with the 802.11a standard transmit at 5 GHz.
WiFi radios use much more efficient coding techniques that also contribute to the much
higher data rates. For 802.11a and 802.11g, the technique is known as orthogonal
frequency-division multiplexing (OFDM). For 802.11b, it is called Complementary Code
Keying (CCK).
The radios used for WiFi have the ability to change frequencies. 802.11b cards can transmit
directly on any of three bands, or they can split the available radio band width into dozens
of channels and frequency hop rapidly between them. The advantage of frequency hopping
is that it is much more immune to interference and can allow dozens of WiFi cards to talk
simultaneously without interfering with each other.
Many new laptops already come with a WiFi card built in. For a laptop, this card will
normally be a PCMCIA card that you slide into a PCMCIA slot on your laptop. Or you can
buy a small external adapter and plug it into a USB port. For a desktop machine, you can
buy a PCI card that you install inside the machine, or a small external adapter that you
connect to the computer with a USB cable.
A hotspot is a connection point for a WiFi network. It is a small box that is hardwired into
the Internet. The box contains an 802.11 radio that can simultaneously talk to up to 100 or
so 802.11 cards. There are many WiFi hotspots now available in public places like
restaurants, hotels, libraries and airports.
WIMAX
 Stands for Worldwide Interoperability for Microwave Access.
 It is a telecommunications protocol that provides fixed and mobile Internet access.
 Based on Wireless MAN technology.
 The name "WiMAX" was created by the WiMAX Forum.
 The forum describes WiMAX as "a standards-based technology enabling the delivery
of last mile wireless broadband access as an alternative to cable and DSL".
 It refers to interoperable implementations of the IEEE 802.16 wireless-networks standard.
 WiMAX can provide broadband wireless access (BWA) up to 30 miles (50 km) for fixed
stations, and 3 - 10 miles (5 - 15 km) for mobile stations. In contrast, the WiFi/802.11
wireless local area network standard is limited in most cases to only 100 - 300 feet (30 100m). This is because a WiMAX tower can provide coverage to a very large area -- as big
as 3,000 square miles (~8,000 square km).
 With WiMAX, WiFi-like data rates are easily supported, but the issue of interference is
lessened.
 In practical terms, WiMAX would operate similar to WiFi but at higher speeds, over
greater distances and for a greater number of users.
 WiMAX could potentially erase the suburban and rural blackout areas that currently have
no broadband Internet access because phone and cable companies have not yet run the
necessary wires to those remote locations.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 255
VIRUSES
 A computer virus is a program written to interfere with the proper functioning of a
computer.
 It may damage programs, delete files, reformat hard disks and perform other forms of
destructive acts.
 A virus is normally capable of executing itself by placing its own code in the execution
path of another program which is called the host program.
 Viruses are also able to replicate themselves by replacing existing computer files with
copies of the virus-infected files.
WORMS
 A worm is a program made to replicate itself automatically. It replicates continuously until
the entire hard disk space and memory are eaten up.
 Unlike the typical virus, the worm does not require a host program to propagate. A worm
enters a computer through a weakness in the computer system and propagates itself using
network flaws.
 A worm normally sends copies of itself to other computers through network flaws,
therefore bypassing any need for user intervention.
 Worms harm a computer or a computer network by consuming bandwidth and slowing
down the network speed.
TROJAN HORSES:
 Trojan Horses are common but dangerous programs that hide within other seemingly
harmless programs.
 Once installed, the program will infect other files throughout your system and potentially
wreak havoc on your computer. They can even send important information from your
computer over the Internet to the developer of the Trojan. The developer can then
essentially control your computer, slowing your system's activity or causing your machine
to crash.
 With the help of Trojan, harms that could be done by a hacker on a target computer system
are:
Data theft (e.g. passwords, credit card information, etc.)
Installation of unwanted software
Downloading or uploading of files
Modification or deletion of files
Keystroke logging
Viewing the user's screen
Wasting computer storage space
Crashing the computer
 You have to consciously or unconsciously run the .exe file to install the program -- it
doesn't propagate on its own like a virus.
 They are generally transferred by emails, attachments and freeware & shareware software.
SPAMS:
 Spam is flooding the Internet with many copies of the same message, in an attempt to force
the message on people who would not otherwise choose to receive it.
 Most spam is commercial advertising, often for dubious products.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 256
HACKING
 A hacker is a person who has enough knowledge to break into a computer system or
facility though he normally does not cause any harm to the computer system or
organization. He normally violates computer security to prove his intellectual genius, to
help an organization discover security flaws or to exercise his mental faculty.
 A cracker, on the other hand, is a person who gains unauthorized access to a computer and
it’s data with malicious intent.
IPR ISSUES
 IPR stands for Intellectual Property Rights.
 Since computer software or other work created on the computer represents intellectual
property, the creator of such work can obtain a copyright or patent for his work and hence
exercise control over it’s usage and distribution.
COOKIES
 A cookie is a piece of text that a Web Server can store on a user's hard disk.
 Cookies thus allow a web site to store information on a user's machine and later retrieve it.
This information is normally in the form of name-value pairs and allows the Web site to
identify the user.
 When the user types the URL of a Web Site in the browser, the browser sends a request to
the Web site for the page. While doing so it also looks for the cookie file created by that
site and if present it sends its contents to the server along with the URL. The Web site can
use that information. If no cookie file was present, the Web site knows that you are a first
time user and so it creates a new cookie file for you that it sends along with the header for
the web page it sends and the browser creates the new cookie file on your hard disk.
 Web sites use cookies to:
o Accurately determine how many people visit the site.
o Customize the site appearance for the site visitor ( e.g. a site offers customized
weather information based on the zip code of the user).
 E commerce sites can implement things like a shopping cart and quick checkout options.
 Though cookies are only benign text files they can pose a security hazard because of the
following:
o A web site can track a lot of information about the user from the pages that the user
reads, the ads that he clicks on, the purchases that he makes. The site could
aggregate that information in a database and distribute it making the user a target
for telemarketing and junk mails.
o Certain infrastructure providers (like DoubleClick ) can create cookies that are
actually visible on multiple sites, gather information about you from multiple sites
and so form very rich profiles. They could also link these profiles back to name and
address information and then threaten to sell that personal data.
CYBER CRIMES
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 257




Cyber crime (or Computer crime) refers to any crime wherein the computer is either a tool
or a target or both.
Cyber crimes are crimes like online banking frauds, online share trading fraud, source code
theft, credit card fraud, tax evasion, virus attacks, cyber sabotage, phishing attacks, email
hijacking, denial of service, hacking, pornography, sending obscene or offensive messages
etc.
The cyber police work as a detector to detect the cyber crime.
Cyber crime is dealt with by the Cyber Law.
CYBER LAW
 Cyber Law is the law governing computers and the Internet.
 Deals with legal issues related to the use of networked information devices.
 Includes laws governing intellectual property, software licences, unauthorized access, data
privacy, spamming, hacking etc.
 Deals with Cyber Crimes.
 Cyber Law is important today as today’s world is highly digitized. E.g.
o Almost all transactions in shares are in demat form.
o Almost all companies extensively depend upon their computer networks and keep
their valuable data in electronic form.
o Government forms including income tax returns, company law forms etc are
now filled in electronic form.
o Consumers are increasingly using credit cards for shopping.
o Most people are using email, cell phones and SMS messages for communication.
o Even in "non-cyber crime" cases, important evidence is found in computers / cell
phones e.g. in cases of divorce, murder, kidnapping, tax evasion, organized crime,
terrorist operations, counterfeit currency etc.
o Digital signatures and e-contracts are fast replacing conventional methods of
transacting business.
INDIA IT ACT
 The Information Technology Act, 2000 was renamed as Information Technology
(Amendment) Act 2008 and is referred to as ITAA 2008.
 This is an Act to provide legal recognition for the transactions carried out by means of
electronic data interchange and other means of electronic communication, commonly
referred to as "Electronic Commerce", which involve the use of alternatives to paper based
methods of communication and storage of information.
 It also aims to facilitate electronic filings of documents with the Government agencies.
 It lays down procedures for authentication of electronic records by affixing digital and
Electronic signatures, electronic governance, attribution, acknowledgement and despatch of
electronic records.
 It talks about the duties of the subscriber and also about the offences and the
penalties.
INTRODUCTION TO WEB SERVICES
World Wide Web (WWW)
 It is an Internet service that allows the Internet user to explore the Internet- in other words an
information retrieval system on the Internet.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 258

It refers to the universe of information present on the Internet as a hyperlinked database
available via the Hyper Text Transfer Protocol (HTTP).
 It is called the web as it is made up of many web sites linked together and users can travel from
one site to another by clicking on hyperlinks.
 It is a network of information servers principally ones using HTTP to serve up HTML
documents. What this means is that the web presents information as a series of documents
(referred to as Web Pages). These documents are prepared using HTML. One document can
point to another document via hyperlinks.
 It is non-linear. There is no top, no bottom. You do not need to follow a hierarchical path to
information resources.
 It can also understand other internet protocols like ftp, telnet etc.
Web page
 The basic unit of information on the Web is a Web page.
 It is a page prepared using a language called HTML.
 It contains hypertext (a term coined by Ted Nelson).
 Hypertext is ordinary information plus hyperlinks.
 A hyperlink is a word or a group of words or even an image that points to another information
resource (i.e. when you click on it you open up another web page). When viewed with an
Internet browser, hyperlinks appear highlighted or underlined or in a different colour. Clicking
on them leads to another location.
Hypertext
 It is a term coined by Ted Nelson.
 Hypertext is ordinary information plus hyperlinks.
 A hyperlink is a word or a group of words or even an image that points to another information
resource.
 When viewed with an Internet browser, hyperlinks appear highlighted or underlined or in a
different colour. Clicking on them leads to another location
Hyperlink
 A hyperlink is a word or a group of words or even an image that points to another information
resource.
 When viewed with an Internet browser, hyperlinks appear highlighted or underlined or in a
different colour. Clicking on them leads to another location.
Web site
 A set of Web pages that can be visited by browsers.
Home page
 A home page is generally the first page of a web site.
 It contains details about a particular entity such as a person, a company, a group of people or
an organization.
 A home page generally leads you to other pages of the web site.
HTML(Hyper Text Markup Language) :
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 259

The language of the world wide web used to create Web pages, with hyperlinks and markup for
text formatting (heading styles, bold, italics, numbered lists, insertion of images etc.)
XML(Extensible Markup Language):
 It is a markup language for documents that contain structured information (contents + some
indication of the role that the content plays).
 It is a meta language for describing markup languages.
 It provides a facility for defining tags and the relationship between tags.
HTTP(Hyper Text Transfer Protocol) :
 The set of rules using which World Wide Web browsers and servers communicate.
 The protocol used most often to transfer information from Web servers to Web browsers.
DOMAIN NAME
 Domain name is a unique name assigned to a web site.
 It is a familiar, easy to remember name for a computer web site on the Internet (such as
google.com). Domain names are therefore used generally as a convenient way of locating
information and reaching others on the Internet.
 Since web sites are stored on computers and each computer on the Internet has a unique IP
address the domain names internally correspond to a series of numbers called Internet
Protocol numbers or IP addresses.
 A domain name is contained in a URL. Generally it has 3 parts:
o www
o Name describing the website’s purpose.
o Top level Domain (TLD) e.g. .com, .net, .edu….
 The part on the left, after www, names the organization and the part on the right helps
identifying what type of agency or organization is hosting the site. For example:
.com
commercial site.
.edu
educational institution.
.gov
U.S. government.
.mil
military.
.net
network.
.org
non-profit organization.
Other endings may be added to meet the demands of new site names.
Countries have their own URL endings as well. Example:
.in
India
.fr
France
.kr
Korea
.ca
Canada
.ph
Philipines
.au
Australia.
.uk
The United Kingdom.
URL
 Stands for Uniform Resource Locator.
 It is the addressing scheme used on the Internet i.e. it is used to locate and access information
stored on the Internet.
 A URL consists of two parts:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 260

a) a protocol prefix ( http://, gopher://, ftp://, telnet:// )
b) a domain name (identifies the Internet site)
c) path and file name ( the path of directories and subdirectories to be followed to reach the
desired file.) If only the protocol prefix and the domain names are mentioned then the
index.html file in the root directory of the accessed server is automatically accessed.
Example of a URL:
http://www.dotsurf.com/animals/cowbells.html
http:// -> protocol prefix indicating that what follows is a web page.
www.dotsurf.com -> domain name.
Animals/cowbells.com -> path and filename
Web browser
 A program that allows users to read Web pages and navigate between them. It thus acts as an
interface between the user and the World Wide Web.
 Examples are: Netscape Navigator, Lynx, and Internet Explorer.
 A browser can be only text based or graphics based.
 A browser acts as a Web Client i.e. it:
a) contacts a web server and requests for information.
b) Receives the information and displays it on the user computer.
 Browsers often include helper applications which are generally software programs needed to
display images, hear sounds or run animation sequences. These are automatically invoked
when a user selects a link to a resource that requires them.
 Most web browsers are capable of accessing gopher directories, downloading FTP files and
sending emails.
Web server
 A computer on the Internet running a WWW server process capable of entertaining requests
from Clients and servicing them.
 Servers can be of two types – Dedicated Servers and Non Dedicated Servers. The former are
those that only perform the function of a server while the latter are the ones that can also
double up as a workstation.
WEB HOSTING







If you want other people to view your web site, you must copy your site to a public server
that is attached to the Internet all the time.
Web Hosting Service is a type of Internet Hosting Service that allows individuals and
organizations to make their own website accessible via the World Wide Web.
Web hosting is done by allowing the user to upload his file ( i.e. copy it from his machine
to a server ) via the File Transfer Protocol. This is also called publishing a web site.
Web hosts are companies that provide space on a server they own or lease for use by their
clients as well as providing Internet connectivity, typically in a data centre.
Even if you can use your own PC as a web server, it is more common to let an Internet
Service Provider (ISP) host your site.
Included in a Web hosting solution you can expect to find domain name registration and
standard email services.
Before choosing a web host one must take into consideration disk space, monthly traffic,
connection speed and cost involved.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 261





If your web site needs to update large quantities of information via the web, you will need a
database to store your information and so the web host must provide database support also.
Some ISPs offer free web hosting. Free web hosting is best suited for small sites with low
traffic, like personal sites. It is not recommended for high traffic or for real business.
Technical support is often limited, and technical options are few.Very often you cannot use
your own domain name at a free site. You have to use a name provided by your host like
http://www.freesite.com/users/~yoursite.htm. This is hard to type, hard to remember, and
not very professional.
Shared hosting is very cost effective. With shared hosting, your web site gets its own
domain name, and is hosted on a powerful server along with maybe 100 other web sites.
Shared solutions often offer multiple software solutions like e-mail, database, and different
editing options. Technical support tends to be good.
With dedicated hosting, your web site is hosted on a dedicated server.Dedicated hosting is
the most expensive option. This option is best suited for large web sites with high traffic,
and web sites that use special software.You should expect dedicated hosting to be very
powerful and secure, with almost unlimited software solutions.
Collocated hosting lets you place your own web server on the premises (locations) of a
service provider.This is pretty much the same as running your own server in your own
office, only that it is located at a place better designed for it.Most likely an ISP will have
dedicated resources like high-security against fire and vandalism, regulated backup power,
dedicated Internet connections and more.
WEB SCRIPTING
WHAT IS A SCRIPT?
 A script is a program or sequence of instructions that is interpreted or carried out by
another program rather than by the computer processor (as a compiled program is).
 In the Internet scenario scripts are executable instructions embedded within a Web Page or
contained in a separate file.
 Scripts are used to add interactivity to otherwise static Web pages.
TYPES OF SCRIPTS:
Scripts, in the Internet World, are of two types:
(1) CLIENT SIDE SCRIPTS:
 Scripts that are executed in the client's browser.
 Client-side scripts are often embedded within an HTML document (hence known as
an "embedded script"), but they may also be contained in a separate file, which is
referenced by the document (or documents) that use it (hence known as an "external
script").
 Their source code is visible to everyone ( using the "View source" function).
 They are browser dependent and so may not run with outdated browsers.
(2) SERVER SIDE SCRIPTS:
 Scripts that are executed in the server to create dynamic web pages.
 The visitor of the website can only see the result of execution – not the source code.
Thus, they are preferable from a security point of view.
 Such scripts can connect to databases and use data from them while running.
WHAT ARE SCRIPTING LANGUAGES?
 Languages used for writing scripts.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 262


Scripting languages are easier and faster to code in than the more structured and compiled
languages.
However, a script takes longer to run than a compiled program since each instruction is
being handled by another program first (requiring additional instructions) rather than
directly by the basic instruction processor.
EXAMPLES OF SCRIPTING LANGUAGES:
CLIENT SIDE SCRIPTING LANGUAGES:
Popular client-side scripting languages are:
 JavaScript
 VBScript
 Jscript
 PHP
SERVER SIDE SCRIPTING LANGUAGES:
Popular server-side scripting languages are:
 ASP ( Active Server Pages ) - MicroSoft
 JSP ( Java Server Pages ) - Sun
 ANSI C SCRIPTS
 Cold Fusion Markup Language. ( Adobe )
 Server Side Java Script.
 PHP
 Python
 Perl
 SMX
 Laso
 WebDNA






WEB 2.0
The term ‘Web 2.0’ was officially coined in 2004 by Dale Dougherty, a vice-president of
O’Reilly Media Inc.
It is supposed to be the second generation of the World Wide Web.
It is a movement away from static web pages to dynamic and shareable content and social
networking.
It is a more socially connected Web in which people can contribute as much as they can
consume.
A group of technologies which have become deeply associated with the term are : blogs,
wikis, podcasts, RSS feeds, folksonomies, mash ups etc., which facilitate a more socially
connected Web where everyone is able to add to and edit the information space.
In Web 2.0 it is possible to combine data from various sources, even sources that you don't
own control or even exist, and turn that into data that people can use. For example, an idea
for a Web 2.0 site might be to combine a Flickr tagged gallery of restaurants with actual
reviews that people have written about those restaurants and a connection to Google Maps
to find the restaurants in your area. The Web site which put this up might not have any of
the data for the reviews, none of the photos from Flickr, and only an interface to allow
people to pinpoint where they are or where they are going and either read reviews of local
restaurants or even post a blogged review and attach it to those already tagged.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 263



Individual production and User Generated Content is a key feature of Web 2.0. With a few
clicks of the mouse a user can upload a video or photo from their digital camera and into
their own media space, tag it with suitable keywords and make the content available to
their friends or the world in general. In parallel, individuals are setting up and writing blogs
and working together to create information through the use of wikis.
It is the idea that, by acting independently, but collectively, the ‘crowd’ is more likely to
come up with ‘the right answer’, in certain situations, than any one individual. An example
is Cloudmark, a collaborative spam filtering system, which aggregates ‘the individual
decisions of email users about what is and is not spam, outperforming systems that rely on
analysis of the messages themselves. Thus, Web 2.0 harnesses the power of the crowd.
The delivery of Web 2.0 applications and services has been driven by the widespread
adoption of one particular group of technologies which are referred to as Ajax –
Asynchronous Javascript + XML – a term first coined by Jesse James Garrett.
5.7.1.2 Sample Solved Questions:
(a) Why is a switch referred to as an intelligent hub?
1
Ans. Unlike a Hub, a switch keeps a record of the MAC addresses of the devices that are
connected to its ports. When a switch receives a data packet it forwards the packet directly
to the recipient device by looking up the MAC address as opposed to a hub that broadcasts
it to all connected devices. Thus, a switch makes the most efficient use of the available
bandwidth and so s called an “intelligent hub”.
( 1 Mark for the correct answer )
(b) Give full forms of the following:
WLL, CDMA, GPRS,ARPANET
2
Ans.
WLL : Wireless In Local Loop
CDMA : Code Division Multiple Access
GPRS : General Packet Radio Services
ARPANET : Advanced Research Project Agency Network
( ½ mark each for each correct full form. )
(c) Assume that 50 employees are working in an organization. Each employee has been allotted
a separate workstation to work. In this way, all computers are connected through the server and
all these workstations are distributed over two floors. In each floor, all the computers are
connected to a switch. Identify the type of network?
1
Ans. LAN(Local Area Network)
( 1 Mark for writing the correct answer )
(d) Arun opened his e-mail and found that his inbox was full of hundreds of unwanted . It took
him around two hours to delete these unwanted mails and find the relevant ones in his inbox.
What may be the cause of his receiving so many unsolicited mails? What can Arun do to
prevent this happening in future?
2
Ans. Arun’s email has been attacked with spam.
These may be promotional mails from different advertisement groups. Arun must have
checked some promotional offers while surfing the Internet.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 264
He should create filters in his email to stop receiving these unwanted mails.
(1 Mark for writing correct Answer)
(1 Mark for writing correct Justification to prevent Spam)
5.7.1.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
(a) Which out of the following does not come under Cyber Crime?
(i) Copying data from the social networking account of a person without his/her information &
consent.
(ii) Deleting some files, images, videos, etc. from a friend‟ s computer with his consent.
(iii) Viewing & transferring funds digitally from a person‟ s bank account without his/her
knowledge.
(iv) Intentionally making a false account on the name of a celebrity on a social networking site.
(b) Expand the following:1. GSM 2. TDMA
(c) What is the significance of cookies stored on a computer?
(d) Kabir wants to purchase a Book online and he has placed the order for that book using an ecommerce website. Now, he is going to pay the amount for that book online using his Mobile, then
he needs which of the following to complete the online transaction:1. A bank account,
2. Mobile phone which is attached to above bank account,
3. The mobile banking app of the above bank installed on that mobile,
4. Login credentials(UID & Pwd) provided by the bank,
5. Or all of above.
CBSE Sample Paper ( 2016-17)
(a) Identify the type of topology on the basis of the following:
1. Since every node is directly connected to the server, a large amount of cable is needed
which increases the installation cost of the network.
2. It has a single common data path connecting all the nodes.
(b) Expand the following:
a. VOIP
b. SMTP
(c) Who is a hacker?
(d) The following is a 32 bit binary number usually represented as 4 decimal values, each
representing 8 bits, in the range 0 to 255 (known as octets) separated by decimal points.
140.179.220.200
What is it? What is its importance?
CBSE Sample Paper ( 2015-16)
(a) Write any 1 advantage and 1 disadvantage of Bus topology.
(b) Name the protocol
i. Used to transfer voice using packet switched network.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 265
ii.Used for chatting between 2 groups or between 2 individuals.
(c) What is an IP Address?
(d) What is HTTP?
(e) Explain the importance of Cookies.
(f) How is 4G different from 3G?
CBSE Sample Paper ( 2014)
(a) Give any two advantage of using Optical Fibres.
(b) Identify the Domain name and URL from the following.
http://www.income.in/home.aboutus.hml
(c) What is Web Hosting?
(d) What is the difference between packet & message switching?
(e) Define firewall.
(f) Which protocol is used to creating a connection with a remote machine?
5.7.1.4 Questions From Previous Year Board Papers:
CBSE All India – 2017
(a)Differentiate between communication using Optical Fiber and Ethernet Cable in context of
wired medium of communication technologies.
(b) Janish Khanna used a pen drive to copy files from his friend’s laptop to his office computer.
Soon his office computer started abnormal functioning. Sometimes it would restart by itself and
sometimes it would stop different applications running on it. Which of the following options out of
(i) to (iv), would have caused the malfunctioning of the computer? Justify the reason for your
chosen option:
(i) Computer Virus
(ii) Spam Mail
(iii) Computer Bacteria
(iv) Trojan Horse
(c) Ms. Raveena Sen is an IT expert and a freelancer. She recently used her skills to access the
Admin password for the network server of Super Dooper Technology Ltd. and provided
confidential data of the organization to its CEO, informing him about the vulnerability of their
network security. Out of the following options (i) to (iv), which one most appropriately defines
Ms.Sen? Justify the reason for your chosen option:
(i) Hacker
(ii) Cracker
(iii) Operator
(iv) Network Admin
CBSE Delhi – 2017
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 266
(a) Differentiate between Radio Link and Microwave in context of wireless communication
technologies.
(b) Amit used a pen drive to copy files from his friend’s laptop to his office computer.Soon his
office computer started abnormal functioning. Sometimes it would restart by itself and sometimes
it would stop functioning totally. Which of the following options out of (i) to (iv), would have
caused the malfunctioning of the computer ? Justify the reason for your chosen option :
(i) Computer Worm
(ii) Computer Virus
(iii) Computer Bacteria
(iv) Trojan Horse
(c) Jai is an IT expert and a freelancer. He recently used his skills to access the Administrator
password for the network server of Megatech Corpn Ltd. and provided confidential data of the
organization to its Director, informing him about the vulnerability of their network security. Out of
the following options (i) to (iv), which one most appropriately defines Jai ?
Justify the reason for your chosen option :
(i) Hacker
(ii) Cracker
(iii) Operator
(iv) Network Admin
CBSE All India – 2016
(a) Differentiate between PAN and LAN types of networks.
(b) Which protocol helps us to transfer files to and from a remote computer?
(c) Write two advantages of 3G over 2G Mobile Telecommunication Technologies in terms of
speed and services?
(d) Write two characteristics of Web 2.0.
(e) What is the basic difference between Computer Worm and Trojan Horse?
(f) Categorieze the following under Client side and Server Side script category?
(i) Java Script
(ii) ASP
(iii) VB Sript
(iv) JSP
5.7.1.5 Important Tips:

Go through all the networking terms mentioned in the curriculum. You should be able to
write two lines about each term.
5.7.2 QUESTION 7 (e) Network Layout Design ( 4 Marks )
5.7.2.1 Revision Notes
Application based on notes given in the previous section. Some points to remember while solving
the problem:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 267
1. Give a possible layout for connecting all blocks together.
• Make a star type of layout with the block with the maximum number of computers
at the center and connected to all other blocks.
2. Where should the server be kept?
• In the block that has the maximum number of computers.
3. Where should the modem be placed?
• In the block that has the maximum number of computers.
4. Where should a repeater be placed?
• If the distance between any two blocks that are connected together in your layout
diagram , the distance exceeds 100 m you can place a repeater between those 2
blocks to amplify the signal.
5. Where should you place the hub/switch?
• In all buildings as it is used to interconnect computers together.
6. Which device will you prefer for more efficient utilization of bandwidth – hub /
switch?
• Switch
7. What type of network is formed?
• If the blocks are in two different cities …. WAN
• If the blocks are within a city …..MAN
• If the blocks are within a city and within a radius of 1 km ….LAN
8. Best media for connection in a hilly area ? - Radio waves
5.7.2.2 Sample Solved Questions:
Multipurpose Public School, Bengaluru is setting up the network between its Different Wings
on the school campus. There are 4 wings named as SENIOR(S), JUNIOR(J), ADMIN(A) and
HOSTEL(H).
4
Multipurpose Public School, Bengaluru
Distance between various wings are given below:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 268
Number of Computers installed at various wings are as follows:
(i) Suggest the best wired medium and draw the cable layout to efficiently connect various
wings of Multipurpose Public School, Bengaluru.
Ans. Best Wired Media : Optical Fibre or CAT5 or CAT6 or CAT7 or CAT8 or Ethernet
Cable.
(½ Mark for writing best wired medium)
(½ Mark for drawing the layout correctly)
(ii) Name the most suitable wing where the Server should be installed. Justify your answer.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 269
Ans. Wing Senior(S)- Because it has maximum number of computers.
(½ Mark for correct Wing)
(½ Mark for valid justification)
(iii) Suggest a device/software and its placement that would provide data security for the entire
network of the School.
Ans. Firewall - Placed with the server at Senior
OR
Any other valid device/software name
( ½ mark for writing the device/software name correctly )
( ½ mark for writing correct placement )
(iv) Suggest a device and the protocol that shall be needed to provide wireless Internet access
to all smartphone/laptop users in the campus of Multipurpose Public School, Bengaluru.
Ans. Device Name: WiFi Router OR WiMax OR RF Router OR Wireless Modem OR
RFTransmitter
Protocol : WAP OR 802.16 OR TCP/IP OR VOIP OR MACP OR 802.11
(½ Mark for writing correct device name)
(½ Mark for writing correct protocol)
5.7.2.3 Questions From Sample Papers:
CBSE Sample Paper ( 2017-18)
Sanskar University of Himachal Pradesh is setting up a secured network for its campus at
Himachal Pradesh for operating their day-to-day office & web based activities. They are planning
to have network connectivity between four buildings. Answer the question (i) to (iv) after going
through the building positions in the campus & other details which are given below:
The distances between various buildings of university are given as:-
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 270
Number of computers:-
As a network expert, you are required to give best possible solutions for the given queries of the
university administration:(a) Suggest cable layout for the connections between the various buildings,
(b) Suggest the most suitable building to house the server of the network of the university,
(c) Suggest the placement of following devices with justification:
1. Switch/Hub
2. Repeater
(d) Suggest the technology out of the following for setting-up very fast Internet connectivity
among buildings of the university
1. Optical Fibre
2. Coaxial cable
3. Ethernet Cable
CBSE Sample Paper ( 2016-17)
Rehaana Medicos Center has set up its new center in Dubai. It has four buildings as shown in the
diagram given below:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 271
Distances between various buildings are as follows:
Number of Computers
As a network expert, provide the best possible answer for the following queries:
i) Suggest a cable layout of connections between the buildings.
ii) Suggest the most suitable place (i.e. buildings) to house the server of this organization.
iii) Suggest the placement of the following device with justification:
a) Repeater b) Hub/Switch
iv) Suggest a system (hardware/software) to prevent unauthorized access to or from the network.
5.7.2.4 Questions From Previous Year Board Papers:
CBSE All India – 2019
Jonathan and Jonathan Training Institute is planning to set up its centre in Amritsar
with four specialised blocks for Medicine, Management, Law courses alongwith an
Admission block in separate buildings. The physical distances between these blocks
and the number of computers to be installed in these blocks are given below. You as
a network expert have to answer the queries as raised by their board of directors as
given in (i) to (iv).
Shortest distances between various locations in metres :
Admin Block to Management Block
60
Admin Block to Medicine Block
40
Admin Block to Law Block
60
Management Block to Medicine Block
50
Management Block to Law Block
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
110
Excellence
Page 272
Law Block to Medicine Block
40
Number of Computers installed at various locations are as follows :
Admin Block
150
Management Block
70
Medicine Block
20
Law Block
50
(i)
(ii)
(iii)
(iv)
Suggest the most suitable location to install the main server
of this institution to get efficient connectivity.
Suggest the devices to be installed in each of these buildings
for connecting computers installed within the building out of
the following :
 Modem
 Switch
 Gateway
 Router
Suggest by drawing the best cable layout for effective network
connectivity of the blocks having server with all the other blocks.
Suggest the most suitable wired medium for efficiently
connecting each computer installed in every building out of
the following network cables :
 Co-axial Cable
 Ethernet Cable
 Single Pair Telephone Cable

CASE STUDY BASED QUESTION :
Ayurveda Training Educational Institute is setting up its centre in
Hyderabad with four specialised departments for Orthopedics, Neurology
and Pediatrics along with an administrative office in separate buildings.
The physical distances between these department buildings and the
number of computers to be installed in these departments and
administrative office are given as follows. You, as a network expert, have
to answer the queries as raised by them in (i) to (iv).
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 273
Shortest distances between various locations in metres :
Administrative Office to Orthopedics Unit
55
Neurology Unit to Administrative Office
Orthopedics Unit to Neurology Unit
Pediatrics Unit to Neurology Unit
Pediatrics Unit to Administrative Office
Pediatrics Unit to Orthopedics Unit
30
70
50
40
110
Number of Computers installed at various locations are as follows :
Pediatrics Unit
40
Administrative Office
140
Neurology
50
Orthopedics Unit
80
(i)
(ii)
(iii)
(iv)
Ownership
Suggest the most suitable location to install the main server
of this institution to get efficient connectivity.
Suggest the best cable layout for effective network
connectivity of the building having server with all the other buildings.
Suggest the devices to be installed in each of these buildings for
connecting computers installed within the building out of
the following :
 Gateway
 Modem
 Switch
Suggest the topology of the network and network cable for efficiently
connecting each computer installed in each of the buildings out of the
following :
Topologies : Bus Topology, Star Topology
Network Cable : Single Pair Telephone Cable, Coaxial Cable, Ethernet
Cable
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 274
CBSE All India – 2017
Hi Standard Tech Training Ltd is a Mumbai based organization which is expanding its office setup to Chennai. At Chennai office compound, they are planning to have 3 different blocks for
Admin, Training and Accounts related activities. Each block has a number of computers, which are
required to be connected in a network for communication, data and resource sharing.
As a network consultant, you have to suggest the best network related solutions for them for
issues/problems raised by them in (i) to (iv), as per the distances between various blocks/locations
and other given parameters.
Shortest distances between various blocks/locations:
Number of computers installed at various blocks are as follows:
(i)
(ii)
(iii)
Suggest the most appropriate block/ location to house the SERVER in the CHENNAI
Office (out of the 3 blocks) to get the best and effective connectivity. Justify your
answer.
Suggest the best wired medium and draw the cable layout (Block to Block) to
efficiently connect various blocks within the CHENNAI office compound.
Suggest a device/software and its placement that would provide data security for the
entire network of the CHENNAI office.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 275
(iv)
Suggest a device and the protocol that shall be needed to provide wireless Internet
access to all smartphone/laptop users in the CHENNAI office
CBSE Delhi – 2017
Hi Speed Technologies Ltd. is a Delhi based organization which is expanding its office setup to
Chandigarh. At Chandigarh office campus, they are planning to have 3 different blocks for HR,
Accounts and Logistics related work. Each block has number of computers, which are required to
be connected in a network for communication, data and resource sharing. As a network consultant,
you have to suggest the best network related solutions for them for issues/problems raised in (i) to
(iv), keeping in mind the distances between various blocks / locations and other given parameters.
Shortest distances between various blocks/locations :
Number of Computers installed at various blocks are as follows :
(i) Suggest the most appropriate block/location to house the SERVER in the CHANDIGARH
Office (out of the 3 blocks) to get the best and effective connectivity. Justify your answer.
(ii) Suggest the best wired medium and draw the cable layout (Block to Block) to efficiently
connect various Blocks within the CHANDIGARH office compound.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 276
(iii) Suggest a device / software and its placement that would provide data security for the entire
network of CHANDIGARH office.
(iv) Which of the following kind of network, would it be ?
(a) PAN
(b) WAN
(c) MAN
(d) LAN
CBSE All India – 2016
Intelligent Hub India is a knowledge community aimed to uplift the standard of skills and
knowledge in the society. It is planning to setup its training centers in multiple towns and villages
pan India with its head offices in the nearest cities. They have created a model of their network
with a city, a town and 3 villages as follows.
As a network consultant, you have to suggest the best network related solutions for their
issues/problems raised in (i) to (iv), keeping in mind the distances between various locations and
other given parameters.
Shortest distances between various locations:
Number of Computers installed at various locations are as follows:
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 277
Note:
In Villages, there are community centers, in which one room has been given as training center to
this organization to install computers. The organization has got financial support from the
government and top IT companies.
(i) Suggest the most appropriate location of the SERVER in the YHUB (out of the 4
locations), to get the best and effective connectivity. Justify your answer.
(ii) Suggest the best wired medium and draw the cable layout (location to location) to
efficiently connect various locations within the YHUB.
(iii)Which hardware device will you suggest to connect all the computers within each location
of YHUB?
(iv) Which service/protocol will be most helpful to conduct live interactions of Experts from
Head Office and people at YHUB locations?
5.7.2.5 Important Tips:



Remember the distance at which amplification is required for each network cable type.
Remember that a switch is an intelligent hub.
Remember that computers within an organization form a LAN, within a city a MAN and
across cities a WAN.
Ownership
Integrity
Collaboration
Compendium/2019-20/Computer Science/Punam Pant Ma’am
Excellence
Page 278
Download