Write the definition of a class RING in C++ with following description.

Private Members:
- RingNumber //data member of integer type
- Radius //data member of float type
- Area //data member of float type
- CalcArea //member function to calculate and assign 
//Area as 3.14 * Radius * Radius

Public Members:
- GetArea() //A function to allow user to enter value of RingNumber,
//and Radius. Also call CalcArea function for Area.
- ShowArea() //A function to display RingNumber,Radius and Area

===============================================
Solution:
===============================================
class RING
{
int RingNumber;
float Radius, Area;
void CalcArea()
{
Area=3.14*Radius*Radius;
}
public:
void GetArea()
{
cout<<"Enter Ring Number    : ";
cin>>RingNumber;
cout<<"Enter Radius of Ring : ";
cout<<Radius;
CalcArea();
}
void ShowArea()
{
cout<<"..........RING DETAILS..........\n";
cout<<"Ring Number    : "<<RingNumber<<endl;
cout<<"Radius of Ring : "<<Radius<<endl;
cout<<"Area of Ring   : "<<Area<<endl;
}
};


No comments

Post your comments

Powered by Blogger.