CBSE Guess > Papers > Important Questions > Class XII > 2012 > Computer Science > Computer Science Mr. Pradumna Singh
Computer Science- CBSE CLASS XII
Q. 9. ) Define a class TAXPAYER in C++ with following description : For - 4 Marks
Private members :
- Name of type string
- PanNo of type string
- Taxabincm (Taxable income) of type float
- TotTax of type double
- A function CompTax( ) to calculate tax according to the following slab:
Taxable Income Tax%
Up to 160000 0
>160000 and <=300000 5
>300000 and <=500000 10
>500000 15
Public members :
- A parameterized constructor to initialize all the members
- A function INTAX( ) to enter data for the tax payer and call function CompTax( ) to assign TotTax.
- A function OUTAX( ) to allow user to view the content of all the data members.
Ans.
class TAXPAYER
{private:
char Name[30],PanNo[30];
float Taxabincm;
double TotTax;
void CompTax()
{ if(Taxabincm >500000)
TotTax= Taxabincm*0.15;
else if(Taxabincm>300000)
TotTax= Taxabincm*0.1;
Else if(Taxabincm>160000)
TotTax= Taxabincm*0.05;
else
TotTax=0.0; }
public:
TAXPAYER(char nm[], char pan[], float tax, double ttax) //parameterized constructor
{ strcpy(Name,nm);
strcpy(PanNo,pan);
Taxabincm=tax;
TotTax=ttax; }
void INTAX()
{ gets(Name);
cin>>PanNo>>Taxabincm;
CompTax(); }
void OUTAX()
{ cout<<Name<<’\n’<<PanNo<<’\n’<<Taxabincm<<’\n’<<TotTax<<endl; } };
Q. 10 .Answer the questions (1) to (4) based on the following : For - 4 Marks
class Student
{ private :
char Rollno[20], Sname[30];
protected :
auto float marks;
public:
Student( );
void ENROL( );
void SHOW( );
};
class Graduate: public Student
{ char Fname[30];
protected:
unsigned int age;
public:
Graduate( );
void GENROL( );
void GSHOW( );
};
class Pgraduate: private Graduate
{
char Mname[25];
signed int year;
public:
Pgraduate( );
void PGENROL( );
void PGSHOW( );
};
- Mention the member names that are accessible by an object of Pgraduate class.
Ans. PGENROL( ), PGSHOW( )
- Name the data members which can be accessed by the objects of Graduate class.
Ans. None
- Name the data members that can be accessed by the functions of Pgraduate class.
Ans. Mname[25], year, age & marks
- How many bytes will be occupied by an object of class Pgraduate?
Ans. 113 bytes
Q . 11. Write a function TRANSFERP( int ALL[ ], int N) , to transfer all the prime numbers from a one dimensional array ALL[ ] to another one dimensional array PRIME[ ]. The resultant array PRIME[ ] must be displayed on screen. For - 3 Marks
Ans.:
TRANSFERP( int ALL[ ], int N)
{ int PRIME[100],i,j,tp=0,count;
for(i=0;i<N;i++)
{
count=0;
for(j=0;j<=ALL[i];j++)
if(ALL[i]%j= =0)
count++;
if(count= = 2)
{
PRIME[tp]=ALL[i];
tp++;
}
} //end of for
//displaying all prime numbers of array PRIME[]
cout<<”\nAll prime numbers in resultant array are:\n”;
for(i=0;i<tp;i++)
cout<<PRIME[i]<<’ ‘; }
Q. 12 . b) An array PP[40]32] is stored in the memory along the row with each of the elements occupying 10 bytes. Find out the memory location for the element PP[18][22], if the element PP[7][10] is stored at memory location 5000. For - 3 Marks
Sol.
Given : B=?, W=10, m=40, n=32, I=7, J=10, PP[I][J]=5000, LBr=0, LBc=0
Row Major:
Address of PP[7][10]=B+W(n(I-LBr)+(J-LBc))
5000=B+10(32(7-0)+(10-0))
5000=B+10(224+10)
5000=B+10*234
5000=B+2340
Therefore B=5000-2340 = 2660
Now Address of PP[18][22] = 2660+10(32(18-0)+(22-0))
=2660+10(576+22)
=2660+10*598
=2660+5980 = 8640
Ans. Base address = 2660 & address of PP[18][22] is 8640
Prepared By: Mr. Pradumna Singh
mail to: [email protected] |