Sunteți pe pagina 1din 10

REVISION PRACTICE

CLASS XII
void main()
{
int x = 20, y = 23;
1. What is wrong with the following while loop: y = fun (x, y);
int counter = 1; b. int counter = 1;
cout << x << ‘, ’ << y << ‘\n’;
while ( counter < 100) while ( counter < 100)
x = fun (y);
{ cout << counter << “\n;
cout << x << ‘, ’ << y << ‘\n’;
cout << counter << “\n; counter + +;
y = fun (x);
counter - -;
cout << x << ‘, ’ << y << ‘\n’;
}
}
2. What will be the output of following: 7. Find output
void main ( )
#include<iostream.h>
{
void fun (int &A, int &B)
int val = 10;
{
cout << val ++ << val << ++ val;
A = A + B;
}
B = A – B;
A = A – B;
3. Given the following code fragment: }
int ch = 20; void main ( )
cout << ch << ++ ch << ch << “\n”; {
(i) The output of the code fragment. int a = 4, b = 18;
(ii) What is the effect of replacing ++ ch with ch + 1? fun (a, b);
cout << a << “, ” << b;
4. Differentiate between the output of following code }
fragments:
(i) int f = 1, i = 2; (ii) int f = 1, i = 2; 8. Give output:
while (++ i < 5) do { void Change (int x[4]. int i)
f *= i; f *= i; {
cout << f; } while (++ i < 5); x[i] = x[i] * I;
cout << f; }
void main ( )
5. Give output: {
#include<iostream.h> int x[ ] = {11, 21, 31, 41};
int global = 20; for (int i = 0; i < 4; i++)
void fun (int &x, int y) {
{ Change (x, i);
x = x – y; y = x * 10; cout << x[i] << ‘\n’;
cout << x << ‘, ’ << y << ‘\n’; }}
}
void main() 9. Rewrite the following codes after removing errors, if
{ any, in the following snippet. Explain each
int global = 8; error.
fun (:: global, global); #include<iostream.h>
cout << global << ‘, ’ << :: global << ‘\n’; void main()
fun (global, :: global); {
cout << global << ‘, ’ << :: global << ‘\n’; int x[5], *y, z[5]
} for (i = 0; i < 5; i ++
{
6. Give output: x[i] = i;
#include<iostream.h> z[i] = i + 3;
int fun ( int &a, int b = 0) y = z;
{ x = y;}}
if (a % b = = 0) return ++ a;
else return b - - ; }
10. Rewrite the following codes after removing errors, if 15. What will be the output of the following program?
any, in the following snippet. Explain each #include <iostream.h>
error. void main()
void main() {
{ int A[5] ={0, 3, 4, 2, 1};
const int i = 20; int b[5]= {0};
const int * const ptr = &i; int n =4;
(*ptr)++; for ( int i=0; i<5;++i)
int j = 15; b[a[i]]=a[i];
ptr = &j; cout<< b[0]<<b[1]<<b[2]<<b[3}<<b[4];
} }

11. Give the output of the following program: 16. What will be the output of the following program
void main() #include<iostream.h>
{ void main()
char *p = “Difficult”; {
char c; int var1=5,var2=10;
c = ++ *p ++; for(int i=1;i<=2;i++)
printf (“%c”,c); {
} cout << var1++ << “\t” << --var2<< endl;
cout << var2-- << “\t” << ++var1<< endl;
12. Give the output of the following program: }
void main() }
{
int x [] = { 10, 20, 30, 40, 50}: 17. Find the output of the following program
int *p, **q, *t; #include<iostream.h>
p = x; void main( )
t = x + 1; {
q = &t; long NUM = 1234543;
cout << *p << “,” << **q << “,” << *t++; int F = 0, S = 0;
} do
{
13. In the following program, if the value of N given by int Rem = NUM% 10;
the user is 20, what maximum and if (Rem % 2 !=0)
minimum value the program could possibly display ()? F+ =R;
#include<iostream.h> else
#include<stdlib.h> S+ = R;
void main() NUM/=10;
{ } while(NUM>0);
int N, Guessme; cout<<F-S;
randomize(); }
cin>>N;
Guessme = random(N-10) + 10 ; 18. Find the output of the following program:
cout<<Guessme<<endl; #include<iostream.h>
} void main()
{
14. Rewrite the following program after removing the long Number = 7583241;
error(s), if any. Underline each correction. int First=0, Second=0;
#include <iostream.h> do
void main() {
{ int R=Number%10;
int x, sum =0; if (R%2==0)
cin>>n; First+=R;
for (x=1;x<100, x+=2) else
if x%2=0 Second+=R;
sum+=x; Number /=10;
cout<< “sum=” >>sum; } while (Number > 0);
} cout<<First-Second;
}
{
19. Rewrite the following program after removing the char *x = “teAmIndia”;
syntactical error(s), if any Underline each char c;
correction: c = ( *(x+1) ) ++ ;
#include <iostream.h> cout<<c;
void main( )
}
{
struct TV
{ Give the output of the following program( Assume
char Manu_name[20]; all necessary header files are included):
char Tv_Type; void main( )
int Price = 17000; {
} New Tv; char * x = “teAmIndia”;
gets(Manu_name); char c;
gets(Tv_Type); c = ++( *(x+1) );
} cout<<c;
}
20. Identify error in the following program segment:
class ABC{
What will be the output of the program( Assume all
public:
int read(); necessary header files are included) :
char display val(); #include<iostream.h>
private: void print (char * p )
int x; {
char ch; p = "pass";
} cout<<"value is "<<p<<endl;
}
21. Write the output of the following program: void main( )
#include<iostream.h> {
class Test{ char * x = "Best of luck";
int a, b;
print(x);
public:
void set( int I, int j) { a = I; b = j;}
cout<<"new value is "<<x<<endl;
void show() {cout << a << “ ” << b << endl;} }
};
void main() Give output of following code fragment:
{ char *msg = “a ProFile”;
Test t1, t2; for (int i = 0; i < strlen (msg); i++)
T1.set(10,4); if (islower(msg[i]))
t2 = t1; msg[i] = toupper (msg[i]);
t1.show() else
t2.show() if (isupper(msg[i]))
} if( i % 2 != 0)
msg[i] = tolower (msg[i-1]);
Give the output of the following program( Assume else
all necessary header files are included) msg[i--];
cout << msg << endl;
:
void main( ) 4 Give output of following code fragment:
{ char *msg = “WELCOME”;
char * x = “teAmIndia”; for (int i = strlen (msg) - 1; I >= 0; i--)
char c; if (islower(msg[i]))
c = ++ *x ++; msg[i] = toupper (msg[i]);
cout<<c; else
} if (isupper(msg[i]))
if( i % 2 != 0)
Give the output of the following program(Assume all msg[i] = tolower (msg[i-1]);
necessary header files are included): else
msg[i--];
void main( )
cout << msg << endl;
void main()
5 Find output {
#include<iostream.h> int ar[] = {2, 3, 4, 5};
struct Box { int *ptr = arr;
int Len, Bre, Hei; int val = *ptr; cout << val << endl;
}; val = *ptr ++; cout << val << endl;
void Dimension(Box B) val = *ptr; cout << val << endl;
{ val = * ++ptr; cout << val << endl;
cout << B.Len << “ X ” << B.Bre << “ X ”; }
cout << B.Hei << endl;
} 9 Give the output of the following program :
void main ( ) #include<iostream.h>
{ struct point
Box B1 = {10, 20, 8}, B2, B3; {
++B1.Hei; int x,y;
Dimension (B1); };
B3= B1; void showpoint p)
++B3.Len; {
B3.Bre++; cout<<p.x<< ‘:’<<p.y<<endl;
Dimension (B3); }
B2= B3; void main()
B2.Hei += 5; {
B2.Len - = 2; point u = {20,10},V,W;
Dimension (B2); v=u;
} v.x+=20;
w=v;
6 Give output u.y+=10;
int Execute( int M) u.x+=5;
{ w.x-=5;
if (M % 3 = 0) show(u);
return M * 3; show(v);
else show(w);
return M + 10; }
}
void output( int B = 2) 10. Write the output of the following program :
{ #include<iostream.h>
for (int T = 0; T < B; T++) int calc(int u)
cout << Execute(T) << “*”; {
cout << endl; if(u%2==0)
} return u+10;
void main() else
{ return u*2;
output (4); }
output ( ); void pattern(char M, int B=2)
output (3); {
} for(int cnt=0;cnt<b;cnt++)
cout<<calc(cnt)<<m;
7 Give the output of the following program: cout<<endl;
void main() }
{ void main()
int ar[] = {2, 3, 4, 5}; {
int *ptr = arr; pattern(‘*’);
int val = *ptr; cout << val << endl; pattern(‘#’,4);
val = *ptr ++; cout << val << endl; pattern(‘@’,3);
val = *ptr; cout << val << endl; }
val = * ++ptr; cout << val << endl;
}
11 Find the output of the following program:
8 Give the output of the following program: #include<iostream.h>
#include<conio.h>
void ChangeContent(int Arr[], int Count) void convert (char str[], int len)
{ {
for(int C=1 ; C<Count ; C++) for (int count =0; count <len; count++)
{ {
Arr[C-1]+=Arr[C] ; if ( isupper(str[count]))
} str[count]=tolower(str[count]);
} else if ( islower(str[count]))
void main() str[count]=toupper(str[count]);
{ else if ( isdigit(str[count]))
clrscr( ); str[count]=str[count]+2;
int A[ ]={3, 4 , 5}, B[ ]={10,20,30,40}, C[ ]={900, 1200}, else
L; str[count]= ‘#’;
ChangeContent(A,3); }
ChangeContent(B,4); }
ChangeContent(C,2); void main()
for(L=0 ; L<3 ; L++) {
{ char text[]= “AISSCE 2008@”;
cout<<A[L]<<"#"; int size =strlen(text);
} convert (text,size);
cout<<endl; cout<<text<<endl;
for(L=0 ; L<4 ; L++) for (int c =0, r=size-1; c<=size/2;c++, r--)
{ {
cout<<B[L]<<"#" ; char temp= text[c];
} text [c]= text[r];
cout<<endl; text[r]= temp;
for(L=0 ; L<2 ; L++) }
{ cout<< text << endl;
cout<<C[L]<<"#" ; }
}
getch(); 14 Give the output of the following program.
} #include < iostream.h >
#include <conio.h >
12 Find the output of the following program: int a = 10;
#include<iostream.h> int main( )
#include<conio.h> {
struct Game void demo ( int &, int , int *);
{ clrscr( );
char Magic[20]; int a = 20;
int Score; demo ( ::a,a,&b);
}; cout << ::a << “\t” << a << “\t” << b;
void main() }
{ void demo ( int &x, int y , int *z )
clrscr(); {
Game M={"Tiger", 500} ; a += x; y *= a; *z = a+y;
char *Choice ; cout << x << “\t” << y << “\t” << *z << endl;
Choice = M.Magic; }
Choice[4]='P' ;
Choice[2]='L' ; 15 Write the output of the follwoing program segment
M.Score+=50; char *NAME="ComPUteR";
cout<<M.Magic<<M.Score<<endl; for(int x=0;x<strlen(NAME);x++)
Game N= M; if(islower(NAME[x]))
N.Score-=120 ;
NAME[x]=toupper(NAME[x]);
cout<<N.Magic<<N.Score<<endl;
getch();
else
} if(isupper(NAME[x]))
if(x%2==0)
13 Write the output of the following program: NAME[x]=tolower(NAME[x]));
#include<iostream.h> else
#include<string.h> NAME[X]=NAME[x-1];
#include<ctype.h> puts(NAME);
void Replace (state &a, state &b)
16 What will be the output of the following program { size = a.size + b.size;
#include<iostream.h> delete state_name;
#include<ctype.h> state_name = new char[size+1] ;
#include<conio.h> strcpy(state_name, a.state_name);
#include<string.h> strcat(state_name, b.state_name);
void changestring(char text[], int &counter) }
{ };
char *ptr = text; void main( )
int length=strlen(text); { char *temp = “Delhi”;
for(;counter<length-2;counter+=2,ptr++) state state1(temp), state2(”Mumbai”), state3(”Nagpur”),
{ S1, S2;
*(ptr+counter) = toupper(*(ptr+counter)); S1.Replace(state1, state2);
} S2.Replace(S1, state3);
} S1.display( );
void main() S2.display( );
{ }
clrscr();
int position = 0; Find the output of the following program:
char message[]= “Mouse Fun”; #include<iostream.h>
changestring(Message,position); #include<string.h>
cout<<message<< “@” <<position; class student
} { char *name;
int I ;
17 What will be the output of the following program: public:
#include<iostream.h> student( ) {I =0; name=new char [ I +1]; }
#include<ctype.h> student (char *s)
#include<conio.h> { I =strlen(s); name=new char[I+1];
#include<string.h> strcpy (name,s);
void changestring(char text[], int &counter) }
{ void display( ) {cout<<name<<endl;}
char *ptr = text; void manipulate(student & a, student & b)
int length=strlen(text); { I = a.I + b.I;
for( ;counter<length-2; counter+=2,ptr++) delete name;
{ name=new char[I+1];
*(ptr+counter) = toupper(*(ptr+counter)); strcpy(name, a.name);
} strcat(name, b.name);
} }
void main() };
{
clrscr(); void main( )
int position = 0; { char * temp = “Jack”;
char message[]= “Pointer Fun”; student name1 (temp), name2(” Jill”),
changestring(Message, position); name3(”John”),S1,S2;
cout<<message<< “@” <<position; S1 .manipulate (name1, name2);
} S2.manipulate (S1, name3);
S1.display ( );
18. Find the output of the following program S2.display ( );
# include<iostream.h> }
#include<string.h>
class state 21 Find the output of the following program:
{ char * state_name; #include<iostream.h>
int size; #include<string.h>
public; class country
state( ); { size=0; state_name=new char[size+1]; } { char *country name;
state(char *s) int length;
{ size = strlen(s) ; state_name = new char[size+1];} public:.
strcpy(state_name, s); country ( ) {length =0; country_name=new char
} [length+1];}
void display() {cout<<state name<<endl; } country (char *s)
{ length = strlen(s); country_name=new char [length +1]; for (int i=0;i<=l;i++)
strcpy (country_name, s); {
} if
void display ( ) { cout<< country_name <<endl;} ((boy[i]==’a’)||(boy[i]==’e’)||(boy[i]==’i’)||(boy[i]==
void Replace (country & a, country & b)
’o’ || (boy[i]==’u’))
{ length a.length + b.length;
delete country_name;
v=v+1;
country_name=new char [length + 1]; }
strcpy (country_ name, a.country_name); cout<<l<<v;
strcat (country_name, b.country name); return;
} }
}; 36. Give the output of the following program :
void main ( ) #include<iostream.h>
{ char * temp = “India”; #include<conio.h>
country country1 (temp), country2 (“Nepal”), country3 main( )
(“China”), S1,S2; {
S1.Replace (country1, country2);
int number[10],a,b,c,d;
S2.Replace (S1,country3);
S1.display( ); clrscr( );
S2.display ( ); for(int i=0;i<10;i++)
} {
number[i]=i+i;
22 Find the output of the following program: }
#include < iostream.h> clrscr( );
void main( ) for(int j=0;j<9;j++)
{ int *PointerArray [10]; {
int marks [ = {75, 68, 90, 34, 0, 10, 90, 65}; for(int k=j+1;k<10;k++)
for (int I = 0; marks [ I]!=0; I++) {
{ PointerArray [I]=&marks[I];
if (number[j]>number[k])
* (PointerArray [I] ) += 5;
}
{
int index = 0; a=number[j];
while(index < I ) number[j]=number[k];
{ int p=*(PointerArray[index] ); number[k]=a;
if(p >=60) cout <<p<< ‘, ’; }}}
index ++; cout<<endl;
} for(i=0;i<10;i++)
} cout<<number[i]<<“\t”;i++;
getch( );
Give the output of the following program : return 0;
#include<iostream.h> }
#include<conio.h>
#include<string.h> 37 Give the output of the following program :
#include<ctype.h> #include<iostream.h>
void main( ) #include<conio.h>
{ main( )
int b; {
char bboy[10]; int a=0;
clrscr( ); clrscr( );
bboy[0]=’d’,bboy[1]=’e’,bboy[2]=’f’,bboy[3]=’g’; char *name;
len(bboy); name= “Internet Browsing”;
getch( ); for(a=0;a<=8;a++)
return 0; cout<<name[a+1];
} cout<<endl;
void len(char boy[10]) cout<<name[a];
{ cout<<endl<<(int)name[a]-1;
int l,v=0; getch( );
l=strlen(boy); return 0;
} main( )
{
38 Give the output of the following program : clrscr( );
#include<iostream.h> char *name;
#include<conio.h> int len=0;
main( ) name= “dheeraj@lw1.vsnl.net.in”;
{ len = strlen(name);
void arm(int); len = len-1;
clrscr( ); cout<<endl;
int num; for(int i=len;i>=0;i=i-2)
num=191; { cout<<name[i];}
arm(num); cout<<endl;
getch( ); cout<<i;
return 0; cout<<endl;
} cout<<name[i+4];
void arm(int n) cout<<endl;
{ getch( );
int number, sum=0,dg,dgg,digit; return 0;
number=n; }
while(n>0)
{ What is the output of the following program( Assume
dg=n/10; all necessary header files are
dgg=dg*10; included) :
digit=n-dgg; void main( )
cout<<digit+digit<<endl; {
sum=sum+digit*digit*digit; char *name= “IntraNet”;
n=n/10; for ( int i = 0; i < strlen( name) ; i++)
} {
cout<<digit<<endl<<sum; if ( islower( name[i]) )
} name[i] =toupper(name[i]) ;
else
name[i] = name[i - 1] ;
39 Give the output of the following program : }
#include<iostream.h> }
#include<conio.h> 43 What is the output of the following program(
#include<string.h> Assume all necessary header files are
main( ) included) :
{ void main( )
clrscr( ); {
char *name; char * name= “teAmIndia”;
int l; for ( int i = 0; name[i] ! = ‘\0’ ; i + 2)
name= “SHANA”; {
l=strlen(name); if ( islower( name[i]) )
cout<<l<<endl<<(int) name[l-2]; name[i] = toupper(name[i]) ;
cout<<endl; else
cout<<name[l-3]; name[i] = tolower(name[i]);
getch( ); }
return 0; }
} 44 What is the output of the following program(
Assume all necessary header files are included) :
40 Give the output of the following program : void main( )
#include<iostream.h> {
#include<conio.h> char * name= “ThE bESt mAN wINs”;
#include<stdio.h> for ( int i = 0; name[i] ! = ‘\0’ ; i + 1)
#include<string.h> {
if ( islower( name[i]) ) }
name[i] = toupper(name[i]) ; cout<<str;
else }
if( isupper(name[i]) ) void main( )
if ( i % 2 = = 0) name[i] -- ; {
else clrscr( );
name[i] = tolower(name[i - 1] NewText(“Good Morning”, 0) ;
}} }

45 What is the output of the following program( 48 What is the output of the following program(
Assume all necessary header files are included) : Assume all necessary header files are included) :
void main( ) # include <iostream.h>
{ # include<ctype.h>
char * str = “TEACHER”; #include<string.h>
for ( int i = strlen(str) – 1 ; i >= 0 ; i --) #include<conio.h>
{ class country{
for ( int x = 0 ; x <= i ; x ++) char * c_name;
cout<<s[x] ; int length;
cout<<”\n”; public:
}} country( )
{
length = 0;
46 What is the output of the following program( c_name = new char[length+1];
Assume all necessary header files are included) : }
void main( ) country(char * s)
{ {
int * p[10]; length = strlen(s);
int score[] = {80, 30, 74, 50, 34, 67,0, 98}; c_name = new char[length+1];
for ( int i = 0 ; score[i] != 0 ; i ++) strcpy(c_name, s);
{ }
p[i] = & score[i]; void display()
*(p[i]) += 10; {
} cout<<c_name<<endl;
int count = 0; }
while( count < i) void replace(country &a, country &b)
{ {
int q = *(p[count]); length= a.length+b.length;
count++ ; c_name = new char[length+1];
if(q > 50) strcpy(c_name, a.c_name);
cout<<q<< “,” ; strcpy(c_name, b.c_name);
}} }
};
47 What will be the output of the following program void main( )
: {
# include<iostream.h> char *temp="India";
#include<ctype.h> clrscr( );
#include<conio.h> country c1=temp, c2("Nepal"),c3;
#include<string.h> c3.replace(c1,c2);
void NewText(char str[ ], int & pos) c3.display( );
{ getch( );
char * p = str; }
int length = strlen(p);
for( ; pos < length - 2; pos += 2 , p++) 53 Find the output of the following program
{ # include<iostream.h>
*(p + pos) = toupper(*(p+pos)); void main ( )
{
char *name;
node *next;
}
node n[ ]={
{“Anamika”, n+1},
{“Shruthi”,n+2},
{“Swathi”,n}
};
node * m[3];
for(int i=0;i<3;i++)
m[i]=n[i].next;
cout.write(m[0]->name,7); cout.put(‘\n’);
cout.write((*m)->name,7); cout.put(‘\n’);

What would be the output of the following? Assume


that the array starts at location 5714 in the memory?
# include<iostream.h>
void main()
{ int tab[3][4]={ 5,6,7,8,
1,2,3,4,
9,10,0,11};
cout<<”\n”<<*tab[0]<<” “<<*(tab[0]+1);
cout<<”\n”<<*(*(tab+0)+1);
}

S-ar putea să vă placă și