12_2009_sample_paper_computer_science_02_ms
12_2009_sample_paper_computer_science_02_ms
Answer:
Object Oriented Programming Procedural Programming
• Emphasis on Data • Emphasis on doing things (functions)
• Follows Bottom-Up approach in • Follows Top-down approach in
program design program design
• Data hiding feature prevents accidental • Presence of Global variables
change in data increase chances of accidental
change in data
• Features like data encapsulation, • Such features are not available
polymorphism, inheritance are present
(d) Write the names of the header files to which the following belong: 1
(i) frexp() (ii) isalnum()
Answer:
(i) math.h (ii) ctype.h
(e) Rewrite the following program after removing the syntactical errors (if any).
Underline each correction. 2
#include <iostream.h>
struct Pixels
{ int Color,Style;}
void ShowPoint(Pixels P)
{ cout<<P.Color,P.Style<<endl;}
void main()
{
Pixels Point1=(5,3);
ShowPoint(Point1);
Pixels Point2=Point1;
Color.Point1+=2;
ShowPoint(Point2);
}
Answer:
#include <iostream.h>
struct Pixels
{ int Color,Style;};
void ShowPoint(Pixels P)
{ cout<<P.Color<<P.Style<<endl;}
void main()
{
Pixels Point1={5,3};
ShowPoint(Point1);
Pixels Point2=Point1;
9
Point1.Color+=2;
ShowPoint(Point2);
}
10
Answer:
TiLeP550
AiLJP430
(g) In the following program, if the value of N given by the user is 20, what maximum
and minimum values the program could possibly display? 2
#include <iostream.h>
#include <stdlib.h>
void main()
{
int N,Guessnum;
randomize();
cin>>N;
Guessnum=random(N-10)+10;
cout<<Guessnum<<endl;
}
Answer:
Maximum Value: 19 Minimum Value: 10
2.
(a) What do you understand by Polymorphism? Give a suitable example of the same. 2
Answer:
Polymorphism: It is a method of using the same operator or function (method) to work
using different sets of input. Function overloading is one of the example of polymorphism,
where more than one function carrying same name behave differently with different set of
parameters passed to them.
void Display()
{
cout<<”Hello!”<<endl;
}
void Display(int N)
{
cout<<2*N+5<<endl;
}
(c) Answer the questions (i) and (ii) after going through the following program: 2
class Match
{
int Time;
public:
Match() //Function 1
11
{
Time=0;
cout<<”Match commences”<<end1;
}
void Details() //Function 2
{
cout<<”Inter Section Basketball Match”<<end1;
}
};
iii) Which category of constructor - Function 4 belongs to and what is the purpose
of using it?
Answer:
Copy Constructor, it is invoked when an object is created and initialised with
values of an already existing object.
iv) Write statements that would call the member Functions 1 and 3
Answer:
Match M1; //for Function 1
Match M2(90); //for Function 3
12
Public Members
• A function FEEDINFO() to allow user to enter values for Flight Number,
Destination, Distance & call function CALFUEL() to calculate the quantity of
Fuel
• A function SHOWINFO() to allow user to view the content of all the data
members
Answer:
class FLIGHT
{
int Fno;
char Destination[20];
float Distance, Fuel;
void CALFUEL();
public:
void FEEDINFO();
void SHOWINFO();
};
void FLIGHT::CALFUEL()
{
if (Distance<1000)
Fuel=500;
else
if (Distance<2000)
Fuel=1100;
else
Fuel=2200;
}
void FLIGHT::FEEDINFO()
{
cout<<”Flight No :”;cin>>Fno;
cout<<”Destination :”;gets(Destination);
cout<<”Distance :”;cin>>Distance;
CALFUEL();
}
void FLIGHT::SHOWINFO()
{
cout<<”Flight No :”<<Fno<<endl;
cout<<”Destination :”<<Destination<<endl;
cout<<”Distance :”<<Distance<<endl;;
cout<<”Fuel :”<<Fuel<<endl;;
}
13
public:
CUSTOMER();
void Status();
};
class SALESMAN
{
int Salesman_no;
char Salesman_Name[20];
protected:
float Salary;
public:
SALESMAN();
void Enter();
void Show();
};
class SHOP : private CUSTOMER , public SALESMAN
{
char Voucher_No[10];
char Sales_Date[8];
public:
SHOP();
void Sales_Entry();
void Sales_Detail();
};
(vi) Write the names of data members which are accessible from objects belonging
to class CUSTOMER.
(vii)Write the names of all the member functions which are accessible from objects
belonging to class SALESMAN.
(viii) Write the names of all the members which are accessible from member
functions of class SHOP.
(ix) How many bytes will be required by an object belonging to class SHOP?
Answer:
(i) None of data members are accessible from objects belonging to class CUSTOMER.
(ii) Enter(), Show()
(iii) Data members: Voucher_No, Sales_Date, Salary
Member function: Sales_Entry(), Sales_Details(), Enter(), Show(), Register(), Status()
(iv) 66
3.
(a) Write a function in C++ to combine the contents of two equi-sized arrays A and B
by computing their corresponding elements with the formula 2*A[i]+3*B[i]; where
value i varies from 0 to N-1 and transfer the resultant content in the third same
sized array. 4
Answer:
void AddNSave(int A[],int B[],int C[],int N)
{
for (int i=0;i<N;i++)
C[i]=2*A[i]+3*B[i];
}
14
(1 Mark for correct formation of loop)
(1 Mark for the formula)
(1 Mark for transferring elements in the resultant array)
(f) An array P[20][30] is stored in the memory along the column with each of the
element occupying 4 bytes, find out the memory location for the element P[5][15],
if an element P[2][20] is stored at the memory location 5000. 4
Answer:
Given,
W=4
N=20
M=30
Loc(P[2][20])=5000
Column Major Formula:
Loc(P[I][J]) =Base(P)+W*(N*J+I)
Loc(P[2][20]) =Base(P)+4*(20*20+2)
5000 =Base(P)+4*(400+2)
Base(P) =5000- 1608
Base(P) =3392
Loc(P[5][15]) =3392+4*(20*15+5)
=3392+4*(300+5)
=3392+1220
=4612
(1/2 Mark for correct formula/substitution of values in formula)
(1 ½ Mark for correctly calculating Base Address)
(2 Mark for correctly calculating address of desired location)
15
(h) Write a function in C++ to find sum of rows from a two dimensional array. 2
Answer:
void MatAdd(int A[100][100],int N,int M)
{
for (int R=0;R<N;R++)
{
int SumR=0;
for (int C=0;C<M;C++)
SumR+=A[C][R];
cout<<SumR<<endl;
}
}
True
Step 2: Push
False
True
Step 3: AND Push
Pop Pop
Op2=True Op1=False
Op2=True
True False
Step 4: Push
True
False
Step 5: Push
True
True
False
Step 6: NOT Push
Pop
Op2=True False
True True
False False
Step 7: OR Push
Pop Pop
Op2=False Op1=True
16
True Op2=False True
False False False
Step 8: AND Push
Pop Pop
Op2=True Op1=False
Op2=True
False False
Step 9: Pop
Result
False
( 1½ Mark for showing stack position for operatio ns NOT,OR and AND)
( ½ Mark for correctly evaluating the final resul t)
4.
(a) Observe the program segment given below carefully and fill the blanks marked as
Statement 1 and Statement 2 using seekg() and tellg() functions for performing the
required task. 1
#include <fstream.h>
class Employee
{
int Eno;char Ename[20];
public:
//Function to count the total number of records
int Countrec();
};
int Item::Countrec()
{
fstream File;
File.open(“EMP.DAT”,ios::binary|ios::in);
______________________ //Statement 1
Answer:
File.seekg(0,ios::end); //Statement 1
File.tellg(); //Statement 2
17
(b) Write a function in C++ to count the number of alphabets present in a text file
“NOTES.TXT”. 2
Answer:
void CountAlphabet()
{
ifstream FIL(“NOTES.TXT”);
int CALPHA=0;
char CH=FIL.get();
while (!FIL.eof())
{
if (isalpha(CH)) CALPHA++;
CH=FIL.get();
}
cout<<”No. of Alphabets:”<<CALPHA<<endl;
FIL.close();
}
(c) Write a function in C++ to add new objects at the bottom of a binary file
“STUDENT.DAT”, assuming the binary file is containing the objects of the
following class. 3
class STUD
{
int Rno;
char Name[20];
public:
void Enter(){cin>>Rno;gets(Name);}
void Display(){cout<<Rno<<Name<<endl;}
};
Answer:
void Addnew()
{
fstream FIL;
FIL.open(“STUDENT.DAT”,ios::binary|ios::app);
STUD S;
char CH;
do
{
S.Enter();
FIL.write((char*)&S,sizeof(S));
cout<<”More(Y/N)?”;cin>>CH;
}
while(CH!=’Y’);
FIL.close();
}
18
5.
(a) What do you understand by Primary Key & Candidate Keys? 2
Answer:
An attribute or set attributes which are used to identify a tuple uniquely is known as
Primary Key. If a table has more than one such attributes which identify a tuple uniquely
than all such attributes are known as Candidate Keys.
(b) Consider the following tables GAMES and PLAYER. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii) 6
Table: GAMES
GCode GameName Number PrizeMoney ScheduleDate
101 Carom Board 2 5000 23-Jan-2004
102 Badminton 2 12000 12-Dec-2003
103 Table Tennis 4 8000 14-Feb-2004
105 Chess 2 9000 01-Jan-2004
108 Lawn Tennis 4 25000 19-Mar-2004
Table: PLAYER
PCode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 101
4 Nazneen 103
(ii) To display details of those games which are having PrizeMoney more than
7000.
Answer:
SELECT * FROM GAMES WHERE PrizeMoney>7000
( ½ mark for correct SELECTion of columns)
( ½ mark for correct use of WHERE)
(iii) To display the content of the GAMES table in ascending order of ScheduleDate.
Answer:
SELECT * FROM GAMES ORDER BY ScheduleDate;
( ½ mark for correct SELECTion of columns)
( ½ mark for correct use of ORDER BY)
19
(vi)SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;
Answer:
19-Mar-2004 12-Dec-2003
( ½ mark for correct output)
6.
(a) State and algebraically verify Absorbtion Laws. 2
Answer:
X+X.Y = X
L.H.S = X+X.Y
= X.1+X.Y
= X.(1+Y)
= X.1
= X
= R.H.S
X+X’.Y = X+Y
L.H.S. = X+X’.Y
= (X+X’).(X+Y)
= 1.(X+Y)
= X+Y
= R.H.S
(b) Write the equivalent Boolean Expression for the following Logic Circuit 2
Answer:
F(U,V)=U’.V+U.V’
(Full 2 marks for obtaining the correct Boolean Expression for the Logic Circuit)
OR
(1 mark correctly interpreting Product terms)
20
(e) Write the SOP form of a Boolean function G, which is represented in a truth table
as follows: 1
Answer:
P Q R G
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
G(P,Q,R) = P’.Q.R’+P.Q’.R’+P.Q.R’+P.Q.R
F(U,V,W,Z)=UV+WZ+UZ
7.
b) Define the term Bandwidth. Give unit of Bandwidth. 1
Answer:
Bandwidth is the capability of a medium to transmit an amount of information
over a distance. Bandwidth of a medium is generally measured in bits per second
(bps) or more commonly in kilobits per second (kbps)
( ½ Mark for correct definition and ½ Mark for corr ect unit)
21
e) Define the term firewall. 1
Answer:
Firewall is a feature used for Network Security. In a Network there is always
danger of information leaking out or leaking in. Firewall is a feature which forces
all information entering or leaving the network to pass through a check to make
sure that there is no unauthorized usage of the network.
(1 Mark for correct definition)
e)
Ravya Industries has set up its new center at Kaka Nagar for its office and
web based activities. The company compound has 4 buildings as shown in
the diagram below:
Fazz
Raj
Building
Building
Jazz
Harsh Building
Building
22
e1) Suggest a cable layout of connections between the buildings. 1
Answer:
Layout 1:
Fazz
Raj
Building
Building
Jazz
Harsh Building
Building
Layout 2: Since the distance between Fazz Building and Jazz Building is quite
short
Fazz
Raj
Building
Building
Jazz
Harsh Building
Building
e2) Suggest the most suitable place (i.e. building) to house the server of
this organisation with a suitable reason. 1
Answer:
The most suitable place / block to house the server of this organisation would
be Raj Building, as this block contains the maximum number of computers,
thus decreasing the cabling cost for most of the computers as well as
increasing the efficiency of the maximum computers in the network.
23
e3) Suggest the placement of the following devices with justification: 1
(iii) Internet Connecting Device/Modem
(iv) Switch
Answer:
(i) Raj Building
(ii) In both the layouts, a hub/switch each would be needed in all the
buildings, to interconnect the group of cables from the different
computers in each block
( ½ Mark for placement of each device correctly)
e4) The organisation is planning to link its sale counter situated in various
parts of the same city, which type of network out of LAN, MAN or WAN
will be formed? Justify your answer. 1
Answer:
The type of network that shall be formed to link the sale counters situated in
various parts of the same city would be a MAN, because MAN (Metropolitan
Area Networks) are the networks that link computer facilities within a city.
( ½ mark for correct type and ½ mark for correct ju stification)
24