-->

Classes And Objects

Question
CBSEENCO12011568

Write the definition of a class BOX in C++ with following description:

Private Members

- BoxNumber    // data member of integer type
- Side         // data member of float type
- Area         // data member of float type
- ExecArea()   // Member function to calculate and assign
               // Area as Side * Side

Public Members

- GetBox()     // A function to allow user to enter values of
               // BoxNumber and Side. Also, this
               // function should call ExecArea() to calculate
               // Area
- ShowBox()    // A function
               // and Area

Solution

The definition of a class Box in C++ given,

class BOX
{
	int BoxNumber;
	float Side;
	float Area;
	void ExecArea(){ Area=Side*Side;}
public:
	void GetBox();
	void ShowBox();
};
void BOX::GetBox()
{
	cin>>BoxNumber>>Side;
	ExecArea();
}
void BOX::ShowBox()
{
	cout<<BoxNumber<<' '<<Side<<' '<<Area<<endl;
}

Some More Questions From Classes and Objects Chapter