Holidays
Homework
Class
XII
Sub:
Computer Science
Note: The questions to be done in class notebook .
Ques 1 (a)
Differentiate between a global variable and a local variable. Also give suitable
example in C++.
(b)
Name the Header file(s), to which the following built-in functions belongs to: (i)isdigit ( ) ( ii) gotoxy ( )
(c)
Rewrite the following program after removing syntactical error(s) if any.
Underline each correction.
#include
void
main( )
{
struct
movie
{
char movie_name[20];
char
movie_type;
int
tickets=100;
}
MOVIE;
gets(movie_name);
gets(movie_type);
}
(d)
Find the output of the following program (Assuming that all required header
files are included) void
main( )
{
char * NAME = “admiNStrAtiOn”;
for( int x=0;x
if(islower(NAME[x])
NAME[x] = toupper(NAME[x]);
else
if(isupper (NAME[x]))
if(x%2==0)
NAME[x] = NAME[x -1];
else
NAME[x]--;
cout<
}
(e)
Find the output of the following program
#include
void
Modify(int &a, int b=10)
{
if(b%10==0)
a+=5;
for(int
i=5;i<=a;i++)
cout<
cout<
}
void
Disp(int x)
{
if(x%3==0)
Modify(x);
else
Modify(x,3);
}
void
main()
{
Disp(3);
Disp(4);
Modify(2,20);
}
(f) Observe the following program Game.cpp carefully, if
the value of Num entered by user is 14, choose the correct possible output(s)
from the option i) to iv) and justify your option.
Output options:
i)
1
2 3 4
ii)
1
2 3 4 5 6 7 8 9 10 11
iii)
1 2 3 4 5
iv)
None
of the above
2. Define a class Travel in C++ with the description given below:
Private members:
plancode
of type long
place
of type characters array
number_of_travellers
of type integer
number_of_buses
of type integer
Public members:
A
constructor to assign initial values of plancode as 1001, place as “Kolkata”,
number_of_travellers as 5 and number_of_buses as 1
A
function newplan( ) which allows user to enter plancode , place and
number_of_travellers and also assign the number_of_buses as per the following
conditions:
number_of_travellers
number_of_buses
less
than 20 2
equal
to and more than 20 and less than 40 3
equal
to and more than 40 4
A
function show( ) to display the contents of all the data members on the screen.
3.
(a) What is the
need of defining a MACRO using #define directive. Explain with suitable
example.
(b)
Name the header files that shall be needed for the following code: void main()
{
int N, G;
randomize();
cin>>N;
G=random(N-5)+5;
cout<
}
(c)
Rewrite the following program after removing the syntax
error(s), if any. Underline
each correction
#include
int main()
{
struct
student
{
int. rno, mark;
}stu;
student
stuA= (1001,49);
student stuB= stuA;
if
(stuA!= stuB)
stuA.mark= 55;
else
stuB.mark= 25;
cout<
}
(d) Find the output of the
following program: #include
void main()
{
int list[5];
*list=5;
for(int i=1;
i<5 i="" p="">
*(list+i)=
*(list+i-1)*i;
cout<<”\n”;
for(i=0;i<5 i="" p="">
5>
cout<<””<<*(list+i);
}
(e) Find the output of the following
program:
#include
#include
class country
{ char *country_name;
int length;
public:.
country ( ) {length =0; country_name=new char [length+1];}
country (char *s)
{ length = strlen(s); country_name=new char [length +1];
strcpy (country_name, s);
}
void display () { cout<< country_name <
void Replace (country & a,
country & b)
{ length a.length + b.length;
delete country_name;
country_name=new char [length + 1];
strcpy (country_ name, a.country_name);
strcat (country_name, b.country name);
}
};
void main ( )
{ char * temp = “India”;
country country1 (temp), country2 (“Nepal”), country3 (“China”), S1,S2;
S1.Replace (country1, country2);
S2.Replace (S1,country3);
S1.display( );
S2.display ( );
}
#include
class country
{ char *country_name;
int length;
public:.
country ( ) {length =0; country_name=new char [length+1];}
country (char *s)
{ length = strlen(s); country_name=new char [length +1];
strcpy (country_name, s);
}
void display () { cout<< country_name <
{ length a.length + b.length;
delete country_name;
country_name=new char [length + 1];
strcpy (country_ name, a.country_name);
strcat (country_name, b.country name);
}
};
void main ( )
{ char * temp = “India”;
country country1 (temp), country2 (“Nepal”), country3 (“China”), S1,S2;
S1.Replace (country1, country2);
S2.Replace (S1,country3);
S1.display( );
S2.display ( );
}
(f) Find the output of the following program #include
void
change (int x[4],int i)
{
x[i]=x[i]*i;
}
int main()
{ int a[]={1,11,111,1111};
5>
cout<
exit(0);
getch( ) ;
}
c) Give the output of the following program :
# include
int calc( int u )
{ if( u % 2 = = 0 )
return u + 10 ;
else
return u * 2 ;
}
Void pattern( char m , int b = 2 )
{
For( int cnt = 0 ; cnt
Cout<
Cout<
}
Void main( )
{
Pattern(‘ * ‘) ;
Pattern(‘#’,4)
Pattern(‘@’,3);
}
d) Find the output of the following program :
# include< iostream.h>
struct point
{
int x , y ;
} ;
Void show( point p )
{
cout<< p. x << ‘ : ‘ << p.y <<
endl ;
}
Void main( )
{ Point u = { 20, 10 }, v , w ;
V = 1;
v.x + = 20 ;
w = v ;
u.y + = 10 ;
u.x + = 5 ;
w.x - = 5 ;
show( u ) ;
show( v ) ;
show( w ) ;
}
e) Rewrite the following program after removing the
syntactical errors( if any ) , underline each
correction :
#include()
void main( )
{
int X[ ] = { 60, 50, 30, 40 },y ; count =4 ;
cin>> y;
for( I = count – I ; I >=0 ; I - -)
Switch( I )
{
Case 0 :
Case 2 : cout<
Case 1 :
Case 3 : cout>> y + x[i];
} }
7.
Define a class Serial in C++ with the following specifications :
private members of class Serial
serialcode integer
title 20 characters
duration float
noofepisodes integer
public members of class Serial
A contructor function to initialize duration as
30 and noofepisodes as 10.
Newserial( ) function to accept values for
serialcode and title.
Otherentries( ) function to assign the values
of duration and noofepisodes with the help of
corresponding values passed as parameters to this
function .
Dispdata( ) function to display all the data
members on the screen.