REVISED - SOLUTION OF XII CS - SAMPLE PAPER (BASED ON NEW PATTERN)
SAMPLE PAPER (SOLUTION- MARKING SCHEME ) CS2013
(BASED
ON NEW PATTERN) COMPUTER SCIENCE
[CODE–083] CLASS – XII
Donload Sample paper from : http://cbseacademic.in/web_material/doc/sqp/SQPCS2013Set1.pdf
|
||
Max
Time : 3 hours Max Marks : 70
|
||
1.
|
(a)
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.
AAns:- float Percent (int x=10);
|
(2)
|
1(b) 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));
}
Ans:- <iostream.h>
<math.h>
|
(1)
|
||||||
1(c)
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 a = 2,
b = 5;
demo(::a,a,b); //3,2,5 ::a means global version (declared out of
main())of a will be reffered
demo(::a,a,b);//8,2,10
}
Answer: 3*5*10
8*10*20
2.(a)
What do you understand by Data Encapsulation and Data Hiding? Also, give a
suitable C++ code to illustrate both.
Data
Encapsulation:
· Data Encapsulation
combines data and functions into a single unit called Class.
· Data Encapsulation
enables the important concept of data hiding possible.
Define a class having both data and
functions as members make all data members private to hide its
visibility/accessibility from outside
the class. Make some member function as public that will be used to interact
with the outside world from main function.
Data Encapsulation: Wrapping up of data and functions together in a single
unit is known
as Data Encapsulation. In a
class, we wrap up the data and functions together
in a single
unit.
Data Hiding:
Keeping the data in private visibility mode of the class to prevent it from
accidental change is known as Data Hiding.
class Computer
{char CPU[10];int RAM;
public: Data
Encapsulation
void STOCK();
void SHOW();
};
( ½ Mark each for appropriate definitions)
(1 Mark for appropriate example showing both)
(2)(b)
What is constructor overloading? Give an example to illustrate the same.
……………………………………………………………..ANSWER—EXAMPLE……………………………………………..
class Exam
{char Subject[20] ;
int Marks ;
public :
Exam() //
Function 1
{
strcpy(Subject, “Computer” )
;
Marks = 0 ;
}
Exam(char
P[ ]) //
Function 2
{
strcpy(Subject, P) ;
Marks=0 ;
}
Exam(int
M) //
Function 3
{
strcpy(Subject, “Computer”)
;
Marks = M ;
}
Exam(char
P[ ], int M) // Function 4
{
strcpy(Subject, P) ;
Marks = M ;
} };
(2)(c)
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. (4)
---------------------------------
ANSWER
2(C)--------------------------------------------------------------------
class
HandSet {
private :
char
Make[20];
char
Model[20];
long
int Price;
char
Rating;
public:
void
Read_Data()
{cout<<”\n Enter Make , Model ,Price and Rating : \n“ ;
gets(Make);
gets(Model); cin>>Price; cin>>Rating;}
void
Display()
{cout<<”\n
Make : “<<Make<<”\n Model : “<<Model<<”\n
Price”<< Price<<”\n Rating : “ <<Rating;}
long int
RetPrice() { return Price;}
2(d)
Consider the following class counter:
class
counter
{
protected :
unsigned
int count;
public
:
counter()
{ count
= 0; }
void
inc_count()
{
count++; }
int
get_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.
………………………ANSWER 2(D ) ……………………………..
class new_counter : public counter
{
public:
new_counter(unsigned int x)
{
count=x;
}
void dec_count(){count--;}
void Reset() {count=0;}
};
3 (a)
Write a function TRANSFER(int A[], int B[], int Size) in C++ to copy the
elements of array A into array B in such a way that all the negative elements
of A appear in the beginning of B, followed by all the positive elements,
followed by all the zeroes maintaining their respective orders in array A.
For example:
If the
contents of array A are:
7, -23,
3, 0, -8,-3,4, 0
The
contents of array B should be
-23 ,
-8, -3, 7, 3, 4, 0
------------------------------------------------ANSWER
3(a)----------------------------------------------------
#include<iostream.h>
#include<conio.h>
void transfer(int a[],int b[],int size);
void main()
{
int a[]=
{7, -23, 3, 0, -8,-3,4, 0},b[8];
transfer(a,b,8);
for(int i=0;i<8;i++)
cout<<b[i]<<'\t';
getch();
}
void transfer(int a[],int b[],int size)
{
int k=0;
for(int i=0;i<size;i++)
if(a[i]<0)
{
b[k]=a[i];
k++;
}
for(int i=0;i<size;i++)
if(a[i]>0)
{
b[k]=a[i];
k++;
}
for(int i=0;i<size;i++)
if(a[i]==0)
{
b[k]=a[i];
k++;
}
}
|
3(b) Each
element of the array A[8][6] is stored using 4 bytes of memory. If the element
A[2][4] is stored at location 936, find the address of A[5][1]. Assume that the
array is stored column-wise.
----------------------------------------------------------ANSWER
3(b)---------------------------------------------------------------------
Given : Size of each
element (w) = 4,
No of colums
(Nc) = 6, No. of rows(Nr) =8
Actual Physical
Address of A[2][4] in Column Major scheme
=Base Address + w * [(i -0) +Nr * (j-0)]
Here, i=2 and j=4;
Actual Physical Address of A[2][4] in Column Major scheme =936
So, using
formula we calculate Basic Address (BA)--
936=
BA+4(2+8*4)
936=BA+4*34
BA=936-136
BA=800
Actual
Physical Address of Element A[5][1] in
Column Major scheme =
Base Address + w * [(i -0) +Nr * (j-0)]
Here, i=5 and j=1; BA=800
Actual
Physical Address of Element A[5][1] in
Column Major scheme =800+4[5+8*1]
=800+4*13
=852 (Answer)
3(c)
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).
-----------------------------ANSWER 3 ( c )
-----------------------------------------------------------
#include<iostream.h>
#include<conio.h>
struct PLAYER
{
long PID; //Player ID
char Pname[20]; //Player Name
} p[3];
int rear=-1, front=-1;
void insert( PLAYER p1, int size)
{
if((front==0 &&
rear==size-1)||front==rear+1)
{
cout<<"\n over flow" ;
return;
}
else if(front==-1)
front=rear=0
;
else if(rear==size-1)
rear=0;
else
rear++;
p[rear]=p1;
cout<<"\n player successfully
added";
}
Note: Here , main program is
given only four output testing purpose.
Please don’t write main program in examination..write only the definition of
function asked.
4.(a) A
binary file “Students.dat” contains data of 10 students where each student’s
data is an object of the following class:
class
Student
{
int
Rno;char Name[20];
public:
void
EnterData() {cin>>Rno; cin.getline(Name,20);
void
ShowData() {cout<<Rno<<” - ”<<Name<<endl;}
};
With
reference to this information, write output of the following program segment:
ifstream
File; Student S;
File.open(“STUDENTS.DAT”,ios::binary|ios::in);
File.seekg(0,
ios::end); // it sets the Read File
pointer at the end of file—last char in file
Cout<<File.tellg();
//it displays how far is the READ FILE
POINTER from the beginning of file (in terms of
bytes)
----------------------------------- ANSWER -4
(a)-----------------------------------------------------------
Cout<<File.tellg(); //it displays how far is the READ FILE POINTER from the
beginning of file (in bytes)—here in the
Current situation it displays total no. of
bytes/char present in the file.
Total no. of records (i.e. objects of class student
) present in the “STUDENTS.DAT” = 10
Size of each record= sizeof(student object)= sum of
size of each data member=sizeof(int)+sizeof(Name)=4+20=24
NOTE : SIZE OF “INT” is
different in different compilers. For BORLAND C++ it is “4 Bytes”
Size of file=position of last char in file= No of
Records stored in file * Size of each Record
=10 * 24 =240 Bytes (In BC++)--- Answer = 240
4(b) Write a function in C++ to count the number of lines starting with
a digit in a text file “DIARY.TXT”.
----------------------------------- ANSWER -4
(B)-----------------------------------------------------------
void countLines()
{
ifstream f;
f.open("DIARY.TXT");
int count=0;
char line[200];
while(f)
{
f.getline(line,100);
if (isdigit(line[0])) count++;
}
cout<<"\n No of lines starting with digit = "<<count;
f.close();
}
4 (c) Given a binary file
“STUDENT.DAT”, containing records of the following class Student type:
class student
{ char S_admno[10]; //Admission no. of student
char S_Name[20]; //Name of student
int Percentage; //Marks percentage of student
public:
void EnterData()
{ gets(S_admno); gets(S_Name); cin>>Percentage;
}
void DisplayData()
{ cout<<setw(12)<<S_admno;
cout<<setw(32)<<S_Name;
cout<<setw(3)<<Percentage<<endl;
}
int Ret_Per() {return Percentage;}
};
Write a
function in C++ that would read contents of the file “STUDENT.DAT” and display
the details of those students whose percentage is above 75.
…………………………………………. ANSWER 4 ( c ) ……………………………………………………………………….
void DisplayFile()
{
ifstream f;
f.open("STUDENT.DAT ",ios::binary);
while(1) {
f.read((char*)&p,sizeof(p));
if(f.eof()==1) break;
else
if(p.Ret_Per()>75) p.DisplayData();
}
f.close();
}
5. (a)-(i)- (ANSWER) NO, “MNo” column cannot be made as Primary Key
because valus in this column are not UNIQUE, value 102 is repeated more than
one time. It is violating the Primary Key constraints so cannot act as Primary
Key.
(Same member can purchase many different type of products, hence
respective MNO can be repeated.)
5. (a)-(ii)- (ANSWER) Degree=No. of columns= 4 , Cardinality=No. of rows = 5
5.(b)-(i)-SELECT TITLE FROM
SUBJECT WHERE MARKS_PRAC=0;
(II) SELECT COUNT(TCODE),SUB_CODE FROM TEACHER GROUP BY SUB_CODE;
(III) SELECT NAME FROM TEACHER
ORDER BY SUB_CODE;
(IV) SELECT CODE , TITLE,
(MARKS_THEORY+MARKS_PRAC) AS “ TOTAL MARKS”
FROM SUBJECT ;
5.(C) SELECT SUBJECT.TITLE , TEACHER.NAME FROM SUBJECT , TEACHER where SUBJECT.CODE=TEACHER.SUB_CODE ;
5.(d)-(i) output :
100
70
(ii)output :
4 Shabnam
5 Rashika
6 Vidushi
7 Yash
5.(e) In subject table “ code”
can be made PRIMARY KEY. In TEACHER
table “TCode” can be made PRIMARY KEY
7.(a) RADIO WAVE
7.(b) SMTP
protocol is used to receive emails.
7.(c)COOKIE S -Information sent by webserver to the
web browser.
7.(d) client-side
script
7.(e) Free Software: The S/W’s is
freely accessible and can be freely used changed improved copied and
distributed by all and payments are needed to make for free S/W.
Freeware: Freeware are the software
freely available , which permit redistribution but not modification (and their
source code is not available). Freeware is distributed in Binary Form (ready to run) without
any licensing fees.
****************************THE
END************************
Note- Crossed line which are
marked green are not part of the solution, only yellow colored lines are the
actual solution to be written in exam.
I have tried my best to avoid any
mistakes while preparing the solution, but still there might be few chances
that errors might exist... so, please feel free to post your comments /
suggestions or mail me at hsyadav.kvs@gmail.com
. Your suggestions will be most welcomed and appreciated.
[[ Plan your 10 Days
interval before CS exam to cover all topics as per syllabus and blueprint in
CS..Since pattern of asking questions get changed ..so be ready and do extra
hard work and study whole syllabus properly and deeply ]]
Soon some more "IMPORTANT
STUDY MATTER" will be posted soon... follow me.....
*****************************************************