WAP to overload insertion and extraction operator
#include <iostream>
#include <conio.h>
#include <istream>
#include <ostream>
using namespace std;
class rectangle
{
double H;
double W;
double Area ;
public :
friend istream & operator >> (istream &, rectangle &);
friend ostream & operator << (ostream &, rectangle &);
};
istream & operator >> (istream &din, rectangle &r)
{
cout << "Enter rectangle Height: " ; din >> r.H ;
cout << "Enter rectangle Width : " ; din >> r.W ;
return (din) ;
}
ostream & operator << (ostream &dout, rectangle &r)
{
dout << endl << endl;
dout << "Height of rectangle: " << r.H << endl ;
dout << "Width of rectangle: " << r.W << endl ;
r.Area = r.H * r.W ;
dout << "The Area of the rectangle is : " << r.Area << endl;
getch() ;
return(dout) ;
}
int main()
{
rectangle r1;
cin >> r1;
cout << r1;
}
Comments
Leave a comment