holiday homework(computer science class-xii)

Kendriya Vidyalaya BSFAnupgarh
HOMEWORK 2017-18
Class: XII
SUBJECT – COMPUTER SCIENCE
General Instructions:
(i) All questions are compulsory.
Q1.(a). What is difference between Local and Global varibles? Give an example in
C++ to illustrate both type of parameters.
(b). Out of the following, find those identifiers, which cannot be used for
Naming variables, constants or functions in a c++ program:Total*tax, double,
case, My name, new, switch, column31, _amount
(b). Which C++ header file(s) will be essentially required to be included to run /
execute the following C++ code?
[1]
void main()
{
int rno=24; char name[]=”Anil Singhal”;
cout<<setw(10) <<rno<<setp(2) << name<<endl;
exit(0);
}
(c) Rewrite the following C++ program code after removing syntax error(s) if any.
Underline each correction.
[2]
include<iostream.h>
class FLIGHT
{ long Fcode=5; char Description[25];
~ int FLIGHT() { Fcode=0;}
public
void getinfo();
{cin>>Fcode; gets(Description); }
void show()
{ cout<<Fcode<<” “ <<Description<<endl; } };
void main()
{
FLIGHT F;
getinfo.F(); F.show(); }
(d) Find the output of the following program :
#include<iostream.h>
void Withdef(int HisNum=29)
{
for(int I=12;I<=HisNum;I+=7)
cout<<I<<”,”;
[3]
cout<<endl;
}
void Control(int &MyNum)
{
MyNum+=8;
Withdef(MyNum);
}
void main( )
{
int YourNum=16;
Control(YourNum);
Withdef( );
cout<<”Number=”<<YourNum<<endl;
}
(e) Find the output of the following program:
#include<iostream.h>
class metro
{
int mno,tripno,pc;
pubblic:
metro(int tmno=1)
{ mno=tmno; tripno=0;pc=0}
void trip(int pa=20)
{ tripno++; pc+=pa;}
void show()
{ cout<<mno<<":"<<tripno<<":"<<pc<<endl;}
};
void main()
{ metro m(5),t;
[4]
m.trip();
t.trip(50);
m.show();
m.trip(30);
t.show();
m.show();
}
(e)
Give the output of the following program:
[3]
#include<iostream.h>
void ReCode ( char Text[ ], int Num );
void main ( )
{
char Note [ ] = “Butterfly”;
Recode (Note, 2);
cout << Note <<endl;
}
void ReCode (char Text [ ], int Num)
{
for ( int K = 0 ; Text [K] !=’\0’ ; K++)
if ( K % 2 == 0)
Text [K] = Text [K] ‒ Num;
else if ( islower (Text[K] ))
Text [K] = toupper ( Text [K] )
else
Text[K] = Text[K] + Num;
}
f)
Study the following program and select the correct option(s) out of the
four choices given below as the possible set of such numbers
generated from the program code. Justify your answer and write the
Minimum and Maximum Value of Num.
[3]
#include<iostream.h>
#include<stdlib.h>
const int MIN = 25 ;
void main( )
{
randomize ( );
int SCORE = 5 , Num;
for (int i = 1 ; i <= 4 ; i ++ )
{
Num = MIN + random (SCORE );
cout << Num << “:”;
SCORE ‒ ‒;
}
}
(i)
(ii)
(iii)
(iv)
29:28:30:25:
29:27:28:26:
29:26:27:26:
28:29:29:27:
Q.2(a) Answer the question (i) and (iv) after going through the following class:
[4]
class Seminar
{ int Time,Date;
public:
Seminar()
//fun1
{ Time=30; cout<<"Seminar Starts now"<<endl;
}
void Lecture()
// fun2
{ cout<<"Lectures in the Seminar on"<<endl;
}
Seminar(int Duration)
{ Time=Duration;
//fun3
cout<<"Seminar end now"<<endl;
}
Seminar(Seminar & P )
{ Date=P;
//fun4
cout<<"Seminar data copy
now"<<endl;
}
~ Seminar()
//fun5
{ cout<<"Thanks"<<endl;
}
};
(i) In object oriented programming,what is function 5 referred as and when does it
get invokedor called?
(ii) In object oriented programming,when it will illustrate the polymorphism
concept? Write a statement to calls these fun1 and fun3.
(iii) Write down order of constructor invoked and justify your answer.
(iv) Identify from above code which function show copy constructor, default,
parameterized constructor concept and Write down the use of fun 4.
(b)
Define a class Taxpayer, whose class description is given below:Private Members:-
(5)
int pan - to store the personal account no.
char name[20] - to store the name
float taxableinc - to store the total annual taxable income.
float tax - to store the tax that is calculated.
computetax ( )- A function to compute tax from the following rule:Total Annual Taxable Income
Up to 60000
Rate of Taxation
0%
Greater than 60000, less than = 150000
Above 150000, upto 500000
10%
Above 500000
15%
5%
Public Members :inputdata ( ) - A function to enter the data and call the compute tax( )
function.
display( ) - To display the data.
(d)Consider the following declarations and answer the questions given
below:
[5]
class cloth
{
char category [5];
char description [25];
protected :
float price;
public :
void entercloth ( );
void displaycloth ( );
};
class design : protected cloth
{
char design [21];
protected :
float cost;
public:
int design;
design ( ) { }
void enterdesign ( );
void dispdesign ( );
};
class costing : public cloth
{
float desingfee;
float stiching;
float cal_cp ( );
protected:
float costprice;
float sellprice;
public:
void entercost ( );
void dispcost ( );
costing ( );
};
(i) Write the names of data members which are accessible from objects belonging
to class cloth.
(ii) Write the names of all members which are accessible from objects belonging to
class design.
(iii) Write the names of all the data members which are accessible from member
functions of class costing.
(iv) How many bytes will be required by an object belonging to class design?
(v) Can we access the data member category by using member function
Of class cloth? Justify your answer
(e) What is Data hiding ? Give a suitable example in c++.
[2]
(f) Write down the difference between Multiple and Hierarchical
[2]
Inheritance with suitable c++ example.
(g) Study the following program and select the possible output from it with
justification:
# include <iostream.h>
# include <conio.h>
# include <stdlib.h>
void main ()
{
char serial[] = {'A', 'B', 'C', 'D'};
[2]
int number[] = { 2, 6, 7, 3};
clrscr();
randomize();
cout << " The winner is : ";
cout << serial [random(3)];
for (int i = 0; i < 4; i++)
cout << number[sizeof(int) + random(2) - 1 ];
getch();
}
Outputs:
(i)
(ii)
(iii)
(iv)
The
The
The
The
winner
winner
winner
winner
is
is
is
is
:
:
:
:
A2776
D6766
B6767
C3672
(h) Find the output of the following program
#include<iostream.h>
#include<conio.h>
typedef char Str2[80];
void main()
{ char *Notes;
Str2 str=”vR2GooD”;
int L=6
Notes=Str;
While(L>=3)
{ Str[L]=(islower(Str[L])? toupper(Str[L]):tolower(Str[L]));
cout<<Notes<<endl;
L--;
[2]
Notes++;
}
}
Q3.
a) Define Macro with suitable example.
b) Which C++ header file (s) will be included to run /execute the following
C++ code?
void main( )
{ int Last =26.5698742658;
cout<<setw(5)<<setprecision(9)<<Last; }
c) Rewrite the following program after removing the syntactical error(s) if any.
Underline each correction.
# include <iostream.h>
const int Max 10;
void Main ( )
{
int N [Max]= { 20, 50,10, 30,40 } ;
for (Loc= Max-1 ; Loc > = 0 ; Loc - -)
cout>>N [Loc];
}
d) Find the output of the following C++ program:
#include<iostream.h>
void repch(char s[])
{
for (int i=0;s[i]!='\0';i++)
{
if(((i%2)!=0) &&(s[i]!=s[i+1]))
{
s[i]='@';
}
else if (s[i]==s[i+1])
{
s[i+1]='!';
i++;
}
}
}
void main()
{
char str[]="SUCCESS";
cout<<”Original String”<<str
repch(str);
cout<<"Changed String"<<str;
}
e) Find and write the output of the following C++ program code :
Note : Assume all required header files are already being included in the
program.
class Stock
{
long int ID;
float Rate;
int Date;
public:
Stock(){ID=1001;Rate=200;Date=1;}
void RegCode(long int I,float R)
{
ID=I;
Rate=R;
}
void Change(int New,int DT)
{
Rate+=New;
Date=DT;
}
void Show()
{
cout<<”Date :”<<Date<<endl;
cout<<ID<<”#”<<Rate<<endl;
}
};
void main()
{
Stock A,B,C;
A.RegCode(1024,150);
B.RegCode(2015,300);
B.Change(100,29);
C.Change(–20,20);
A.Show();
B.Show();
C.Show();
}
f) Look at the following C++ code and find the possible output(s) from the
options (i)
to (iv) following it. Also, write the maximum and the minimum values
that can be
assigned to the variable CHANGER.
Note :
• Assume all the required header files are already being included in the
code.
• The function random(n) generates an integer between 0 and n – 1
void main()
{
randomize();
int CHANGER;
CHANGER=random(3);
char CITY[][25]={“DELHI”,”MUMBAI”,”KOLKATA”,”CHENNAI”};
for(int I=0;I<=CHANGER;I++)
{
for(int J=0;J<=I;J++)
cout<<CITY[J];
cout<<endl;
}
}
(i)
DELHI
DELHIMUMBAI
DELHIMUMBAIKOLKATA
(iii)
MUMBAI
MUMBAIKOLKATA
MUMBAIKOLKATACHENNAI
(ii)
DELHI
DELHIMUMBAI
DELHIMUMBAIKOLKATA
DELHIMUMBAIKOLKATACHENNAI
iv)
KOLKATA
KOLKATACHENNAI
Q a) What is polymorphism? How it is implemented in C++? Illustrate with
4 suitable example.
b) Answer the questions after going through the following class.
class Exam
{char Subject[20] ;
int Marks ;
public :
Exam()
// Function 1
{strcpy(Subject, “Computer” ) ; Marks = 0 ;}
Exam(char P[ ])
// Function 2
{strcpy(Subject, P) ;
Marks=0 ;
}
Exam(int M)
// Function 3
{strcpy(Subject, “Computer”) ; Marks = M ;}
Exam(char P[ ], int M)
// Function 4
{strcpy(Subject, P) ; Marks = M ;}
};
i)Which OOP concept does Function 1 and Function 2 implement. Explain?
(ii)What is Function 3 called? When will it be invoked?
c) Write the definition of a class METROPOLIS in C++ with following
description :
Private Members
– MCode
//Data member for Code (an integer)
– MName
//Data member for Name (a string)
– MPop
//Data member for Population (a long int)
– Area
//Data member for Area Coverage (a float)
– PopDens //Data member for Population Density ( a float)
– CalDen() //A member function to calculate ------//Density as PopDens/Area
Public Members
– Enter()
//A function to allow user to enter values of
//Mcode,MName,MPop,Area and call CalDen()
//function
– ViewALL() //A function to display all the data members
//also display a message “Highly Populated Area”
//if the Density is more than 12000
d) Consider the following declarations and answer the questions given below :
class WORLD
{
int H;
protected :
int S;
public :
void INPUT(int);
};
void OUTPUT();
class COUNTRY : private WORLD
{
int T;
protected :
int U;
public :
void INDATA( int, int)
void OUTDATA();
};
class STATE : public COUNTRY
{
int M;
public :
void DISPLAY (void);
};
(i) Name the base class and derived class of the class COUNTRY.
(ii) Name the data member(s) that can be accessed from function
DISPLAY().
(iii) Name the member function(s), which can be accessed from the
objects of class STATE.
(iv) Is the member function OUTPUT() accessible by the objects of the class
COUNTRY ?
Q5. Write down the answers for followings:
1. (a) What is the difference between #define and const? Explain with suitable
example.
2.(a) What is the difference between type casting and automatic type
conversion? Explain with suitable example.
3.(a) What is the purpose of using a typedef command in C++. Explain with
suitable example.
4. (a) What is the difference between call by value and call by reference? Give
an example in C++ to illustrate both.
5. (a) What is the difference between Actual Parameter and Formal Parameter?
Give an example in C++ to illustrate both types of parameters.
6.(a) What is the function of #define keyword? Give an example to illustrate its
use.
7. (a) What is the difference between automatic type conversion and type
casting? Also, give a suitable C++ code to illustrate both.
8.. (a) What is the difference between Local Variable and Global Variable? Also,
give
a suitable C++ code to illustrate both.
9. (a) What is the difference between Object Oriented Programming and
Procedural Programming?
10. (a) Differentiate between the post-increment and pre-increment operators.
Also, give suitable C++ code to illustrate both.
11.What is macro? Why we need it and give a suitable example in c++.
Q6.Find the outputs of following.
(1) # include < iostream.h>
void main ()
{
intArray[] = {4,6,10,12};
int *pointer = Array ;
for (int I=1 ; I<=3 ; I++)
{
cout<<*pointer<<#”;
pointer ++;
}
cout<<endl;
for (I=1 ; I<=4 ; I++)
{
(*pointer)*=3 ;
-- pointer;
}
for(I=l; I<5; I + + )
cout << Array [I-1] << “@”;
cout << endl;
}
(2) #include<iostream.h>
void main ( )
{
int X[ ] = {10, 25, 30, 55, 100};
int *p = X ;
while ( *p < 110)
{
if (*p%3 ! = 0)
*p = *p + 1 ;
else
*p = *p + 2 ;
p++;
}
for(int I = 4 ; 1>= 1 ; I - -)
{
cout << X[I] << “*” ;
if ( I%3 = = 0) cout<<endl ;
}
cout<<X[0]*3<<endl ;
}
(3) #include<iostream.h>
void main ( )
{
int A[ ] = {10, 15, 20, 25, 30}
int *p = A;
while (*p < 30)
{
if (*p%3 ! = 0)
*p = *p + 2 ;
else
*p = *p + 1;
p++;
}
for (int J = 0; J<=4; J++)
{
cout << A[J] << “*” ;
if ( J%3 = = 0) cout<<endl;
}
}
(4) #include <iostream.h>
struct POINT
{int X, Y, Z;};
void StepIn(POINT & P, int Step=1)
{
P.X+=Step;
P.Y -=Step;
P.Z+=Step;
}
void StepOut(POINT & P, int Step=1)
{
P.X-=Step;
P.Y+=Step;
P.Z–=Step;
}
void main ( )
{
POINT P1={15, 25, 5}, P2={10, 30, 20};
StepIn(P1);
StepOut(P2,4);
cout<<P1.X<<“,”<<P1.Y<<“,”<<P1.Z<<endl;
cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
StepIn(P2,12);
cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
}
(5) #include<iostream.h>
void ChangeArray(int Number, int ARR[ ], int Size)
{
for (int L =0; L<Size; L++)
if (L<Number)
ARR [L] +=L;
e1se
ARR [L] *=L;
}
void Show (int ARR [ ], int Size)
{
for (int L=0; L<Size; L++)
(L%2!=0) ?cout<<ARR[L] <<"#": cout<<ARR[L]<<end1 ;
}
void main ( )
{
int Array [ ] = {30, 20, 40, 10, 60, 50};
ChangeArray (3, Array, 6) ;
Show (Array, 6) ;
}
(6) #include <iostream.h>
void SwitchOver(int A [ ], int N, int Split)
{
for (int K=0 ; K<N; K++)
if (K<Split)
A(K]+ =K;
else
A [K]*=K;
}
void Display (int A [ ], int N)
{
for (int K=0 ; K<N ; K++)
(K%2==0)? cout<<A[K]<<"%":cout<<A(K]<<end1;
}
void main ( )
{
int H[ ]= {30,40,50,20,10,5};
SwitchOver (H, 6, 3);
Display (H, 6);
}
(8) #include <iostream.h>
#include <ctype.h>
void MyCode (char Msg [], char CH)
{
for (int (Cnt=O;Msg[Cnt]!=’\0';Cnt++)
{
if (Msg[Cnt]>=’B’ && Msg[Cnt]<=’G’)
Msg[Cnt]=tolower(Msg[Cnt]);
else
if (Msg[Cnt]==’A’|| Msg[Cnt]==’a’)
Msg[Cnt]=CH;
else
if (Cnt%2==0)
Msg[Cnt]=toupper(Msg[Cnt]);
else
Msg[Cnt]=Msg[Cnt-l];
}
}
void main ()
{
char MyText [] =” ApEACeDriVE”;
MyCode(MyText,’@’);
cout<<“NEW TEXT:”<<MyText<<endl;
}
(9) #include<iostream.h>
void main ( )
{
int *Queen, Moves [ ] = {11, 22, 33, 44};
Queen = Moves;
Moves [2] + = 22;
cout<< "Queen @"<<*Queen<<end1;
*Queen - = 11;
Queen + = 2;
cout<< "Now @"<<*Queen<<end1;
Queen++;
cout<< "Finally@"<<*Queen«end1;
cout<< "New Origin @"<<Moves[0]<<end1;
}
(10)
Project Work
Sample Project : Student Information System, Shopping Mall, Banking, Payroll,
Digital Contact Diary,
Hotel Reservation System, Airways Booking System, Railways
System, etc…
Data



Collection and analysis:
Choose any system as your project for XII (a batch of two maximum)
Collect data about the project(bills, reports, admission forms, etc.)
Analyse the design screen and validations of forms (to clear, disable the
components, check for negative values, check for blanks, etc.)
System Development (Coding)
 Design the First Screen – with related picture, title with an impressive font
and an Enter button.
 Second Screen – as a Login Screen.
 Other Screens related to your project including ADD, DELETE, MODIFY and
SEARCH.
Note : Submit the project in a CD .
Your Project should cover the following specifications:






Project Title(name of the project, roll no, class)
Acknowledgement
Certificate
Introduction to project
Software and hardware required ( including Operating system )
Bibliography