Answer to Question #254495 in C++ for Amit

Question #254495

WAP to overload insertion and extraction operator


1
Expert's answer
2021-10-21T16:07:22-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS