You are on page 1of 8

KENDRIYA VIDYALAYA FORTWILLIAM

CLASS XII SMAPLE PAPER 2018


Computer Science
Max. Marks: 70 Duration: 3 Hours
General Instructions – (i) All questions are compulsory.
(ii) Programming Language : C++.
Q1. (a) Write the two forms of type conversion facilitated by C++. Also give suitable [2]
example of each form of type conversion.
(b) Write the related library function name based upon the given information in [3]
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.
(iii) Returns the largest whole number that is not greater than the passed
parameter value.Defined inside math.h header file.
(c) Underlining the syntactical errors (if any) with proper explanation. [2]
#include<iostream.h>
void main()
{ int n = 44;
int *ptr = &n;
++(*ptr);
int *const cptr = &n;
++(*cptr);
++cptr;
const int kn=88;
const int *ptrc = &kn;
++(*ptrc);
++ptrc;
const int *const cptrc =&kn;
++(*cptrc);
++cptrc;
}

(d) Find the output of the following program: [3]


#include<iostream.h>
struct Solid
{ int length, breadth, height;
};
void Dimension(Solid S)
{ cout<<S.length<<"  "<<S.breadth<<"  "<<S.height<<endl;
}
void main()
{
Solid S1={10,20,30},S2,S3;
++S1.height;
Dimension(S1);
S3=S1;
++S3.length;
S3.breadth++;
Dimension(S3);
S2=S3;
S2.height =+ 5;
S2.length = S2.length – 5;
S2.breadth += 5;

Page1 / 8
Dimension(S2);
}
(e) Find the output of the following program: [2]
#include<iostream.h>
static int sum2=0;
void sumfn(int last)
{
auto int sum1=0;
for(inti=last;i>0;i--) sum1+=i;
sum2 +=sum1;
cout<<sum1<<" & "<<sum2<<endl;
}
void main()
{
sum2=10;
for(inti=5; i<7 ; i++) sumfn(i);
}
(f) In the following program, what will be the expected output(s) from the given [2]
options?
#include <iostream.h>
#include <stdlib.h>
void main()
{
int N;
randomize();
for (int I=1;I<=4;I++)
{
if(I%2==0)
N=1+random(I);
else
N=5+random(I);
cout<<N;
}
}
(i) 5354 (ii) 5254
(iii) 5173 (iv) 6264
Q2. (a) What do you understand by copy constructor? Give an example illustrating the [2]
same using C++ coding.
(b) Answer the questions (i) and (ii) after going through the following program: [4]
class mytime
{
int hour, minute, second;
public:
mytime() {} //Function 1
void Details() //Function 2
{
cout<<”The time is “<<hour<<”:“<<minute<<”:”<<second<<endl;
}
mytime(int x, int y, int z) //Function 3
mytime(mytime&mt) //Function 4
};
i) Write the complete function definition for Function 3 .
ii) Write the complete function definition for function 3.

Page2 / 8
iii) Write statements that would call the Member Functions 1 and 3.
iv) Write function definition for destructor of above class and when will it
be invoked?
(c) Define a class IncomeTax in C++ with the following descriptions. [4]
Private members:
EmpName of type character array
Empcode of type long
Grosssalaryof type long
Nettax of type long
Calculate( ) This member function should calculate the value
of Nettax according to the following conditions.
Grosssalary Tax to be paid
Up to 1 Lakh No Tax
>1 Lakh and <=3 Lakhs 10% of (Grosssalary – 1 Lakh)
> 3 Lakhs and <=5 Lakhs 20,000 + 20% of (Grosssalary –
3 Lakhs)
Above 5 Lakhs 60,000 + 30% of (Grosssalary –
5 Lakhs)

Public members:
* A constructor to assign initial values of EmpName as “Ajay”, Empcode
as 53043, Grosssalary as 250000, Nettax as 15000.
* A function Accept() which allows user to enter EmpName, Empcode,
Grosssalary and should call function Calculate().
* 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: [6]
class HQ
{
long HQmaxvalue;
protected :
long HQfundvalue;
public:
intno_of_HQmeritcert;
HQ( );
void HQREAD( );
void HQWRITE( );
};

class RO: private HQ


{
int ROcode;
long ROmaxvalue;
protected:
long ROfundvalue;
public:
intno_of_ROmeritcert;
RO( );
void HQUPDATE( );
void ROREAD( );
void ROWRITE( );
};

Page3 / 8
class KV: public RO
{
int KVcode, no_of_achivements;
char KVname[30];
public:
long cashprize;
KV( );
void ROUPDATE( );
void KVREAD( );
void KVWRITE( );
};

i) Write the type of inheritance illustrated in the above program code.


ii) Write name of base class and child class from the above code.
iii) Mention the member names that are accessible by an object of RO
class.
iv) Name the members which can be accessed by the objects of KV class.
v) Name the data members that can be accessed by the ROUPDATE() of
KV class.
vi) How many bytes will be occupied by an object of class KV?
(e) HQFundValue is accessible inside member function belonging to Class RO but [2]
not accessible inside member function of KV .Why?
Q3. (a) Assume that two arrays A and B contain objects of structure Teacher in the [3]
ascending order of salary. Write a function MERGE in C++ to merge the
contents of arrays A & B into third array C. The resultant array should contain
the objects of both arrays A & B. Array C should be sorted in ascending order
of salary of the corresponding objects.
The arrays A, B, C, No. of objects of A and B should be passed as the
arguments to the function. Definition of structure Teacher is as under:
struct Teacher
{
int ID;
char Name[30];
float Salary;
};
(b) An array P[20][30] is stored in the memory along the column with Base [3]
Address 3392. Find out the memory location for the element P[2][20], if an
element P[5][15] is stored at the memory location 4612.
Q4. (a) Observe the program segment given below carefully, and answer the question [1]
that follows :
class vidyalaya
{
char name[25];
intnumstu;
public:
void inschool( );
void outschool( );
intretnumstu( )
{ return numstu; }
};
void modify(vidyalaya A)
{
fstream INOUT;
INOUT.open(“school.dat”,ios::binary|ios::in|ios::out|ios::ate);

Page4 / 8
vidyalaya B;
intrecread=0, found=0;
while(!found &&INOUT.read((char*)&B,sizeof(B))
{
recread++;
if(A.retnumstu( )= = B.retnumstu( ))
{
__________________//missing statement 1

__________________//missing statement 2
Found=1;
}
else
INOUT.write((char*)&B,sizeof(B));
}
if(!found)
cout<<”\nRecord for modification does not exist”;
INOUT.close( );
}
If the function modify( ) is supposed to modify a record in file school.dat with
the values of vidyalaya A passed to its argument, write the appropriate
statement for missing statements 1 & 2 so that the function would write the
modified record at its proper place.
(b) Write a function in C++ to count the number of words starting with a capital [2]
later, in a text file “NOTES.TXT”.
(c) Given the binary file BOOK.DAT, containing the records of the following [3]
structure:
class book
{
intbook_no;
char book_name[20];
int stock;
public:
intbookreturn()
{
return book_no;
}
void DeleteStock(int);
};
Write the complete definition of the function DelStock(), which delete the
records that match with the book_no passed as the argument to the
function.
5 (a) Find out errors in the following program:- 2
class number
{
int x=10;
float y;
number(){ x=y=10;}
public:
number(number t)
{
x=t.x; y=t.y;
}
. ~number (){ cout<<"Object destroyed ";}
}

Page5 / 8
main()
{
number a1, a2(a1);
}
(b) Write C++ Statement to put file read pointer at the end of 7th record form the end 1
(c) Write statement to display no. of bytes of a file upto 10 th record of the file from beginning. 1
(d) What is the output of the following program? 2
#include <iostream.h>
class Sand
{
public: Sand()
{
cout << "Sand ";
}
~Sand()
{
cout << "~Sand ";
}
};
class Rock
{
public: Rock()
{
cout << "Rock ";
}
~Rock()
{
cout << "~Rock ";
}
};
class Hill: public Sand
{
Rock data_;
public: Hill()
{
cout << "Hill " << endl;
}
~Hill()
{
cout << "~Hill ";
}
};

int main()
{
Hill h;
return 0;
}
( e) #include<iostream.h> 2
class Base1 {
public:
Base1()
{ cout << " Base1's constructor called" << endl; }
};

class Base2 {
public:
Base2()
{ cout << "Base2's constructor called" << endl; }
};

class Derived: public Base1, public Base2 {

Page6 / 8
public:
Derived()
{ cout << "Derived's constructor called" << endl; }
};

int main()
{
Derived d;
return 0;
}

(f) What will be the changes made to the content of the file after running the code? 2
#include <iostream>
#include <fstream>

int main ()
{
//create a text file named file before running.
ofstream ofile;
ofile.open ("file.txt");

ofile<< "File Handling Class XII";


ofile.seekp (8);
ofile<< " Computer Science";

ofile.close();

return 0;
}
(g) Write a function to write records of Class “Patients” at the end of the binary file 2
“Patients.dat”. takeInput() is a public member function of Patients class which
is used to get values of data members of the Class from user.
6 (a) Write C++ statement to explain concept of virtual Class. 3
(b) Write a small program code to explain the difference between multiple and 3
multilevel inheritance.
(c) Why should a constructor be declared inside public section of the class 2
(d) Write the purpose of following functions and syntax for invoking them; 3
(i) get()
(ii) getline()
(iii) eof()
(e) Write a function to replace each ‘s’ present in a text file with # and display the 3
final content of the text file.
Name of text file is “ REPLACE.TXT”
(f) What is wrong with t he below given code: 2
#include<fstream.h>
class Book{
int bookno;
char bname[80];
public:
void values(){ cin>>bookno;gets(bname);}
void show(){cout<<bookno<<bname}
};
void main()
{
ifstream ifile(“Book.dat”,ios::binary);
Book ob;

Page7 / 8
Ob.values();
ifile.write((char*)&ob,sizeof(ob));
close(ifile);
}
Correct the code so that program can be executed successfully.

Page8 / 8

You might also like