Computer Science 2009 Solved For CBSE C++
Computer Science 2009 Solved For CBSE C++
(Solved)
1 (a) What is the difference between call by value and call by reference? Give an ex-
ample in C++ to illustrate both.
Call by value is used to create a temporary copy of the data which is transfered from
the actual parameter in the final parameter. The changes done in the function in formal
parameter are not refelcted back in the calling environment. It does not use & sign.
Call by reference is used to share the same memory location for actual and formal
parameters and so the changes done in the function are reflected back in the calling
environment. It makes the use of the & sign as the reference operator.
Example:
A++;
B++;
cout<<“The function on display gives “;
cout<<“A = “<<A<<“&”<<“B=”<<B<<endl;
}
void main( )
{
int I=50, J=25;
cout<<“Initial of function call “<<endl;
cout<<“I=”<<I<<“&”<<“J=”<<J<<endl;
compute(I,J);
cout<<“After the call of the function”<<endl;
cout<<“I=”<<I<<“&”<<“J=”<<J<<endl;
getch( );
}
(b) Write the names of the header files to which the following belong:
(i) puts( )
(ii) sin( )
Solution:
(i) stdio.h
(ii) math.h
(c) Rewrite the following program after removing the syntactical errors (if any). Under-
line each correction.
#include [iostream.h]
#include [stdio.h]
class Employee
{
int EmpId=901;
char EName[20];
public
Employee( ) { }
void Joinint( ) { cin>>EmpId; gets(EName); }
void List( ) { cout<<EmpId<<“:”<<EName<<endl;}
};
void main( )
{
Employee E;
Joining.E( );
E.List( )
}
Solution:
#include <iostream.h>
#include <stdio.h>
class Employee
{
int EmpId;
char EName[20];
public
Employee( ) { }
void Joinint( ) { cin>>EmpId; gets(EName); }
void List( ) { cout<<EmpId<<“:”<<EName<<endl;}
};
void main( )
{
Employee E;
E.Joining( );
E.List( )
}
#include<iostream.h>
#include<ctype.h>
void Encode(char Info[ ], int N);
void main( )
{
char Memo[ ] = “Justnow”;
Encode(Memo,2);
cout<<Memo<<endl;
}
void Encode(char Info[ ], int N)
{
for (int I=0,Info[I]!=’\0’;I++)
if (I%2==0)
Info[I]=Info[I]-N;
else if (islower(Info[I]))
Info[I] = toupper(Info[I]);
else
Info[I]=Info[I]+N;
}
Solution:
HuQTlOu
(f) Study the following program and select the possible output from it.
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
int Points;
Points = 100 + random(LIMIT);
for (int P=Points; P>=100;P--)
cout<<P<<“#”;
cout<<endl;
}
(i) 103#102#101#100#
(ii) 100#101#102#103#
(iii) 100#101#102#103#104#
(iv) 104#103#102#101#100#
2 (a) What is copy constructor? Give an example in C++ to illustrate copy constructor.
(b) Answer the questions (i) and (ii) after going through the following class:
class WORK
{
int WorkId; 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+W;
}
};
(i) Which member function out of Function 1, Function 2, Function 3 and Function 4 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?
Solution: Function 1
Destructor.
Which member function out of Function 1, Function 2, Function 3 and Function 4 shown in the above
definition of class Work will be called on execution of statement written as Statement 2? What is this
function specifically known as out of Destructor or Copy Constructor or Default Constructor?
Solution: Function 4
Copy Constructor
Private Members:
COMPUTE( ) // A function to calculate and return Amount as Days* Charges and if the value of Days *
Charges is more than 11000 then as 1.02 * Days * Charges
Public Members
Solution:
class RESORT
{
int Rno;
char Name[20];
float Charges;
int Days;
float COMPUTE( );
public:
void Getinfo( );
void Dispinfo( );
};
void RESORT:: Getinfo( )
{
cin>>Rno;
gets(Name);
cin>>Charges;
cin>>Days;
}
class FaceToFace
{
char CenterCode[10];
public:
void Input( );
boid Output( );
};
class Online
{
char website[50];
public:
void SiteIn( );
void SiteOut( );
};
class Training: public FaceToFace, private online
{
long Tcode;
float charge;
int period;
public:
void Register( );
void show( );
};
Multiple Inheritance
(ii) Write names of all the member functions accessible from Show( ) function of class Training.
Register( )
Siteln( ), SiteOut( );
Input( ), Output( );
(iii) Write name of all the member accessible through an object of class Training.
(iv) Is the function Output( ) accessible inside the function SiteOut( )? Justify your answer?
No, function Output( ) is not accessible inside the function SiteOut( ), because Output( ) is a member of
class FaceToFace and SiteOut( ) is a member of class Online, and the classes FaceToFace and Online are
two independent classes.
3( a) 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
{
long Pno; // Player Number
char PName[20];
long Points;
};
Solution:
Solution:
= 5704
Address of S[20][15] =
5704 + 4 ( ( 20 - 1 ) + (15 - 1 ) x 40 )
= 5704 + 4 x 579
= 5704 + 2316
= 8020
(c) Write a function QUEINS( ) in C++ to insert an element in a dynamically allocated Queue containing
nodes of the following given structure.
struct Node
{
int PId; // Product Id
char Pname[20];
NODE *Next;
};
Solution:
Class Queue
{
Node *Front, *Rear;
public:
QUEUE( ) // Constructor to initialize Front and Rear
{
Front = NULL;
Rear = NULL;
}
void QUEINS( ); // Function to insert a node
void QUEDEL( ); // Function to delete a node
void QUEDISP( ); // Function to display nodes
~Queue( ); //Destructor to delete all nodes
};
void Queue::QUEINS( )
{
Node *Temp;
Temp = new Node;
cin>> Temp->PId;
gets(Temp->Pname);
Temp->Next=NULL;
if (Rear = = NULL)
{
Front = Temp;
Rear = Temp;
}
else
{
Rear->Next = Temp;
Rear = Temp;
}
}
(d) Define a function SWAPCOL( ) in C++ to swap (interchange) the first column elements with the last
column elements, for a two dimensional integer array passed as the argument of the function.
2 1 4 9
1 3 7 7
5 8 6 3
7 2 1 2
After swapping of the content of 1st column and last column, it should be:
9 1 4 2
7 3 7 1
3 8 6 5
2 2 1 7
Solution:
(e) Convert the following infix expression to its equivalent postfix expression showing stack contents for the
conversion:
X - Y / (Z + U) * V
Solution:
X - Y / ( Z + U) * V
= ( X - ( ( Y / ( Z + U)) * V ) )
4 (a) Observe the program segment given below carefully and fill the blanks marked as Line 1 and Line 2
using fstream functions for performing the required task.
#include<fstream.h>
class Stock
{
long Ino; // Item Number
char Item[20]; // Item Name
int Qty; // Quantity
public:
void Get(int);// Function to enter the content
void Show( ); // Function to display the content
void Purchase(int Tqty)
{
Qty+ = Tqty; // Function to increment in Qty
}
long KnowIno( )
{ return Ino;}
};
void Purchaseitem(long PINo, int PQty)
// PINo -> Info of the item purchased
// PQty -> Number of items purchased
{
fstream file;
File.open(“ITEMS.DAT”,ios::binary|ios::in|ios::cut);
int Pos=-1;
Stock S;
while (Pos==-1 && File.read((char*)&S, sizeof(S)))
if (S.KnowInc( ) == PINo)
{
S.Purchase(PQty); // To update the number of items
Pos = File.tellg()- sizeof(S);
if (Pos==-1)
cout<<“No updation done as required Ino not found...”;
File.close( );
}
Solution:
Statement 1:
File.seekp(Pos);
Statement 2:
(b) Write a function COUNT_DO( ) in C++ to count the presence of a word ‘do’ in a text file
“MEMO.TXT”.
Solution:
Solution:
void COUNT_TO( )
{
ifstream Fi1(“MEMO.TXT”);
char STR[10];
int c=0;
while (Fi1.getline(STR,10,’ ‘))
{
if (strcmpi(STR, “do”) = = 0)
C++;
}
Fi1.close( );
cout<<“Count to -do- in file: “<<c<<endl;
}
(c) Write a function in C++ to read and display the detail of all the users whose status is ‘A’ (i.e. Active)
from a binary file “USER.DAT”. Assuming the binary file “USER.DAT” is containing objects of class USER,
which is defined as follows:
class USER
{
int Uid; // User Id
char Uname[20]; // User Name
char Status; // User Type: A Active I Inactive
Public:
void Register( ); // Function to enter the content
void show( ); // Function to display all data members
char Getstatus( )
{
return Status;
}};
Solution:
void DisplayActive( )
{
USER U;
ifstream fin;
fin.open(“USER.DAT”, ios:: binary);
while (fin.read( ( char*) &U, sizeof(U)))
{
if (U.Getstatus( ) = = ‘A’)
U.show( );
}
fin.close( ); // Ignore
}
5 (a) What are candidate keys in a table? Give a suitable example of candidate keys in a table.
A candidate key is a combination of attributes that can be uniquely used to identify a database record
without any extraneous data. Each table may have one or more candidate keys. One of these candidate
keys is selected as the table primary key.
A table can easily have 2 or more candidate keys: for example, consider this table for hotel room reserva-
tions:
(b) Consider the following tables GARMENT and FABRIC. Write SQL commands for the statements (i) to
(iv) and give outputs for SQL queries (v) to (viii)
Table: GARMENT
Table: FABRIC
FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE
(i) To display GCODE and DESCRIPTION of each GARMENT in descending order of GCODE
Solution:
(ii) To display the details of all the GARMENTs, which have READYDATE in between 08-DEC-07 and
16-JUN-08 (inclusive of both the dates).
Solution:
(iii) To display the average PRICE of all the GARMENTs, which are made up of FABRIC with FCODE as
F03.
Solution:
SELECT AVG(PRICE) FROM GARMENT WHERE FCODE = ‘F03’;
(iv) To display FABRICwise highest and lowest price of GARMENTs from GARMENT table. (Display
FCODE of each GARMENT along with highest and lowest price).
Solution:
Solution:
SUM(PRICE)
2600
Solution:
DESCRIPTION TYPE
Solution:
MAX(FCODE)
F04
Solution:
COUNT(DISTINCT PRICE)
HENCE PROVED.
(b) Write the equivalent Boolean Expression for the following Logic Circuit:
Solution:
(X+Y’).(X’+Z)
(c) Write the POS form of a Boolean Function H, which represented in a truth table as follows:
A B C H
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
Solution:
(A+B+C).(A’+B+C’).(A’+B’+C_
(d) Reduce the following Boolean Expression using K-Map:
Solution:
ALSO AVAILABLE:
visit: www.schandgroup.com
R′.S′ R′.S R.S R.S′
P′.Q′′
1 1 1
M0 M1 M3 M2
P′.Q 1 1 1
M4 M5 M7 M6
1 1 1
P.Q M12 M13 M 15 M14
1 1
P.Q′′ M8 M9 M11 M10
Resultant Expression:
S + P’R + P.Q.R’
7 (a) What is the difference between STAR topology and BUS topology of network?
Star Topology:
Star networks are one of the most common computer network topologies. In its simplest form, a star network
consists of one central switch, hub or computer, which acts as a conduit to transmit messages
Bus Topology:
A bus network topology is a network architecture in which a set of clients are connected via a shared
communications line, called a bus.
It has the following format:
(i) GSM
GSM (Global System for Mobile ) communications: originally from Groupe Spécial Mobile) is the most
popular standard for mobile phones in the world. Its promoter, the GSM Association, estimates that 80% of
the global mobile market uses the standard.
(ii) CDMA
(c) What is protocol? Which protocol is used to search information from Internet using the Internet
Browser?
On the Internet, the word "protocol" refers to a set of rules for communicating. Two programs or computers
that follow the same rules are able to exchange information, even if they don't run the same operating system
and are not made by the same company.
The protocol used for searching information from Internet using the Internet Browser is TCP/IP or HTTP.
(d) Name two switching techniques used to transfer data between two terminals (computers).
(e) Freshminds University of India is starting its first campus in Ana Nagar of South India with its center
admission office in Kolkata. The University has 3 major blocks comprising of office block, science block
and commerce block in the 5 KM area campus.
As a network experts, you need to suggest the network plan as per (E1) to (E4) to the authorities keeping
in mind the distances and other given parameters.
KOLKATA
Admission
Office Freshminds University
Ana Nagar Campus
Commerce Block
Office Block
Science Block
Expected number of Computers to be installed at various locations in the university are as follows:
Office Block: 10
Commerce Block: 30
(E1) Suggest the authorities, the cable layout amongst various blocks inside university campus for connect-
ing the blocks.
Solution:
Freshminds University
Ana Nagar Campus Commerce
Block
Office Block
Science Block
(E2) Suggest the most suitable place (i.e. block) to house the server of this university with a suitable reason.
Solution:
(E3) Suggest an efficient device from the following to be installed in each of the blocks to connect all the
computers:
(i) MODEM
(ii) SWITCH
(iii) GATEWAY
Solution:
SWITCH
(E4) Suggest the most suitable (very high speed) device to provide data connectivity between Admission
Office located in Kolkata and the Campus located in Ana Nagar from the following options:
- Telephone Line
- Fixed- Line Dial-up connection
- Co-axial Cable Network
- GSM
- Leased Line
- Satellite Connection
Solution:
Satellite Connection