XII - CS - HOME ASSIGNMENTS 1 & 2
HOME ASSIGNMENT 1 (BASED ON XI C++ REVIOSON TOUR: 12 MARKS) For XII-CS Students
1. What
is escape sequence? Explain with example.
2.
Name the header files which are required for successful execution of the
following c++ code:
void
main( )
{
char
String[ ] = “String”;
cout
<< setw(2)<<String;
}
3. Rewrite the following program after removing all the syntax
error(s), if any
#include[iostream] // line 1
void
main(){
int
LIST[ ]=[100,200,300,400] , Y; // line
2
COUNT=
4; // line 3
cin>>Y;
for(i=COUNT-1
; I >=0;,i--)
switch(i) {
case 0
:
case 2
: cout<<Y*LIST[i]<endl; //
line 4
break;
case
1:
case 3
: cout >> Y+LIST[i];
} }
4. Write the output of the following
program
#
include<iostream.h>
#
include<conio.h>
void
Execute(int &X, int Y = 200)
{int
TEMP = X + Y;
X +=
TEMP;
if (Y
!= 200)
cout
<< TEMP << " " <<X<<"
"<<Y<<endl; }
void
main() { int A = 50, B = 20;
Execute(B);
cout
<< A << " " << B << endl;
Execute(A,B);
cout
<< A << " " << B << endl;
getch();
}
5. In the following program , find the correct
possible outputs(s) form the given options :
#include<iostream.h>
#include<stdlib.h>
void
main(){
Randomize();
Char
places[][20]={“VARANASI”, ”VIZAG”, ”KANPUR”, ”AGRA”};
Int
city;
For(int
i=0 ; i<=2;i++){
city
=random(2) + 1;
Cout<<places[city]<<”@@”;}}
Output
:
(i) VIZAG @@ KANPUR @@VIZAG
ii) VARANASI @@ VIZAG@@KANPUR
iii)VIZAG@@KANPUR@@AGRA
iv) VIZAG@@KANPUR@@KANPUR
6. Write a function
void void COMBINE(int
A3[],int A1[],int A2[],int N,int M ) in C++ to transfer the content from
two arrays A1[ ] and A2[ ] to array A3[
]. The even places (0, 2, 4, ...) of
array A3[ ] should get the content from the array A1[ ] and odd places (1, 3, 5, ) of the array A3[] should
get the content from the array A2[ ].
Example:
If
the A1[ ] array contains
35,
60, 95
And
the A2[ ] array contains
100,
500, 805
The
A3[ ] array should contain
35,
100, 60, 500, 95, 805
7.
An array P[20] [50] is stored in the
memory along the column with each of its element occupying 4
bytes,
find out the 1ocation of P[15][10], if P[0][0] is stored at 5200.
8. Name the header files to which the following belong:
(i)abs( )(ii) random( )
9. Rewrite the following program after removing all the
syntax error(s), if any
#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;}
10. Write the output of the following program
#include<iostream.h>
#include<conio.h>
void
main( )
{
long NUM=1234543;
long NUM=1234543;
int
F=0,S=0;
do{
int R=NUM % 10;
int R=NUM % 10;
if (R
%2 != 0)
F +=
R;
else
S +=
R;
NUM /=
10;
}
while (NUM>0);
cout<<(F-S);
getch();
}
11. Write the output of the
following program
#include<iostream.h>
#include<conio.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;
getch();
}
12. Observe the following program GUESS.CPP carefully, if the value of variable Num entered by the user is 5 ,
choose the correct possible output(s) from the options from (i) to (iv) and
justify your option:
// Program Name : GUESS.CPP
#include<stdlib.h>
#include<iostream.h>
#include<conio.h>
void
main()
{
randomize();
int
Num,rndnum;
cin>>Num;
rndnum=random(Num)+5;
for(int
N=1;N<=rndnum;N++)
cout<<N<<"##";
getch();
}
Output
:
(i)1##2##3##4##
(ii)1##2##
(iii)1##2##3##4##5##6##7##8##9##
(iv)1##2##3##
13. Write the output of the
following C++ code. Also, write the name of feature of Object Oriented
Programming used in the following program jointly illustrated by the functions
[I] to [IV].
#include<iostream.h>
#include<conio.h>
int add (int x, int y , int z ) //
Function [I]
{
return (x+y+z);
}
int add (int x, int y ) //
Function [II]
{
return (x+y);
}
double add (double
x, int y , int z ) //
Function [III]
{
return (x+y+z);
}
double add (double x, double y ) //
Function [IV]
{
return (x+y);
}
void main( )
{
cout<<add(10,20,30)<<endl;
cout <<add(40,50)<<endl;
cout<<add(10.5,20,30)<<endl;
cout<<add(30.3,20.5);
getch();
}
14. Write a function in
C++, which accepts an integer array and its size as arguments and swap the
elements of every even location with its following odd location.
Example: If an array of nine elements initially contains the
elements as
2 4 165792310
then the function should rearrange the array as
42617523910
15. An array Array[20][15]
is stored in the memory along the column with each element occupying 8 bytes.
Find out the base address of the element Array[2][3] if the element Array[4][5]
is stored
at the address 1000.
HOME ASSIGNMENT 2 (BASED ON XI C++ REVIOSON TOUR: 12 MARKS)
1. What is
difference between call by value and call by reference ?Also, give a suitable
C++ Code to illustrate both.
2. Name the
header file(s) that shall be needed for successful compilation of the following
C++ code.
void main( )
{
char String[20];
gets(String);
strcat(String,”CBSE”);
puts(String);
}
3. 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; }
4. 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:
5
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; }
6. Find the output of the following
program:
#include<iostream.h>
#include<ctype.h>
void main( )
{ char
Mystring[ ] = "what@OUTPUT!";
for(int I=0; Mystring[I]!=’\0’;I++)
{ if(!isalpha(Mystring[I]))
Mystring[I]=’*’;
else if(isupper(Mystring[I]))
Mystring[I]=Mystring[I]+1;
else
Mystring[I] =Mystring[I+1];
} cout<<Mystring; }
7. An array
A[10…..20][-5…10] having starting row index as 10 and starting column index as
-5, Basic address of array is 2500. Size of each element is 8 Bytes.Find the
following :
(a) A[15][-2] (b)
A[18][8] (c) Size of Array “A”
**********************************************************************
8.
An array G[50][20] is stored in the memory along the row with each of
its elements occupying 8 bytes, find out 3
the location of G[10][15], if G[0][0] is
stored at 4200.
-------------------------------------------------------------------------------------------
9.
What is the difference between Type Casting and Automatic Type
Conversion? Also, give a suitable C++ code to 2
illustrate both.
.......................................................
10.
Write the names of the header files, which is/are essentially required
to run/execute the following C++ code: 1
void main()
{
char CH,Text[]=”+ve Attitude”;
for(int I=0;Text[I]!=’\0’;I++)
if(Text[I]==’’)
for(int I=0;Text[I]!=’\0’;I++)
if(Text[I]==’’)
cout<<endl;
else
{
CH=toupper(Text[I]);
cout<<CH;
cout<<CH;
}
}
.............................................
11.
Rewrite the following program after removing the syntactical error(s)
(if any). Underline each correction. 2
include<iostream.h>
typedef char[80] String;
void main()
void main()
{
String S=”Peace”;
int L=strlen(S);
int L=strlen(S);
cout<<S<<’has’<<L<<’characters’<<endl;
.........................
12.
Find the output of the following program: 3
#include<iostream.h>
void SwitchOver(int A[],int N,int Split)
{
{
for(int K=0;K<N;K++)
if(K<Split)
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]<<endl;
}
void main()
{
{
int H[]={30,40,50,20,10,5};
SwitchOver(H,6,3);
SwitchOver(H,6,3);
Display(H,6);
}
************************
13. Go through the C++ code shown below, and find
out the possible output or outputs from the suggested Output options(i) to
(iv), Also write the minimum and maximum values, which can be assigned to the
variable MyNum.
#include<iostream.h>
#include<stdlib.h>
void main()
#include<stdlib.h>
void main()
{
randomize();
int MyNum,Max=5;
MyNum=20+random(Max);
for (int N=MyNum;N<=25;N++)
cout<<N<<”*”;
cout<<N<<”*”;
}
(i) 20*21*22*23*24*25
(ii) 22*23*24*25
(iii) 23*24
(iv) 21*22*23*24*25
14.
Write a Get2From2() function in C++ to transfer the content from one
array ALL[] to two different arrays Odd[] 3
and Even[]. The Odd[] array should contain
the values from odd positions (1,3,5,…) of ALL[] and Even[] array should contain the values from even
positions(0,2,4,…) of ALL[].
Example:
If the ALL[] array contains
12,34,56,67,89,90
12,34,56,67,89,90
The ODD[] array should contain
34,67,90
34,67,90
And the EVEN[] array should contain
12,56,89
12,56,89
.......................
15.
An array G[50][20] is stored in the memory along the row with each of
its elements occupying 8 bytes, find out 3
the location of G[10][15], if G[0][0] is
stored at 4200.
..............
16.Which C++ header file(s) are
essentially required to be included to run/execute the following C++ source
code(Note: Do 1
not include any header file, which is/are
not required):
void main()
{
char TEXT[]=”SomeThing”;
cout<<”Remaining SMS
Chars :”<<160-strlen(TEXT)<<endl;
}
17.Observe the following program and find out,
which output(s) out of(i) to(iv) will not be expected from the program? What will be the
minimum and the maximum value assigned to the variable chance?
#include<iostream.h>
#include<stdlib.h>
void main( )
void main( )
{
randomize(
);
int Arr[]={9,6},N;
int Chance=random(2)+10;
for (int C=0;C<2;C++)
{
for (int C=0;C<2;C++)
{
N=random(2);
cout<<Arr[N]+Chance<<”#”;
}
}
(i) 9#6# (ii) 19#17# (iii) 19#16# (iv) 20#16#
18.Write a function SWAP2BEST (int
ARR[],int Size) in C++ to modify the content of the array in such a way that
the 3
elements, which are multiples of 10 swap with
the value present in the very next position in the array. For example:
If the content of array ARR is
90,56,45,20,34,54
90,56,45,20,34,54
The content of array ARR should become
56,90,45,34,20,54
56,90,45,34,20,54
19.An array T[20][10] is stored in the memory along the column with each
of the element occupying 2 bytes, find out
the memory location of T[10][5], if an
element T[2][9] is stored at location 7600.
*****************************************
Submit above two assignments on 14th April 2014. Use separate Book for Home work/Assignments.
******************************************