Write the definition of a class METROPOLIS in C++ with following descriptions:

Private Members:
-MCode // Code in Integer
-MName // Name in String
-MPop // Population in Long
-Area // Area coverage in Float
-PopDens // Population Density in Float
-CalDen() // Function to calculate Density as MPop/Area

Public Members:
-Enter() // Function to enter values of MCode, MName, MPop, Area
// and call Function CalDen
-ViewAll() // Function to display all the data members also display 
// message Highly Populated Area if the density is more than 12000
===============================================
Solution:
===============================================

class METROPOLIS
{
int MCode;
char MName[20];
long MPop;
float Area;
float PopDens;
void CalDen()
{
PopDens=MPop/Area;
}

public:
void Enter()
{
cout<<"Enter City Code       : ";
cin>>MCode;
cout<<"Enter City Name       : ";
cin>>MName;
cout<<"Enter City Population : ";
cin>>MPop;
cout<<"Enter Area of City    : ";
cin>>Area;
CalDen();
}
void ViewAll()
{
cout<<"..........METROPOLIS CITY DETAILS..........\n";
cout<<"City Code       : "<<MCode<<endl;
cout<<"City Name       : "<<MName<<endl;
cout<<"City Population : "<<MPop<<endl;
cout<<"Area of City    : "<<Area<<endl;
cout<<"Density of City : "<<PopDens<<endl;
if(PopDens>12000)
cout<<"Highly Populated Area City"<<endl;
}
};



No comments

Post your comments

Powered by Blogger.