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
class METROPOLIS
{
int Mcode;
char MName[20];
long int MPop;
float Area;
float PopDens;
void CalDen();
public:
void Enter();
void ViewALL();
};
void METROPOLIS::Enter()
{
cin>>Mcode;
gets(MName); // OR cin>>MName;
cin>>MPop;
cin>>Area;
CalDen();
}
void METROPOLIS::ViewALL()
{
cout<<Mcode<<MName<<MPop<<Area<<PopDens;
if(PopDens>12000)
cout<<”Highly Populated Area”;
}
void METROPOLIS::CalDen()
{
PopDens= PopDens/Area;
}