You are on page 1of 3

KENDRIYA VIDYALAYA, BELLARY

XII COMPUTER SCIENCE MONTHLY TEST FOR JULY


Max. Marks 25
1. What s a copy constructor? What s ts sgnfcance? Whch stuatons s t
nvoked n? Support your answer wth exampes.
(3)
2. Defne a cass Pay n C++ wth the foowng specfcatons:
(3)
Prvate members of cass Pay:
- Paycode nteger
- PayTte 25 characters
- Duraton foat
- Noofscenes nteger
Pubc Member functon of cass Pay
- A constructor functon to ntaze Duraton as 45 and Noofscenes as 5
- Newpay() functon to accept vaues for Paycode and PayTte
- Morenfo() functon to assgn the vaues of correspondng vaues passed as
parameters to ths functon
- Shopay() functon to dspay a the data members on the screen.

3. What w be the output of the foowng code:
(4)
#ncude <ostream.h>
cass A{
nt m;
pubc:
A()
{m= 30;cout << "10\n";}
A(nt x)
{m=x;cout<<"20\n";}
-A()
{cout<<m<<"\n";}
};
cass B{
nt n;
pubc:
B()
{n = 40;cout<<"50\n";}
B(nt x)
{n=x; cout<<"60\n";}
-B()
{cout<<n<<"\n";}
};
Cass C{ A ob1, ob2;
B ob3;
pubc:
C():ob1(70), ob3(80)
{cout<<"80\n";}
-C()
{cout<<"90\n";)
};
vod man()
{ C oc; B ob; A oa(40); }
4. Identfy the errors gvng |ustfcaton:
(4)
#ncude <ostream.h>
cass Reta()
{
char Category|20|;
char Item;
nt Oty;
foat Prce;
Reta()
{
strcpy(Category, "Cerea");
strcpy(Item,"Rce");
Oty=100;
Prce=25;
}
vod show()
{cout<< Category<<"-"<<Item<<":"<< Oty<<"@"<<Prce<<end;}
}
vod man()
{
Reta R;
R.show();
}
5. What s the beneft of decarng a data member as protected?
(2)
6. Can prvate members of a cass be accessed by derved cass? If yes , how or
f not
then why not? Expan wth exampes
(3)
7. Consder the foowng and answer the questons gven beow:
(4)
cass MNC
{
char Cname|25|; //Company name
protected:
char Hoffce|25|; //Head Offce
pubc:
MNC();
char Country|25|;
vod EnterDate();
vod DspayData();
};
cass Branch : pubc MNC
{
ong NOE; //Number of Empoyees
char Ctry|25|; //Country
protected:
vod Assocaton();
pubc:
Branch();
vod Add();
vod Show();
};
cass Outet : pubc Branch
{
char State|25|;
pubc:
Outet();
vod Enter();
vod Output();
};
() Whch casss constructor w be caed frst at the tme of decaraton of
an ob|ect of cass Outet?
() How many bytes an ob|ect beongng to cass Outet requre?
() Name the member functon(s) whch are accessed from the ob|ect(s) of
cass Outet?
(v) Name the data members whch are accessbe from an ob|ect of cass
Branch?
8. What ponts shoud you consder when creatng a derved cass when the base
cass has expct constructor defned? Expan wth exampes.
(2)

You might also like