Tuesday, May 6, 2014

Holiday Homework Class XII

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="">
                          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 ( );
}
   (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};
                          for(int k=0;k<4 k="" p="">
                          {
                              change(a,k);
                               cout<
                            }   }
4.      Define a class named DRAMA in C++ with the following description                          
Private members
SHOW_NO                                integer
NAME_OF_THE_DRAMA        Array of characters (String)
DAY                                       integer (Total number of days the same drama is shown)
DAILY_COLLECTION            float
TOTAL_COLLECTION          float
Public Members
      input_data  :        A user defined function  to read an object of ENTRY type
     print_data :          A function  to display the details of an object
      update_data: A  function  to update the total collection and daily collection once the day
    changes.  Total collection will be incremented by daily collection and daily  collection is made Zero

5.    Define a class TEST in C++ with following description:
Private Members
• TestCode of type integer
• Description of type string
• NoCandidate of type integer
• CenterReqd (number of centers required) of type integer
• A member function CALCNTR() to calculate and return the number of centers as
(NoCandidates/100+1)
Public Members
• A function SCHEDULE() to allow user to enter values for TestCode,
Description, NoCandidate & call function CALCNTR() to calculate the number of
Centres
• A function DISPTEST() to allow user to view the content of all the data members

6. a) What is the difference between call by value and call by reference in a user defined function in C++ ?
Give an example.
b) Name the header file, included in the following program :
void main( )
{ clrscr( ) ;
cout<
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.


ASSIGNMENT INHERITANCE

ASSIGNMENT INHERITANCE