English

Write the Definition of a Class Box 1n C++ with the Following Description Private Members Boxnumber Side Area Execarea Public Members Getbox() Showbox () - Computer Science (C++)

Advertisements
Advertisements

Question

Write the definition of a class BOX 1n C++ with the 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()   // function to allow user to enter values of BoxNumber and Side. Also, this

                  // function should call ExecArea () to calculate Area

- Showbox ()  //  A function to display BoxNumber , Side and Area

Solution

class Box
{
private:int BoxNumber;
       float side, Area;
void ExecArea()
{
    Area = Side * Side;
}
public:void GetBox();
    void ShowBox();
};
void Box :: GetBox()
{
     cout <<“enter BoxNumber and side” ;
     cin >> BoxNumber >> side;
}
void Box :: Show Box()
{
     cout << "the BoxNumber and side is" << BoxNumber << Side;
}
void main ()
{
   obj.GetBox();
   obj.ShowBox();
   obj.ExecArea();
}
shaalaa.com
Using Private and Public Visibility Modes, Default Visibility Mode (Private)
  Is there an error in this question or solution?
2016-2017 (March) All India Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×