Click here to load reader
View
2
Download
0
Embed Size (px)
KENDRIYA VIDYALAYA SANGATHAN
IMPORTANT QUESTIONS
SUB: COMPUTER SCIENCE(083)
CLASS XII
Review of C++ covered in Class XI
Q1. What is difference between implicit and explicit type casting? Justify your answer with example.
Ans : Implicit is automatic type conversion of one data type into another i.e compiler does itself from lower
range to higher range.
e.g. int x, char c=’A’;
x=c;
cout
Q5. What is the difference between Global Variable and Local Variable?
Ans:
Global Variable Local Variable
It is a variable, which is declared outside all the functions
It is accessible throughout the program.
It is a variable, which is declared with in a function or with in a compound statement
It is accessible only within a function/ compound statement in which it is declared.
#include
float NUM=900; //NUM is a global variable
void LOCAL(int T)
{
int Total=0; //Total is a local variable
for (int I=0;I
Q8. Differentiate between a Call by Value and Call by Reference, giving suitable examples of each?
Ans:
Call by Value Call by Reference
In this method separate memory created for formal parameters, so any
change on formal parameters will the
affect actual parameters. Hence actual
parameters are preserved in this case.
In this method no separate memory created for formal parameters, hence formal
parameter share the same memory location of
actual parameters. Therefore any change on
formal parameters will automatically
reflected back to actual paramters.
void change(int b)
{
b = 10;
}
void main()
{
int a = 5;
cout
stdio.h
Q2. Name the header file(s) that shall be needed for successful compilation of the following C++ code:
void main( )
{
char inp, outp;
inp = getchar();
outp = toupper(inp)
cout
Ans: #include
void main()
{
int X[ ]={60,50,30,40},Y, count=4; // multiple declaration separated by comma
cin>>Y;
for(int i=count-1; i>=0; i--) // i should be declared
switch(i)
{
case 1:; // case should follow by :
case 2: coutq>>r;
}
Ans: #include
int func(int y , int &x) // violating the rule of Default argument
{
if(x%y = = 0) return ++x ; else return y-- ; // = = relational operator
}
void main()
{
int p = 20, q = 23;
int r = func(p,q); // r should be declared
cout
}
Ans: #include
struct Pixels
{ int Color,Style;} ; // Definition of structure Pixels must be ended with ;
void ShowPoint(Pixels P)
{ cout
}
}; // class definition must terminate with ;
void main()
{
sum s(20, 10);
s.display(); // member function must be invoked using . operator
}
Questions based on Finding Outputs (CBSE Q.1(d) for 2 marks) Q1. Find the output of the following program:
#include
void main()
{
long NUM = 98534210;
int f=0,s=0;
do
{
int rem = NUM % 10;
if( rem % 2 == 0)
f += rem;
else
s += rem;
NUM /= 10;
}while(NUM > 0);
cout
Q3. Find the output of the following program:
#include
#include
void main()
{
char *name= "ThE bESt meN wIN";
for ( int i =0; name[i]!='\0' ; i++)
{
if ( islower( name[i]) )
name[i] = toupper(name[i]) ;
else
if( isupper(name[i]) )
if ( i%2 == 0)
name[i] – – ;
else
name[i] = tolower(name[i–1]);
}
cout
for (int C = 0; C
i = 0;
while(s[i] != '\0')
{
if(s[i] > 'A' && s[i] < 'P')
s[i] = tolower(s[i]);
else if(s[i] > 'a' && s[i] < 'p')
{
if(i % 3 == 0)
s[i] = tolower(s[i-1]);
else
s[i] = tolower(s[i]);
}
i++;
}
}
void main()
{
char str[] = "MiCroSoFT";
yourstr(str,3); cout
Q3. Find the output of the following program:
#include
int modify(int temp = 2)
{
if(temp % 3 == 0)
temp = temp + 1;
else
temp = temp + 3;
return temp;
}
void UpdateMe(int m, int &n)
{
static int i;
i++;
m = n + i;
if(n > 10)
n = modify();
else
n = modify(n);
cout
(***d)+= 10;
cout
void main( )
{
randomize();
int Number;
Number=50 + random(Max);
for(int P=Number; P >=50; P - -)
cout
OBJECT ORIENTED PROGRAMMING CONCEPTS
CBSE QUESTIONS BASED ON DESIGN OF CLASS (4 MARKS)
Question 1.
Define a class candidate in C++ with following Description:
Private Members
A data member RNo (Registration Number) of type long
A data member Name of type string
A data member Score of type float
A data member Remark of type string
A member function AssignRem( ) to assign Remarks as per the Score obtained by a candidate.
Score range and the respective Remarks are shown as follows:
Score Remarks >=50 Selected less than 50 Not selected
Public members
A function ENTER( ) to allow user to enter values for RNo, Name, Score & call function AssignRem() to assign
the remarks.
A function DISPLAY( ) to allow user to view the content of all the data members.
Solution:
class Candidate
{ long RNo;
char Name[20];
float Score;
char Remarks[20];
void AssignRem( ) ;
public:
void Enter( );
void Display( );
} ;
void Candidate: :AssignRem( )
{ if (Score>=50)
strcpy (Remarks,"Selected") ;
else strcpy(Remarks,"Not Selected") ;
}
void Candidate: : Enter ( )
{
cin>>RNo ;
gets (Name) ;
cin>>Score;
AssignRem( ) ;
}
void Candidate: :Display()
{
cout
cin >> Price >> Qty;
GetOffer();
}
void ITEM::ShowItem()
{
cout
iv) Copy constructor. Exam::Exam(Exam &T)
{
Marks = T.Marks;
strcpy(Subject,T.subject);
}
INHERITANCE 1. Answer the questions (i) to (iv) based on the following:
class PUBLISHER
{ char Pub[12];
double Turnover;
protected:
void Register();
public:
PUBLISHER();
Void Enter();
void Display();
};
class BRANCH
{
char CITY[20];
protected: float Employees;
public: BRANCH();
void Haveit();
void Giveit();
};
class AUTHOR :private BRANCH, public PUBLISHER
{
int Acode;
char Aname[20];
float Amount;
public:
AUTHOR();
void Start();
void Show();
};
i) Write the names of data members, which are accessible from objects belonging to class AUTHOR. ii) Write the names of all the member functions which are accessible from objects belonging to class
AUTHOR.
iii) Write the names of all the members which are accessible from member functions of class AUTHOR. iv) How many bytes will be required by an object belonging to class AUTHOR?
Ans :
i) None of the data member is accessible from object of class AUTHOR
ii) Enter(), Display(), Start(), Show()
iii) member functions : Register(), Enter(), Display(),Haveit(), Giveit(),Start(), Show() data members :
Amount, Acode, Aname[20], Employees,
iv) 70
2 . Answer the questions (i) to (iv) based on the following code :
class Drug
{ char Category[10];
char Date_of_manufacture[10];
char Company[20];
public:
Drug();
void enterdrugdetails();
void showdrugdetails();
};
class Tablet : public Drug
{ protected:
char tablet_name[30];
char Volume_label[20];
public:
float Price;
Tablet();
void entertabletdetails();
void showtabletdetails ();
};
class PainReliever : public Tablet
{ int Dosage_units;
char Side_effects[20];