Created
September 5, 2023 11:31
-
-
Save HSley13/fea78e6c5cfe5e52386f11c79bf52e8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
using namespace std; | |
class abc | |
{ | |
public: | |
double x, y, z, b, h; | |
abc() | |
{ | |
x=y=z=0; | |
} | |
abc(double i, double j, double k) | |
{ | |
x=i; | |
y=j; | |
z=k; | |
} | |
double area() | |
{ | |
return b*h; | |
} | |
}; | |
// overloading the << operator | |
// it can also be a friend member, the coordinates would be Private Data then | |
ostream &operator<< (ostream &stream, abc &obj) | |
{ | |
stream<<obj.x<<" "; | |
stream<<obj.y<<" "; | |
stream<<obj.z<<" "<<endl; | |
cout<<" The Enter values for the Base and Height are: "<<endl; | |
stream<<obj.b<<"\n"; | |
stream<<obj.h<<endl<<" "; | |
cout<<" The area is: "; | |
stream<<obj.area(); | |
return stream; | |
} | |
// overloading the >> operator | |
istream &operator>> (istream &stream, abc &obj) | |
{ | |
cout<<" Enter the Coordinate Values: "<<endl; | |
stream>>obj.x>>obj.y>>obj.z; | |
cout<<" Enter the values for the Base and the Height respectively"<<endl; | |
stream>>obj.b>>obj.h; | |
return stream; | |
} | |
int main() | |
{ | |
abc triangle; | |
cin>>triangle; | |
cout<<" The Entered coordinates are the following: "<<triangle<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment