Sei sulla pagina 1di 4

Kendriya Vidyalaya Fortwilliam

Monthly Test –April


Class XII CS 2018-19
MM: 50 Time 1 ½ Hr.
Q1.Find O/P :3

#include<iostream.h> #class Outer


void main()
#include<string.h> {
{ Outer obj;
class Inner int a;
Obj.Outer_Init(10,"Inner Class");
{ int a; char desc[20];
obj.outer_function();
public: public:
}
Inner_Init(int c) Outer_Init(int x, char y[])
{ a=c;} { a=x; strcpy(desc,y);}
intgetA(){ return a;} voidouter_function()
void show() { Innerobj ; obj.Inner_Init(120);
{ cout<<"\n Inner::"<<a;} if(obj.getA()>a)
}; obj.show();
else
cout<<"\nOuter::"<<a<<"##"<<desc; }};

Q2.Find Error : - 3

#include<iostream.h>
#include<stdio.h>
class Hardware
{int slno=10;
char desc[30];
public:
void enterValues()
{ cin>>slno; cin.gets(desc);}
void outData()
{ cout<<slno;puts(desc);}
};
void main()
{ Hardware H1;
enterValues();
cout<<slno<<desc;
}

Q3. Identify header files required to run the following C++ code: 1
void main()
{ int r=65+random(5);
for(inti=1;i<5;i++)
cout<<”\n Set Width:”<<setw(10)<<r;
}
Q4.Write the output of the following C++ program code : 3
Note : Assume all required header files are already being included in the program

Class Eval
{ char Level; int Point;
public: Eval(){Level=’E’;Point=0;}
void Sink(int L)
{ Level-=L; }
void Float(int L)
{ Level+=L; Point++; }
void Show()
{ cout<<Level<<”#”<<Point<<endl; }
};
void main()
{ Eval E; E.Sink(3);
E.Show(); E.Float(7); E.Show();
E.Sink(2); E.Show();
}
Q5. Define a class named ADMISSION in C++ with the following descriptions: 4
Private members: AD_NO integer (Ranges 10 - 2000) ,NAME Array of characters (String) ,
CLASS Character ,FEES Float
Public Members:
• Function Read_Data ( ) to read an object of ADMISSION type
• Function Display() to display the details of an object
• Function Draw-Nos ( ) to choose 2 students randomly. And display the details. Use random
function to generate admission nos. to match with AD_NO.
Q6. Find O/p:(Assume all necessary header files are included in the program): 3
#define Diff(N1,N2) ((N1>N2)?N1-N2:N2-N1)
void main()
{ int A , B , num[]={10,23,14,54,32};
for( int cnt=4; cnt>0; cnt --)
{ A=num[cnt];
num[cnt]=num[cnt-1];
cout<<Diff(A,B)<<”#”;
} }
Q7. Explain static data members of a class with help of suitable C++ code. 3
Q8. Explain typedef with suitable ++ code. 2
Q9. Rewrite the following C++ code after removing any/all syntactical errors with each correction
underlined.Note: Assume all required header files are already being included in the program. 2
void main()
{
cout<<"Enter an Alphabet:";
cin>>CH;
switch(CH)
case ‘A’ cout<<"Ant"; Break;
case ‘B’ cout<<"Bear" ; Break;
}
Q10. Look at the following C++ code and find the possible output(s) from the options (i) to (iv)
following it. Also, write the maximum values that can be assigned to each of the variables N and M.2
#include<stdlib.h>
#include<iostream.h>
void main()
{
randomize();
int N=random(3),M=random(4);
int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
for(int R=0; R<N; R++)
{
for(int C=0; C
<M; C++)
cout<<DOCK[R][C]<<" ";
cout<<endl;
}
}

Q11. Write C++ program code to explain all three types of member functions of a class. 3
Q12. Write C++ Program to explain the difference between private and public members of a class. 3
Q13. Write difference between the two classes declared below- 2
# include<iostream.h>
class x //Class 1
{
members variable functions of class;
};
int main ( )
{
class num // Class 2
{
public:
int a;
};
Member functions of class 2
}
14. Write the concept explained in the below given C++ Code: 3
class score
{
int a;
public: class batsman {
int b;
public:
int c;
void total( )
{ cin>>b>>c; int sum = b+c; }
}; // end of class batesman
batsman obj2; // object of class batesman
void second( void)
{ cout<<score :: second()<<endl; cout<<”A =” <<a
}
}; //end of class score;
(i) Write C++ statement to create object of Class batman in main
(ii) Write C++ statement to invoke total() function of batman class.
(iii) Write C++ statement to invoke function total().
15.What do you mean by nesting of member functions.Explain with the help of suitable C++
code. 3

Potrebbero piacerti anche