Find The Output PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

FIND THE OUTPUT OF THE FOLLOWING PROGRAM

EACH QUESTION CARRY 2 OR 3 MARKS

Remember to show steps and at the end write “final output of the program will be ……”

1. Find the output of the following program:


#include<iostream.h>
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{ int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}

Ans: - 2

2. Find the output of the following program: (3)


#include<iostrem.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;
}
Ans: Nnd@*Xrk!*

3. Give the output of the following program 2


#include<iostream.h>
int global = 10;
void func(int &x, int y)
{
x = x-y; y = x * 10;
cout<< x <<' , ' << y << "\n";
}
void main()
{
int global = 7;
func(:: global, global);
cout<<global<<' , '<<::global<<"\n";
func(global, ::global);
cout<<global<<' , '<<::global<<"\n";
}
Ans:
3, 30
7, 3
4, 40
4, 3
5. Find the output of the following program: 3
#include <iostream.h>
struct GAME
{ int Score, Bonus;};
void Play(GAME &g, int N=10)
{
g.Score++;g.Bonus+=N;
}
void main()
{
GAME G={110,50};
Play(G,10);
cout<<G.Score<<":"<<G.Bonus<<endl;
Play(G);
cout<<G.Score<<":"<<G.Bonus<<endl;
Play(G,15);
cout<<G.Score<<":"<<G.Bonus<<endl;
}
Ans:

111:60
112:70
113:85
(1 Mark for each correct line of output)

6. Find the outpu t of the following program. 2


# include<iostream.h>
# include<ctype.h>
#include<string.h>
void string_func (char* str)
{
int i, j, len=strlen (str);
for (i =0; i< len; i++)
{
for( j=0;j<=i; j++)
cout<<str[i];
cout<<endl;
}
}
void main ( )
{
string_func(“CALIFORNIA”);
}

Ans:
C
AA
LLL
IIII
FFFFF
OOOOOO
RRRRRRR
NNNNNNNN
IIIIIIIII
AAAAAAAAAA

7. Find the output of the following program: (3)


#include<iostream.h>
void ChangetheContent(int Arr[], int Count)
{
for(int C=0; C<Count; C++)
Arr[C]= Arr[Count – C- 1];
}
void main()
{
int A[]= {1, 2, 3}, B[] = {20, 30, 40, 50}, C[]= {100, 200};
ChangetheContent(A,3);
ChangetheContent(B,4);
ChangetheContent(C,2);
for(int L=0; L<3; L++) cout<<A[L]<<’#’;
cout<<endl;
for(int L=0; L<4; L++) cout<<B[L]<<’#’;
cout<<endl;
for(int L=0; L<2; L++) cout<<C[L]<<’#’;
cout<<endl;
}
Ans:
3#2#3#
50#40#40#50#
200#200#

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


#include<iostream.h>
void main ( )
{
int *Queen, Moves [ ] = {11, 22, 33, 44};
Queen = Moves;
Moves [2] + = 22;
Cout<< "Queen @"<<*Queen<<end1;
*Queen - = 11;
Queen + = 2;
cout<< "Now @"<<*Queen<<end1;
Queen++;
cout<< "Finally@"<<*Queen«end1;
cout<< "New Origin @"<<Moves[0]<<end1;
}
Ans
Queen @11
Now @55
Finally @44
New origin @0

9)Give the output of the following program (Assuming that all required header files are
included in the program) (2)
void main()
{
char a[]= “Exam-2011 AheAd”;
int i;
for(i=0; a[i]!= ‘\0’;i++)
{
if(a[i]>= 97 && a[i]<=122)
a[i] --;
else
if(a[i]>= ‘0’ && a[i]<= ‘9’)
a[i] = a[i -1];
else
if(a[i]>= ‘A’ && a[i]<= ‘Z’)
a[i]+ = 32;
else
a[i]= ‘#’;
}
puts(a);
}
Ans
ew`l######agdac
10. Find the output of the following program: 2
#include <iostream.h>
#include <ctype.h>
void Encrypt(char T[])
{
for (int i=0;T[i]!='\0';i+=2)
if (T[i]=='A' || T[i]=='E') T[i]='#';
else if (islower(T[i])) T[i]=toupper(T[i]);
else T[i]='@';
}
void main()
{
char Text[]="SaVE EArtH";//The two words in the string Text
//are separated by single space
Encrypt(Text);
cout<<Text<<endl;
}

Ans:

@a@E@E#rTH

(1 Mark for writing all alphabets at correct positions)


(1/2 Mark for writing @ at correct positions)
(1/2 Mark for writing # at correct position)

11.Find the output of the following program: 2


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

Ans:

TiLeP550
AiLJP430

(1 Mark for each line of output)

12) Find the output of the following program: 3


#include <iostream.h>
struct THREE_D
{int X,Y,Z;};
void MoveIn(THREE_D &T, int Step=l)
}
T.X+=Step;
T.Y-=Step;
T.Z+=Step;
}
void MoveOut(THREE_D &T, int Step=l)
{
T.X-=Step;
T.Y+=Step;
T.Z-=Step;
}
void main ()
{
THREE_D Tl={lO,20,5},T2={30,lO,40};
MoveIn(T1);
MoveOut(T2,5) ;
cout<<Tl.X<<“,”<<Tl.Y<<“,”<<T1.Z<<endl;
cout<<T2.X<<“,”<<T2.Y<<“,”<<T2.Z<<endl;
MoveIn(T2,l0);
cout<<T2.X<<“,”<<T2.y<<“,”<<T2.Z<<endl;
}

Ans.

11, 19, 6
25, 15, 35
35, 5, 45

13.Find the output of the following program: (3)


#include<iostream.h>
#include<string.h>
class student
{ char *name;
int l ;
public:
student( ) {l=0; name=new char [1+1]; }
student (char *s)
{ I =strlen(s); name=new char[I+1];
strcpy (name,s);
}
void display( ) {cout<<name<<endl;}
void manipulate(student & a, student & b)
{ I = a. I + b.I;
delete name;
name=new char[I+1];
strcpy(name, a.name);
strcat(name, b.name);
}
};
void main( )
{ char * temp = “Jack”;
student name1 (temp), name2(” Jill”), name3(”John”),S1,S2;
S1 .manipulate (name1, name2);
S2.manipulate (S1, name3);
S1.display ( );
S2.display ( );
}

Ans:

Jack Jill
Jack JillJohn

14. Give the output of the following program segment (Assuming all required header
files are included in the program): 3
# include<iostream.h>
# include<ctype.h>
void change (char* state, int &s)
{ int b = s;
for (int x = 0; s>=0; x++, s−−)
if ((x+s)%2)
*(state+x) = toupper(*(state+b-x));
}
void main ( )
{
char s[ ] = “Punjab”;
int b = strlen (s)−1;
change (s, b);
cout<<s<<”#”<<b;}

Ans:
BAJJAB#-1

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


#include < iostream.h>
void main( )
{ int *PointerArray [10];
int marks [ ]= {75, 68, 90, 34, 0, 10, 90, 65};
for (int I = 0; marks [ I]!=0; I++)
{ PointerArray [I]=&marks[I];
* (PointerArray [I] ) += 5;
}
int index = 0;
while(index < I )
{ int p=*(PointerArray[index] );
if(p >=60) cout <<p<<’,’;
index ++;
}
}

Ans:

80, 73, 95,

16) Find the output of the following program : 2


# include < iostream.h>
void main ()
{
Int Array[] = {4,6,10,12};
int *pointer = Array ;
for (int I=1 ; I<=3 ; I++)
{
cout<<*pointer<<”#”;
pointer ++;
}
cout<<endl;
for (I=1 ; I<=4 ; I++)
{
(*pointer)*=3 ;
-- pointer;
}
for(I=1; I<5; I + + )
cout << Array [I-1] << “@”;
cout << endl;
}
Ans:

4#6#10#
12@18@30@36@
17) Find the output of the following program : 3
# 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;
}
Ans:
20 25 30
20 25 30
Number=30

18) Find the output of the following program: 3


#include<iostream.h>
void ChangeArray(int Number, int ARR[ ], int Size)
{
for (int L =0; L<Size; L++)
if (L<Number)
ARR [L] +=L;
e1se
ARR [L] *=L;
}
void Show (int ARR [ ], int Size)
{
for (int L=0; L<Size; L++)
(L%2!=0) ?cout<<ARR[L] <<"#": cout<<ARR[L]<<end1 ;
}
void main ( )
{
int Array [ ] = {30, 20, 40, 10, 60, 50};
ChangeArray (3, Array, 6) ;
Show (Array, 6) ;
}
Ans:
30
21#42
30#240
250#

19) Obtain the output from the following C++ program as expected to appear on the screen
after its execution. 2
Important Note :
- All the desired header files are already included in the code,
which are required to run the code.
void main()
{
char *Text=”AJANTA”;
int *P, Num[]={1,5,7,9};
P=Num;
cout<<*P<<Text<<endl;
Text++;
P++;
cout<<*P<<Text<<endl;
}

Ans:
1AJANTA
5JANTA

20) Find the output of the following program:


#include<iostream.h> (3)
void main ( )
{int N [ ] = { 10 , 15 , 20 , 25 , 30}
int *z = N;
while (*z<30)
{
if(*z % 3 !=0 )
*z = *z + 2;
else
*z = *z + 1;
z++;
}
for (int R = 0 ; R <=4 ; R++ )
130
{ cout<<N[R]<<”$“;
If (R % 3 = = 0)
cout<<endl;
}
cout<<N[4] * 3 <<endl;
}
Ans:
12$
16$22$27$
30$90

21. Find the output of the following program: (2)


#include<iostream.h>
void repch(char s[])
{
for (int i=0;s[i]!='\0';i++)
{
if(((i%2)!=0) &&(s[i]!=s[i+1]))
{
s[i]='@';
cout<<"Hello";
}
else if (s[i]==s[i+1])
{
s[i+1]='!';
i++;
}
}
}
void main()
{
char str[]="SUCCESS";
cout<<”Original String”<<str
repch(str);
cout<<"Changed String"<<str;
}
Ans:
Original StringSUCCESSHello Changed StringS@C!ES!
22. Give the output of the following program (3)
Note: Assume all required header files are already being included in the program.
class Eval
{
char Level;
int Point;
public:
Eval() {Level='E'; Point=0;}
void Sink(int L)
{
Level -=L;
}
void Float(int L)
{
Level += L;
Point++;
}
void Show()
{
cout<<Level<<"#"<<Point<<endl;
}

void main()
{
Eval E;
E.Sink(3);
E.Show();
E.Float(7);
E.Show();
E.Sink(2);
E.Show();
}
Ans:

B#0
I#1
G#1
23) #include<iostream.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
void PointersFun(char Text[], int &count)
{
char *ptr=Text;
int length=strlen(Text);
for(; count<length-2; count+=2, ptr++)
{
*(ptr + count) = toupper( * (ptr + count) );
}
}
void main()
{
clrscr();
int position=0;
char Data[]= “ChangeString”;
PointersFun(Data, position);
cout<<Data<< “@”<< position;
cout.write(Data + 3, 4);
}
Ans:

ChaNgeStrIng@10
24)

Ans:

New Encrypted Message after Pass 1 is : Dpnqvufs3128


New Encrypted Message after Pass 2 is : Eqorwvgt4239

25)

Ans:

B:380
A:350
C:275

You might also like