Professional Documents
Culture Documents
Xiics Sample Paper
Xiics Sample Paper
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( );
};
Page3 / 8
class KV: public RO
{
int KVcode, no_of_achivements;
char KVname[30];
public:
long cashprize;
KV( );
void ROUPDATE( );
void KVREAD( );
void KVWRITE( );
};
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; }
};
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.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