1.

Consider the following class State :class State{protected :int tp;public :State( ) { tp=0;}void inctp( ) { tp++;};int gettp();{ return tp;}};Write a code in C++ to publically derive another class ‘District’ with the following additional members derived in the public visibility mode.Data Members :Dname stringDistancefloatPopulation long intMember functions :DINPUT( ) : To enter Dname, Distance and population DOUTPUT( ) : To display the data members on the screen.

Answer»

class District : public State

{

public :

char Dname[20];

float Distance;

long int Population;

void DINPUT( )

{

gets(Dname);

cin>>distance;

cin>>Population;

}

void DOUTPUT( )

{

cout<<Dname<<endl;

cout<<Distance<<endl;

cout<<population<<endl;

}

};



Discussion

No Comment Found

Related InterviewSolutions