Output questions

(1) Find the output of the following program:3

#include <iostream.h>

void Changethecontent(int Arr[], int Count)

{

for (int C=1;C<Count;C++)

Arr[C-1]+=Arr[C];

}

void main()

{

int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};

Changethecontent(A,3);

Changethecontent(B,4);

Changethecontent(C,2);

for (int L=0;L<3;L++) cout<A[L]<’#’;

cout<endl;

for (L=0;L<4;L++) cout<B[L] <’#’;

cout<endl;

for (L=0;L<2;L++) cout<C[L] <’#’;

}

(2) Predict the output of the following code: 2

#include<iostream.h>

struct package

{

int length, breadth, height;

};

void occupies(package m )

{

cout<m.length<”x” <m.breadth<”x”<m.height<endl;

}

void main()

{

package p1={100, 150,50}, p2,p3;

++p1.length;

occupies(p1);

p3=p1;

++p3.breadth;

p3.breadth++;

occupies(p3);

p2=p3;

p2.breadth+=50;

p2.height--;

occupies(p2);

}

(3) In the following program, if the value of N given by the user is 15, what maximum and minimum values the program could possibly display? 2

#include <iostream.h>

#include <stdlib.h>

void main()

{

int N,Guessme;

randomize();

cin>N;

Guessme=random(N)+10;

cout<Guessme<endl;

}

(4) Find the output of the following program (3)

#include<iostream.h>

#include<ctype.h>

void main()

{ char text[]=Mind@Work!;

for(int i = 0;text[i]!=’\0’;i++)

{

if(!isalpha(text[I]))

text[I] = ‘*’

else if(isupper(text[I]))

text[I] = text[I] + 1;

else

text[I] = text[I+1];

}

cout<text; }

(5) Find the output of the following program (2)

#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;

} }

(6) In the follwing program,find the correct possible output(s)

from the options: (2)

#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;

(7) Go through the C++ Code shown below & find the possible output from the suggested output options (i) to (iv). 2

#include<iostream.h>

#include<stdlib.h>

const int LOW = 25;

void main( )

{

randomize( );

int num, point = 5;

for(int i = 1; i<= 4; i++)

{

num = LOW + random(point);

cout<num<”:” ;

point- - ;

}

}

i)29 : 26 : 25 : 28: ii) 24 : 28 : 25 : 26 iii) 29 : 26 : 24 : 28 iv) 29 : 26 : 25 : 26 :

(8) Find the output of the following program: 2

#include<iostream.h>

void switch(int a[ ], int n, int split)

{

for(int k = 0; k < n; k++)

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};

switch(h, 6, 3);

display(h, 6);

}

(9) Find the output of the following program: 3

#include<iostream.h>

struct Package

{

int L, b, h;

};

void occupy(Package M)

{

Cout<M.L<”x”<M.b<”x”<M.h<endl;

}

void main( )

{

Package B1 = { 300, 200, 100}, B2, B3;

++B1.L;

occupy(B1);

B3 = B1;

--B3.b;

B3.b++;

occupy(B3);

B2 = B3;

B2.b += 50;

B2.h++-;

occupy(B2);

}

(10) In the following program, if the value of G entered by the user is 65, whatwill be the expected output(s) from the following options (i), (ii), (iii) and (iv)? 2

#include <iostream.h>

#include <stdlib.h>

void main()

{

int G, N ;

randomize();

cin>G;

for (int I=1;I<=4;I++)

{

N = G + random( I );

cout< ( char ) N ;

}

}

(i) ABBC(ii) ACBA(iii) BCDA(iv) CABD

(11)Find the output of the following code2

#include <iostream.h>

void Secret(char Str[ ])

{

for (int L=0;Str[L]!='\0';L++);

for (int C=0;C<L/2;C++)

if (Str[C]=='A' || Str[C]=='E')

Str[C]='#';

else

{

char Temp=Str[C];

Str[C]=Str[L-C-1];

Str[L-C-1]=Temp;

}

}

void main()

{

char Message[ ]="ArabSagar";

Secret(Message);

cout<Message<endl;

}

(12) Find the output of the following program[2]

# include <iostream.h>

void main( )

{ int a=5, b=10;

cout<b++ – + +a<endl;

cout<– – a + b – – <endl;

}

(13) Find the output of the following program[3]

# include <iostream.h>

void main( )

{ char *TXT="Good Night!";

int Num[ ]={1,2,3,4,5};

int *P=Num; TXT+=10;

while(*P<5)

{cout<*P<"#"<TXT<endl;

P++; TXT – –;

}

}

(14) Find the output(s) which will not be expected on execution of the following program[2]

# include <iostream.h>

# include <stdlib.h>

void main( )

{ int A[ ]={10,20}, RN;

randomize( );

for(int X=0; X<2; X++)

{RN=random(X+1)+10;

cout<A[X]+RN<"@";

}}

(i)10@20@

(ii)20@30@

(iii)21@31@

(iv)20@31@

(15) Find the output of the following program (imagine header files are included) 2

void main()

{

clrscr();

char *NAME = "@KVid5yaLaY*a";

for (int x = 0; x < strlen(NAME); x++)

if (islower(NAME[x]))

NAME[x] = toupper(NAME[x]);

else

if (isupper(NAME[x]))

if (x%2==0)

NAME[x] = tolower(NAME[x]);

else

NAME[x] = NAME[x-1];

puts(NAME);

getch();

}

(16) Give the output of the following program3

#include<iostream.h>

#include<conio.h>

void Execute(int &B, int C = 50)

{

int TEMP = B+C;

B += TEMP;

if(C != 150)

cout < " "<TEMP<" " <" "< B <" "< C < endl;

}

void main ( )

{

clrscr();

int M = 20, N = 10;

Execute(M);

cout <" "< M< " "<" "< N < endl;

Execute(M, N);

cout <" "<M <" "< N < endl;

getch();

}

(17)Find the possible out put(s) & What will be the minimum & Maximum values2

#include<stdlib.h>

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

randomize();

int N, numgus;

N=10;

numgus=random(N)+10;

cout<numgus<endl;

getch();

}

18. / Write the output of the following C++ program code:
NOTE: Assume all required header files are being included in the program.
void Position(int &C1, int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
Court<P1<”,”<P2<endl;
Position(P2,P1);
Cout<P1<”,”<P2<endl;
}
19. / Write the output of the following C++ program code:
NOTE: Assume all required header files are already being included in the program.
Class Calc
{
char Grade;
int Bonus;
public:
Clac() {Grade=’E’; Bonus=0;}
void Down(int G)
{
Grade-=G;
}
void Up(int G)
{
Grade+=G;
Bonus++;
}
void Show()
{
cout<Grade<”#”<Bonus<endl;
}
};
void main()
{
Clac c;
C.Down(2);
C.Show();
C.Up(7);
C.Show();
C.Down(2);
C.Show();
}
20. / Study the following program and select the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable NUM.
NOTE:
-Assume all required header files are already being included in the program.
- random(n) function generates an integer between 0 and n-1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
Char TEXT[]=”ABCDEFGHIJK”;
for(int I=1;I<=NUM;I++)
{
for(int J=NUM;J<=7;J++)
cout<TEXT[J];
cout<endl;
}
}
(i)FGHI (ii)BCDEFGH (iii)EFGH (iv)CDEFGH
FGHI BCDEFGH EFGH CDEFGH
FGHI EFGH
FGHI EFGH
21) / Find the output of the following program:
#include<iostream.h>
Void Chargethecontent(int Arr[], int count)
{
For (int c=1;c<count;c++)
Arr[c-1]+=Arr[c];
}
Void main()
{
Int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};
Chargethecontent(A,3);
Chargethecontent(B,4);
Chargethecontent(C,2);
For(int l=0;l<3;l++) cout<A[l]<’#’;
Cout<endl;
For(int l=0;l<4;l++) cout<’#’;
Cout<endl;
For(int l=0;l<2;l++) cout<C[l]<’#’;
}
22) / Find the output of the following program:
#include<iostream.h>
struct Game
{
Char magic[20]; int Score;
};
Void main()
{
Game M={“Tiger”,500};
Char *Choice;
Choice=M.Magic;
Choice[4]=’P’;
Choice[2]=’L’;
M.Score+=50;
Cout<M.Magic<M.Score<endl;
Game N=M;
N.Magic[0]=’A’; N,Magic[3]=’J’;
N.Score=120;
Cout<N.Magic<N.Score<endl;
}
(23) Observe the following C++ code carefully and write output. (2)
#include<iostream.h>
#include<string.h>
int main()
{
char *STR="AeroDynamics";
int A=1;
STR+=3;
while(A<9)
{
cout<*STR<strlen(STR)<"\n";
STR++;
A=A+2;
}
return 0;
}
(24) Write output for the following program. (3)
#include<iostream.h>
#include<conio.h>
struct ITEM
{
Int ICode,Qty;
};
void assigndetail( ITEM & I, int Q=5)
{
I.ICode++;
I.Qty*=Q;
}
void main()
{
clrscr();
ITEM T={200,25};
assigndetail(T,10);
cout<T.ICode<":"<T.Qty<"\n";
assigndetail(T);
cout<T.ICode<":"<T.Qty<"\n";
assigndetail(T,6);
cout<T.ICode<":"<T.Qty<"\n";
getch();
}
(25) Study the following program carefully and select the option which is NOT a possible output. (2)
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
const int VALUE=15;
int main()
{
clrscr();
int INCR=5;
randomize();
for(int i=1;i<5;i++)
{
int bid=VALUE+random(INCR);
cout<bid<":";
INCR+=2;
}
getch();
return 0;
}
(i)16:19:22:25:
(ii)19:16:15:24:
(iii)15:18:20:16:
(iv)18:22:23:19:
(26) / Find the output of the following program:
#include <iostream.h>
struct Game
{
char Magic[20];int Score;
};
void main()
{
Game M={“Tiger”,500};
char *Choice;
Choice=M.Magic;
Choice[4]=’P’;
Choice[2]=’L’;
M.Score+=50;
cout<M.Magic<M.Score<endl;
Game N=M;
N.Magic[0]=’A’;N.Magic[3]=’J’;
N.Score-=120;
cout<N.Magic<N.Score<endl;
}
(27) / Find the output of the following program:
#include <iostream.h>
void main()
{
long NUM = 98534210;
int f=0,s=0;
do
{
int rem = NUM % 10;
if( rem % 2 == 0)
f += rem;
else
s += rem;
NUM /= 10;
}while(NUM > 0);
cout<“\n”<f<” – “<s<“ = ”<f – s;
}
(28) / In the following program, if the value of N given by the user is 20, what maximum and minimum values the program could possibly display?
#include <iostream.h>
#include <stdlib.h>
void main()
{
int N,Guessnum;
randomize();
cin>N;
Guessnum= random(N – 10)+10;
cout<Guessnum<endl;
}
(29)Find the output of the following program:[3]#include <iostream.h>
struct PLAY
{
int Score, Bonus;
};
void Calculate(PLAY &P, int N=10)
{
P.Score++;
P.Bonus+=N;
}
void main( )
{
PLAY PL={10,15};
Calculate(PL,5);
cout<PL.Score<”:”<PL.Bonus<endl;
Calculate(PL);
cout<PL.Score<”:”<PL.Bonus<endl;
Calculate(PL,15);
cout<PL.Score<”:”<PL.Bonus<endl;
}
(30) In the following program, what will be the output? Justify.[2]
#include <stdlib.h>
#include <iostream.h>
void main()
{randomize();
int score [ ] = {25, 20, 34, 56, 72, 63}, myscore;
myscore = score[2 + random(2)];
cout < myscore <endl;
}
i) 25ii) 56iii) 20iv) None of these
(31) Find the output of the following program. [2]
#include<iostream.h>
void main( )
{
int *Q, M[]={11, 22, 33, 44};
Q=M;
M[2] += 22;
cout<” Queen @ “<*Q <endl;
*Q - = 11;
Q += 2;
cout<” Now @”< *Q <endl;
Q++;
cout<”Finally @”< *Q <endl;
cout<”New Value @”<M[0] <endl;
}
. (32) Find the output of the following program: 3
#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;
}
(33) Find the output of following program:2
#include<iostream.h>
void main()
{
int A=5,B=10;
for(int I=1;I<=2;I++)
{
cout<”Line1=”<A++<”&”<B-2<endl;
cout<”Line2=”<++B<”&”<A+3<endl;
}
}
(34) In the following program, find the correct possible output(s) from the options: 3
#include<iostream.h>
#include<stdlib.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]<”:”;
}
}
(35) Find the output of the following program: 3
#include <iostream.h>
void Changethecontent(int Arr[], int Count)
{ for (int C=1;C<Count;C++)
Arr[C-1]+=Arr[C];
}
void main()
{
int A[]={3,4,5},B[]={10,20,30,40},C[]={900,1200};
Changethecontent(A,3);
Changethecontent(B,4);
Changethecontent(C,2);
for (int L=0;L<3;L++) cout<A[L]<’#’;
cout<endl;
for (L=0;L<4;L++) cout<B[L] <’#’;
cout<endl;
for (L=0;L<2;L++) cout<C[L] <’#’;
}
36. Write the output from the following C++ program code: [2]
#include<iostream.h>
#include<ctype.h>
void strcon(char s[])
{
for(int i=0,l=0;s[i]!='\0';i++,l++);
for(int j=0; j<l; j++)
{
if (isupper(s[j]))
s[j]=tolower(s[j])+2;
else if ( islower(s[j]))
s[j]=toupper(s[j])-2;
else
s[j]='@';
}
}
void main()
{
char *c="Romeo Joliet";
strcon(c);
cout<"Text= "<c<endl;
c=c+3;
cout<"New Text= "<c<endl;
c=c+5-2;
cout<"last Text= "<c
}
37. Find the output of the following C++ program: [3]
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
class Class
{
int Cno,total;
char section;
public:
Class(int no=1)
{
Cno=no;
section='A';
total=30;
}
void addmission(int c=20)
{
section++;
total+=c;
}
void ClassShow()
{
cout<Cno<":"<section<":"<total<endl;
}
} ;
void main()
{
Class C1(5),C2;
C1.addmission(25);
C1.ClassShow();
C2.addmission();
C1.addmission(30);
C2.ClassShow();
C1.ClassShow();
}
38. Study the following C++ program and select the possible output(s) from it :Find the maximum and minimum value of L. [2]
#include<stdlib.h>
#include<iostream.h>
#include<string.h>
void main()
{
randomize();
char P[]="C++PROGRAM";
long L;
for(int I=0;P[I]!='R';I++)
{
L=random (sizeof(L)) +5;
cout<P[L]<"-";
}
}
i) R-P-O-R- ii) P-O-R-+ - iii) O-R-A-G- iv) A-G-R-M-Q2.