MENU

Chapter 7 Pointers Solutions

Question - 1 : -
.Write the definition of a function FixPay (float Pay[ ], int N) in C+ + , which should modify each element of the array Pay having N elements, as per the following rules :

Existing Salary Value

Required Modification in Value

If less than 1,00,000

Add 25% in the existing value

If >=1,00,000 and <20,000

Add 20% in the existing value

If >=2,00,000

Add 15% in the existing value

Answer - 1 : -

Void FixPay(float Pay[],int N)
{
for(int i=0;i
{
if(Pay[i]<100000)
Pay[i]+= Pay[i]*0.25;
else if(Pay[i]<200000)
Pay[i]+= Pay[i]*0.20; 
else
Pay[i]+= Pay[i]*0.15 ;
 }
}

Question - 2 : -
Write the definition of a member function INSERT() for a class QUEUE in C+ +, to remove a product from a dynamically allocated Queue of items considering the following code is already written as a part of the program-

Struct ITEM 
{
int INO; char INAME[20];
ITEM*Link;
};
class QUEUE 
{
ITEM *R,*F;
Public:
QUEUE(){R=NULL; F=NULL;}
void INSERT();
void DELETE();
~QUEUE();
};

Answer - 2 : -

Void QUEUE::INSER()
{
ITEM*newitem = new ITEM; 
Cout<<"enter item number";
cin>>newitem → INO;
Cout<<"Enter item name";  
gets(newitem → INAME); 
newitem → Link = NULL; 
if (R==NULL)
R=F=newitem;
else
{
 R → Link=newitem; 
 R = newitem;
}

Question - 3 : -
Write the output from the following C+ + program code :-

#include
#include 
void strcon(char s[])
{
for(int i=0,l=0;s[i]!='\0';i++,l++); 
fortint j=0;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=c+3;
cout<<"New Text="<
c=c+5-2 ;
cout<<"last Text= "<
 }

Answer - 3 : -

Text = tMKCM@lMJGCR
New Text = KCM@1MJGCR
Last Text = 1MJGCR

Question - 4 : -
Obtain the output of the following C+ + program as expected to appear on the screen after its execution.
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[]={l,5,7,9}
P=Num;
cout <<*p<< Text <
Text++;
P++;
cout<<*P<
}

Answer - 4 : -

1AJANTA
5JANTA

Question - 5 : -
.Obtain the output from the following C+ + program as expected to appear on the screen after its execution.
Important Note :
• Adi the desired header files are already included in the code, which are required to run the code.

void main()
{
char *String="SARGAM"; 
int *Ptr, a[]={1,5,7,9}; 
ptr=a;
cout<<*ptr<
String++; 
ptr+=3;
cout<<*ptr<
}

Answer - 5 : -

1 SARGAM
9ARGAM

Question - 6 : -
.Give the output of the following program segment: (Assuming all desired header file(s) are already included)

void main()
{
float *Ptr, Points[] = {20,50,30,40,10};
Ptr = points; 
cout<<*Ptr<
Ptr+=2;
Points[2]+=2.5; 
cout<<*Ptr<
Ptr++;
(*Ptr)+=2.5; 
cout<
}

Answer - 6 : -

20.00 32.5
42.50

Question - 7 : -
Find the output of the following code :-
Important Note :
All the header files are already included in the code, which are required to run the code.

void main()
{
char *String="SHAKTI";
int*Point,Value[]={10,15,70,19};
Point=Value;
cout<<*Point<
String++;
Point++;
cout<<*Point<
}

Answer - 7 : -

10SHAKTI
15HAKTI

Question - 8 : -
Write the output of the following C+ + program code :-
Note : Assume all required header files are already being included in the program.

void change(int*s)
{
for(int i=0;i<4;i++)
{
if(*s<40)
{
if(*s%2==0)
*s=*s+10; 
else
*s=*s+ll; 
}
else
 {
if(*s%2==0)
*S=*S-10; 
else
*s=*s-ll;
}
cout<<*s<<" ";
s++;
}
}
void main()
{
int score[]={25,60,35,53 }; 
change(score);
}

Answer - 8 : -

36 50 46 42

Question - 9 : -
Find the output of the following program :-

#include
void in(int x,int y,int &z)
{
x+=y; 
y--;
z*=(x-y);
}
void out(int z,int y,int &x)
{
x*=y;
y++;
z/=(x+y);
}
void main()
{
int a=20, b=30, c=10;
out(a,c,b);
cout<
in(b,c, a) ;
cout<
out(a,b,c);
cout<
}

Answer - 9 : -

20#300#10#
620@300@10@
620$300$3000$

Question - 10 : -
Find the output of the following code:-

#include 
void main()
{
int *Striker;
int Track[]={10,25,30,55}; 
Striker=Track; 
Track[1]+=30;
cout<<"Striker"<<*Striker<
*Striker=-10;
Striker++;
cout<<"Next@"<<*Striker<
Striker+=2;
×