MENU

Chapter 1 C plus plus Revision Tour Solutions

Question - 21 : -
Ronica Jose has started learning C++ and has typed the following program. When she compiled the
following code written by her, she discovered that she needs to include some header files to successfully
compile and execute it. Write the names of those header files, which are required to be included in the code.

void main()
{
double X,Times,Result; 
cin>>X>>Times;
Result=pow(X,Times) 
cout<
}

Answer - 21 : -

for cout and cin
for pow()

Question - 22 : -
Rewrite the following C+ + code after removing any/all syntactical error with each correction underlined.
Note : Assume all required header files are already being included in the program.

#define Formula(a,b)= 2*a+b
void main()
{
float x=3.2; Y=4.1;
Z=Formula(X,Y);
cout<<'Result='<
}

Answer - 22 : -

# define Formula(a.b)2*a+b 
void main()
{
float X=3.2, y=4.1;
float Z = Formula(X,Y);
cout<<"Result="<
}

Question - 23 : -
Find and write the output of the following C+ + program code :
Note ; Assume all required header files are already included in the program.

typedef char TexT[80]; 
void JumbleUp(TexT T)
{
int L=strlen(T);
for(int C=0;C
{
char CT=T[C];
T[C] = T[C+l];
T[C+l]=CT;
}
for(C=l;C
if(T[C]>='M'&& T[C]<='U')
T[C] = '@';
void main()
{
TEXT Str = "HARMONIOUS"; 
JumbleUp(Str); 
cout<
}

Answer - 23 : -

AHM@N@OIS@

Question - 24 : -
Out of the following, find those identifiers, which cannot be used for naming Variable, Constants or Functions in a C + + program : _Cost, Price*Qty, float, Switch, Address one, Delete, Numberl2, do

Answer - 24 : -

Price* Qty, float, Address one, do

Question - 25 : -
Jayapriya has started learning C+ + and has typed the following program. When she compiled the following code written by her, she discovered that she needs to include some header files to successfully compile and execute it. Write the names of those header files, which are required to be included in the code.

void main()
{
float A, Number, Outcome; 
cin>>A>>Numbers;
Outcome = pow(A, Number); 
cout<
}
 

Answer - 25 : -

for cout and cin
for Pow()

Question - 26 : -
Rewrite the following C+ + code after removing any/all syntactical error with each correction underlined.
Note : Assume all required header files are already being included in the program.

#define Equation(p,q)=p+2*q 
void main()
{
float A=3.2;B=4.1;
C=Equation (A,B);
cout<<’Output='<
}

Answer - 26 : -

#define Equation(p,q)g+2*q 
void main()  
float A=3.2,B=4.1; 
float C=Equation(A,B);
Cout<<"Output"<
}

Question - 27 : -
Find and write the output of the following C++ program code:
Note : Assume all required header files are included in the program,

typedef char STRING[80]; 
void MIXITNOW(STRING S)
{
int Size=strlen(S); 
for(int 1=0;I
{
char WS=S[I];
S[I]=S[I+1];
S[1+1]=WS;
}
for(1=1;I
If(S[I]>='M1&&S[I]<='U')
S[I]=;
void main()
{
STRING Word = "CRACKAJACK"; 
MIXITNOW(Word); 
cout<
}

Answer - 27 : -

RCCAAKAJKC.

Question - 28 : -
Find and write the output of the following C+ + program code :
Note : Assume all required header files are already being included in the program.

class stock 
{
long int ID; 
float Rate; 
int Date;  
public:
Stock()
{ID=1001;Rate=200;Date=l;} 
void RegCode(long int I, float R)
{
ID=I;
Rate=R;
}
void Change(int New, int DT)
Rate+=New;
Date=DT;
}
void Show()
{
cout<<"Date:"<
cout<
}
};
void main()
{
stock A,B,C;
A.RegCode(1024,150);
B.RegCode(2015,300);
B.Change(100,29);
C.Change(-20,20);
A.Show();
B.show();
C.Show();
}

Answer - 28 : -

Date:1
1024 # 150
Date : 29
2015 # 400
Date : 20
1001 # 180

Question - 29 : -
Out of the following, find those identifiers, which can not be used for naming Variable,
Constants or Functions in a C + + program :
Days*Rent, For, A+Price, Grand Total
double, 2Members, . Participantl, MyCity

Answer - 29 : -

Days * Rent
For
Grand Total
double

Question - 30 : -
Rewrite the following program after removing the syntactical erros (if any). Underline each correction.

#include 
#include 
#include
#include
Class product
{
int product_code,qty,price; 
char name[20]; 
public:product()
{
product_code=0;qty=0;price=0; 
name=NULL;
}
void entry()
{
cout<<"\n Enter code,qty(price"; 
cin>>product_code>>qty>>price; 
gets(name);
}
void tot_price(){return qty*price;}
}
void main()
{
p product; 
p.entry(); 
cot<
}

Answer - 30 : -

#include
#include
#include 
class product 
{
int product_code,qty,price; 
char name[20]; 
public; 
product()
{
product_code=0;qty=0;price=0; 
strcpy(name.NULL);
void entry()
{
cout<<"\n Enter code, qty, price"; 
cin>>product_code>>qty>>price; 
gets(name);
}
int tot_price(){return qty*price;}
};
void main()
{
product p; 
p.entry(); 
×