C++ Program To Find Area Rectangle Using Class Function | C++ Programming

Source Code

#include<iostream>
using namespace std;
#include<iomanip>
class rectangle
{
 float length;
 float breadth;
 public:
  void setdata (int l, int b)
  {
   length=l;
   breadth=b;
  }
  void showdata()
  {
   cout<<"length="<<length<<endl;
   cout<<"Breadth="<<breadth<<endl;
  }
  float area()
  {
   return length*breadth;
  }
  void getdata()
  {
   cout<<"Enter length:\n";
   cin>>length;
   cout<<"Enter breadth:\n";
   cin>>breadth;
   setdata(length,breadth);
  }
};
int main()
{
 rectangle r;
 r.getdata();
 r.showdata();
 cout<<"Area="<<r.area();
}

OUTPUT


Enter length:
25
Enter breadth:
5
length=25
Breadth=5
Area=125

Post a Comment

0 Comments