Posts

Showing posts with the label classes

Program for class and class data member and member function

Program for class: #include<iostream> using namespace std; class rectangle { private: float length; float width; float area; public: void setdata(float, float); void calarea(); float getlength(); float getwidth(); float getarea(); }; void rectangle::setdata(float l, float w) { length=l; width=w; } void rectangle ::calarea() { area=length*width; } float rectangle ::getlength() { return length; } float rectangle ::getwidth() { return width; } float rectangle ::getarea() { return area; } int main() { rectangle box; float boxlength,boxwidth; cout<<" what is length "; cin>>boxlength; cout<<"what is width "; cin>>boxwidth; box.setdata(boxlength,boxwidth); box.calarea(); cout<<"here is the rectangle's data : \n"; cout<<"\n length : "<< box.getlength()<<endl; cout<<" width : "<< box.getwidth() <<endl; cout...