XIIB-CS MAY 2013 ASSIGNMENT/HOME WORK for Summer Vacation
XIIB-CS MAY 2013
ASSIGNMENT/HOME WORK for Summer Vacation
PART-1
Complete your NoteBooks
and isure that it contains the following:
1.A Detailed Note on
Revision of C++ PROGRAMMING Taught in XI:
REVIEW: C++ covered In Class -XI
2.Include all the points
discussed during April-May 2013 class room transactions :
Object Oriented Programming:
Concept of Object Oriented Programming - Data
hiding, Data encapsulation, Class and Object, Abstract
class and Concrete class, Polymorphism
(Implementation of polymorphism using Function overloading
as an example in C++); Inheritance, Advantages of
Object Oriented Programming over earlier
programming methodologies,
Implementation of Object Oriented Programming
concepts in C++:
Definition of a class, Members of a class - Data
Members and Member Functions (methods), Using
Private and Public visibility modes, default
visibility mode (private); Member function definition: inside
class definition and outside class definition using
scope resolution operator (::); Declaration of objects
as instances of a class; accessing members from
object(s), Objects as function arguments - pass by
value and pass by reference;
Constructor and Destructor:
Constructor: Special Characteristics, Declaration
and Definition of a constructor, Default Constructor,
Overloaded Constructors, Copy Constructor,
Constructor with default arguments;
Destructor: Special Characteristics, Declaration and definition of destructor;
Inheritance (Extending Classes):
Concept of Inheritance, Base Class, Derived Class,
Defining derived classes, protected visibility mode;
Single level inheritance, Multilevel inheritance
and Multiple inheritance, Privately derived, Publicly derived
and Protectedly derived class, accessibility of
members from objects and within derived class(es);
PART-2
1) Rewrite the
following program after removing the syntactical error(s) if any. Underline
each correction.
#include<iostream.h>
void main( )
{ F = 10, S = 20;
test(F;S);
test(S); }
void test(int x, int y = 20)
{ x=x+y;
count<<x>>y;}
2)
Find
the output of the following program:
#include<iostream.h>
void main( )
{ int U=10,V=20;
for(int I=1;I<=2;I++)
{ cout<<”[1]”<<U++<<”&”<<V 5 <<endl;
cout<<”[2]”<<++V<<”&”<<U
+ 2 <<endl; } }
3) Rewrite
the following C++ program after removing the syntax error(s) if any. Underline
each correction. [CBSE
2010] include<iostream.h>
class FLIGHT
{
Long
FlightCode;
Char
Description[25];
public
void
addInfo()
{
cin>>FlightCode;
gets(Description);
}
void
showInfo()
{
cout<<FlightCode<<”:”<<Description<<endl;
}
};
void main( )
{ FLIGHT
F;
addInfo.F();
showInfo.F;
}
4)
Rewrite
the following program after removing the syntax error(s) if any. Underline each
correction.
#include<iostream.h>
void main( )
{ One=10,Two=20;
Callme(One,Two);
Callme(Two); }
void Callme(int Arg1,int Arg2)
{ Arg1=Arg1+Arg2;
Count<<Arg1>>Arg2; }
5)
In
the following program, find the correct possible output(s)from the options:
#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize( );
char City[ ][10]={“DEL”, “CHN”, “KOL”,
“BOM”, “BNG”};
int Fly;
for(int I=0; I<3;I++) {
Fly=random(2) + 1;
cout<<City[Fly]<< “:”; } }
Outputs:
(i) DEL : CHN : KOL: (ii) CHN: KOL : CHN:
(iii) KOL : BOM : BNG: (iv) KOL : CHN : KOL:
6)
In
the following program, find the correct possible output(s)from the options:
#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize( );
char Area[ ][10]={“
NORTH”, “SOUTH”, “EAST”, “WEST”};
int ToGo;
for(int I=0; I<3;I++) {
ToGo=random(2) + 1;
cout<<Area[ToGo]<<”:”;
} }
Outputs:
(i) SOUTH : EAST : SOUTH :
(ii) NORTH : SOUTH : EAST :
(iii) SOUTH : EAST : WEST
: (iv) SOUTH : EAST : EAST :
7)
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
Numbers[Max];
Numbers = {20,50,10,30,40};
for(Loc=Max-1;Loc>=10;Loc--)
cout>>Numbers[Loc]; }
8)
In
the following C++ program what is the expected value of Mysore from options (i)
to (iv) given below.Justify your answer.
#include<stdlib.h>
#include<iostream.h>
void main( )
{ randomize(
);
int Score[ ] =
{25,20,34,56,72,63},Myscore;
cout<<Myscore<<endl; }
Ii) 25 (ii) 34 (iii) 20 (iv) None of
the above.
9)
Find
the output of the following program
#include<iostream.h>
void main( )
{ long
NUM=1234543;
int
F=0,S=0;
do
{ int
R=NUM % 10;
if
(R %2 != 0)
F
+= R;
else
S
+= R;
NUM
/ = 10;
} while (NUM>0);
cout<<F-S; }
10)
Rewrite
the following program after removing the syntactical error(s), if any.
Underline each correction.
#include<iostream.h>
const int Multiple 3;
void main( )
{ value = 15;
for(int Counter = 1;Counter
= <5;Counter ++, Value -= 2)
if(Value%Multiple = = 0)
cout<<Value *
Multiple;
cout<<end1;
else
cout<<Value +
Multiple <<endl; }
11)
Find
the output of the following program
#include<iostream.h>
#include<string.h>
#include<ctype.h>
void Convert(char Str[
],int Len)
{ for(int Count=0;Count<Len;Count++)
{ if(isupper(Str[Count]))
Str[Count]=tolower(Str[Count]);
else if (islower(Str[Count]))
Str[Count]=toupper(Str[Count]);
else if(isdigit(Str[Count]))
Str[Count]=Str[Count]+1;
else Str[Count]=.*.;
} }
void main( )
{ char Text[ ]=”CBSE Exam 2005”;
int Size = strlen(Text);
Convert(Text,Size);
cout<<Text<<endl;
for(int C=0,R=Size . 1;C<=Size/2;C++,R--)
{ char
Temp=Text[C];
Text[C]=Text[R];
Text[R]=Temp; }
cout<<Text<<endl; }
12)
The
following code is from a game, which generate a set of 4 random numbers. Praful
is playing this game, help him to identify the correct option(s) out of the
four choices given below as the possible set of such numbers generated from the
program code so that he wins the game. Justify your answer. [CBSE 2010]
#include<iostream.h>
#include<stdlib.h>
const int LOW=25;
void main()
{ randomize();
int POINT=5, Number;
for(int I=1;I<=4;I++)
{ Number=LOW+random(POINT);
cout<<Number<<":"
<<endl;
POINT--; } }
(i)
29:26:25:28: (ii)24:28:25:26:
(iii) 29:26:24:28; (iv)29:26:25:26:
13) Rewrite the
following program after removing the syntactical errors (if any). Underline
each correction.
#include [iostream.h]
class MEMBER
{
int Mno;float Fees;
PUBLIC:
void Register(){cin>>Mno>>Fees;}
void Display{cout<<Mno<<" :
"<<Fees<<endl;}
};
void main()
{
MEMBER M;
Register();
M.Display();
}
PART-3
14.
Find the output of the following program.
#include<iostream.h>
void Withdef(int
HisNum=30)
{ for(int I=20;I<=HisNum;I+=5)
cout<<I<<”,”;
cout<<endl; }
void Control(int
&MyNum)
{ MyNum+=10;
Withdef(MyNum); }
void main()
{ int YourNum=20;
Control(YourNum);
Withdef();
cout<<.Number=.<<YourNum<<endl; }
15.
Find the output of the following program:
#include<iostream.h>
void Indirect(int Temp=20)
{ for(int I=10;I<=Temp;I+=5)
cout<<I<<”,”;
cout<<endl; }
void Direct(int &Num)
{ Num+=10;
Indirect(Num); }
void main( )
{ int Number=20;
Direct(Number);
Indirect( );
cout<<”Number =”<<Number<<endl; }
16.
Find the output of the following program:
#include<iostream.h>
#include<ctype.h>
void Secret(char Msg[],int
N);
void main( )
{ char SMS=” rEPorTmE”;
Secret(SMS,2);
cout<<SMS<<endl; }
void Secret(char Msg[],int
N)
{ for(int c=10;Msg[]1=’\0’;c++)
if(c%2==0)
Msg[c]= Msg[c]+N;
else if (isupper(Msg[c]))
Msg[c]=tolower(Msg[c]);
else
Msg[c]= Msg[c]-N; }
17.
Find the output of the following program: [CBSE 2010]
#include<iostream.h>
struct three_d
{ int x,y,z; };
void movein(three_d &t, int step=1)
{ t.x+=step;
t.y+=step;
t.z+=step; }
void moveout(three_d &t, int step=1)
{ t.x-=step;
t.y+=step;
t.z-=step; }
void main()
{ three_d
t1={10,20,5},t2={30,10,40};
movein(t1);
moveout(t2,5);
cout<<t1.x<<","<<t1.y<<","<<t1.z<<endl;
cout<<t2.x<<","<<t2.y<<","<<t2.z<<endl;
movein(t2,10);
cout<<t2.x<<","<<t2.y<<","<<t2.z<<endl; }
18.
Write the output of the following program:
#include<iostream.h>
int func(int &x,int
y=10)
{ if(x%y==0) return
++x;else return y- -; }
void main( )
{ int p=20,q=23;
q=func(p,q);
cout<<p<<q<<endl;
p=func(q);
cout<<p<<q<<endl;
q=func(p);
cout<<p<<q<<endl; }
19.
Find the output of the following program. [CBSE 2010]
#include<iostream.h>
#include<ctype.h>
void Mycode(char
Msg[],char ch)
{ for(int cnt=0;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-1];
} }
void main()
{ char
MyText[]="ApEACeDriVE";
Mycode(MyText,'@');
cout<<"NEW TEXT:
"<<MyText<<" "<<endl; }
PART-4
20. Consider the following declarations and
answer the questions given below:
class Animal
{
int leg:
protected:
int tail;
public:
void INPUT (int );
void OUT ( );
};
class wild : private Animal
{
int carniv;
protected:
int teeth;
Public:
void INDATA (int, int )
void OUTDATA( );
};
class pet : public Animal
{
int herbiv;
public:
void Display (void);
};
(i) Name the base class and derived class of
the class wild.
(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 pet.
(iv) Is the member function OUT ( )
accessible by the objects of the class wild?
21.
Answer the questions (i) to (iv) based on the following class declaration:
class Medicine
{
char category[10];
char Date_of_Manufacture[10];
char Date_Of_Expiry[10];
protected:
char company[20];
public:
int x,y;
Medicine( );
void Enter( );
void Show( );
};
class Tablet :protected Medicine
{
protected:
char tablet_name[30];
char volume_label[20];
void disprin( );
public:
float price;
Tablet( );
void enterdet( );
void showdet( );
};
class PainReliever : public Tablet
{
int Dosage_units;
long int tab;
char effects[20];
protected:
int use_within_Days;
public :
PainReliever( );
void enterpr( );
showpr( );
};
(i) How many bytes will be required by an
object of class Drug and an object of class PainReliever respectively.
(ii) Write names of all the data members
which are accessible from the object of class PainReliever.
(iii) Write names of all member functions
which are accessible from objects of class PianReliever.
(iv) Write the names of all the data members
which are accessible from the functions enterpr().
22.
Answer the questions (i) to (iv) based on following code:
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 that can be
accessed from function DISPLAY( )
(iii) Name the member functions, which can be
accessed from the objects of class State.
(iv) Is the member function OUTPUT()
accessible by the objects of the class Country ?
Define a class named ADMISSION in C++ with
the following descriptions: 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.
23.
Define a class named MOVIE in C++ with the following description:
Private members
HALL_NO integer
MOVIE_NAME Array of characters (String)
WEEK integer (Total number of weeks the same
movie is shown)
WEEK_COLLECTION Float
TOTAL_COLLECTION Float
Public Members
* Function Read_Data( ) to read an object of
ADMISSION type
* Function Display( ) to display the details of
an object
* Function Update( ) to update the total
collection and Weekly collection once in
week changes. Total collection will be incremented by Weekly collection
and Weekly collection is made Zero
24.
Define a class in C++ with following description:
Private Members
• A data member Flight number of type integer
• A data member Destination of type string
• A data member Distance of type float
• A data member Fuel of type float
• A member function CALFUEL() to calculate
the value of Fuel as per the following criteria:
Distance
Fuel
<=1000 500
more than 1000 and <=2000 1100
More than 2000 2200
Public Members
" A function FEEDINFO() to allow user to
enter values for Flight Number, Destination, Distance & call function
CALFUEL() to calculate the quantity of Fuel
" A function SHOWINFO() to allow user to
view the content of all the data members
25.
Define a class Clothing in C++ with the following descriptions:
Private Members:
Code of type string
Type of type string
Size of type integer
Material of type string
Price of type float
A function Calc_Price() which calculates and
assigns the value of Price as
follows: For the value of Material as
“COTTON”
Type Price (Rs.)
TROUSER 1500
SHIRT 1200
For Material other than “COTTON” the above
mentioned Price gets reduced by 25%.
Public Members:
A constructor
to assign initial values of Code, Type and Material with the word “NOT
ASSIGNED” and Size and Price with 0. A function Enter () to input the values of
the data members Code, Type, Size and Material and invoke the CalcPrice()
function. A function Show () which displays the content of all the data members
for a Clothing.
NOTE- Submit the above works/assignments latest by 24th
June 2013. Feel free to mail me at hsyadav.kvs@gmail.com
for any queries/doubts.