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=1;}
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 :"<<Date<<endl;
cout<<ID<<"#"<<Rate<<endl;
}
};
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();
}
Output:
Date :1
1024#150
Date :29
2015#400
Date :20
1001#180
Write the definition of a class METROPOLIS in C++ with the following description:
Private Members
-Mcode //Data member for Code (an integer)
-MName //Data member for Name (a string)
-MPop //Data member for Population (a long int)
-Area //Data member for Area Coverage (a float)
-PopDens //Data member for Population Density (a float)
CalDen()//A member function to calculate
//Density as PopDens/Area
Public Members
-Enter() //A function to allow user to enter values of
//Mcode,MName,MPop,Area and call CalDen()
//function
-ViewALL()//A function to display all the data members
//also display a message ”Highly Populated Area”
//if the Density is more than 12000
Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files are included:
class FICTION
{
long FCode;
char FTitle[20];
float FPrice;
public:
FICTION() //Member Function 1
{
cout<<"Bought"<<endl;
FCode=100;strcpy(FTitle,"Noname");FPrice=50;
}
FICTION(int C,char T[],float P) //Member Function 2
{
FCode=C;
strcpy(FTitle,T);
FPrice=P;
}
void Increase(float P) //Member Function 3
{
FPrice+=P;
}
void Show() //Member Function 4
{
cout<<FCode<<":"<<FTitle<<":"<<FPrice<<endl;
}
~FICTION() //Member Function 5
{
cout<<"Fiction removed!"<<end1;
}
};
void main() //Line 1
{ //Line 2
FICTION F1,F2(101,"Dare",75); //Line 3
for (int I=0;I<4;I++) //Line 4
{ //Line 5
F1.Increase(20);F2.Increase(15); //Line 6
F1.Show();F2.Show(); //Line 7
} //Line 8
} //Line 9
Which specific concept of object-oriented programming out of the following is illustrated by Member Function 1 and Member Function 2 combined together?
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>>Number;
Outcome=pow(A,Number);
cout<<Outcome<<endl;
}
Look at the following C++ code and find 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 CHANGER.
Note:
● Assume all the required header files are already being included in the code.
● The function random(n) generates an integer between 0 and n‐1.
void main()
{
randomize();
int CHANGER;
CHANGER=random(3);
char CITY[][25]={"DELHI","MUMBAI","KOLKATA","CHENNAI"};
for(int I=0;I<=CHANGER;I++)
{
for(int J=0;J<=I;J++){
cout<<CITY[J];
}
cout<<endl;
}
}
(i) | (ii) |
DELHI DELHIMUMABAI DELHIMUMABAIKOLKATA |
DELHI DELHIMUMABAI DELHIMUMABAIKOLKATA DELHIMUMABAIKOLKATACHENNAI |
(iii) | (iv) |
MUMABAI MUMABAIKOLKATA MUMABAIKOLKATACHENNAI |
KOLKATA KOLKATACHENNAI |
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, Number12, do
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 STRING[80];
void MIXITNOW(STRING S)
{
int Size=strlen(S);
for (int I=0;I<Size1;I+=2)
{
char WS=S[I];
S[I]=S[I+1];
S[I+1]=WS;
}
for (I=1;I<Size;I+=2){
if (S[I]>='M' && S[I]<='U'){
S[I]='@';
}
}
void main()
{
STRING Word='CRACKAJACK';
MIXITNOW(Word);
cout<<Word<<endl;
}
}
Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files are included:
class FICTION
{
long FCode;
char FTitle[20];
float FPrice;
public:
FICTION() //Member Function 1
{
cout<<"Bought"<<endl;
FCode=100;strcpy(FTitle,"Noname");FPrice=50;
}
FICTION(int C,char T[],float P) //Member Function 2
{
FCode=C;
strcpy(FTitle,T);
FPrice=P;
}
void Increase(float P) //Member Function 3
{
FPrice+=P;
}
void Show() //Member Function 4
{
cout<<FCode<<":"<<FTitle<<":"<<FPrice<<endl;
}
~FICTION() //Member Function 5
{
cout<<"Fiction removed!"<<end1;
}
};
void main() //Line 1
{ //Line 2
FICTION F1,F2(101,"Dare",75); //Line 3
for (int I=0;I<4;I++) //Line 4
{ //Line 5
F1.Increase(20);F2.Increase(15); //Line 6
F1.Show();F2.Show(); //Line 7
} //Line 8
} //Line 9
How many times the message "Fiction removed!" will be displayed after executing the above C++ code? Out of Line 1 to Line 9, which line is responsible to display the message "Fiction removed!"?
Differentiate between Constructor and Destructor functions giving suitable example using a class in C++. When does each of them execute?
Rewrite the following C++ code after removing any/all syntactical errors 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='<<C<<endl;
}