MENU
Question -

Write the definition of a class METROPOLIS in C+ + with 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)
┬а-┬а ┬а CaldenO┬а ┬а //A member function
┬аto calculate.........
┬а//Density as PopDens/Area
Public Members
┬а-┬а ┬а Ender ()┬а ┬а //A function to
┬аallow┬а ┬а user to┬а enter values┬а of
┬а//MCode, MName, MPop, Area and call claDen () //function
┬а-┬а ┬а viewall┬а ┬а //A function┬а ┬а to
┬аdisplay all the data members┬а
//also display a message "Highly Populated Area"┬а
//if the Density is more than 12000



Answer -

class METROPOLIS
┬а{
┬аint MCode;┬а
char MName[2 0] ;┬а
long int MPop;┬а
float Area;┬а
float PopDens;┬а
void CalDen()┬а
public:
┬аVoid Enter();┬а
void veiw ALL();
┬а} ;
┬аvoid METROPOLIS::Enter()
┬а{
┬аcin>>Mcode;┬а
gets(MName);
┬аCin>>Mpop;
┬аCin>>Area;
┬аCalDen();
┬а}
┬аvoid METROPOLIS::viewALL ( )
┬а{
┬аcout <
┬аif (Pop Dens > 12000) cont<<"Highly Populated Area";
┬а}
┬аvoid METROPOLIS::call Den()
┬а{
┬аPopDens =Mpop/Area
┬а}┬а ┬а┬а

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×