//C++ program to demonstrate Class and Object
//Class Rectangle with length and breadth as private members
//and appropriate member functions to read data, calculate and display area
#include <iostream>
using namespace std;
class Rectangle
{
private:
float l,b,a;
public:
void ReadData();
void CalculateArea();
void DisplayArea();
};
void Rectangle::ReadData()
{
cout<<"Enter length and breadth: ";
cin>>l>>b;
}
void Rectangle::CalculateArea()
{
a=l*b;
}
void Rectangle::DisplayArea()
{
cout<<"The area is "<<a;
}
int main()
{
Rectangle r1;
r1.ReadData();
r1.CalculateArea();
r1.DisplayArea();
return 0;
}
//Class Rectangle with length and breadth as private members
//and appropriate member functions to read data, calculate and display area
#include <iostream>
using namespace std;
class Rectangle
{
private:
float l,b,a;
public:
void ReadData();
void CalculateArea();
void DisplayArea();
};
void Rectangle::ReadData()
{
cout<<"Enter length and breadth: ";
cin>>l>>b;
}
void Rectangle::CalculateArea()
{
a=l*b;
}
void Rectangle::DisplayArea()
{
cout<<"The area is "<<a;
}
int main()
{
Rectangle r1;
r1.ReadData();
r1.CalculateArea();
r1.DisplayArea();
return 0;
}
No comments:
Post a Comment