fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Figure{
  5. protected:
  6. double s=0;
  7. public:
  8. Figure(){
  9. // cout<<"Constructor Figure"<<endl;
  10. }
  11. ~Figure(){
  12. // cout<<"Destrutor Figure"<<endl;
  13. }
  14. double getS(){
  15. return s;
  16. }
  17.  
  18. friend std::ostream & operator<<(std::ostream &, const Figure);
  19. };
  20. std::ostream & operator<< (std::ostream & out, const Figure x) {
  21. out <<"S="<< x.s<<endl;
  22. out<<"Hello";
  23. return out;
  24. }
  25.  
  26. class Triangle:public Figure{
  27. public:
  28. int x, y, z;
  29. Triangle(int a, int b, int c)
  30. {
  31. cout<<"Constructor Tri"<<endl;
  32. x = a;
  33. y = b;
  34. z = c;
  35. s=a+b+c;
  36. }
  37. friend std::istream & operator>> (std::istream &, Triangle &);
  38.  
  39. ~Triangle(){
  40. // cout<<"Destrutor Triangle"<<endl;
  41. }
  42. };
  43.  
  44. class Rect: public Figure
  45. {
  46. public:
  47. int x, y;
  48. Rect(int a, int b)
  49. {
  50. //cout<<"Constructor Rect"<<endl;
  51. x = a;
  52. y = b;
  53. s=a*b;
  54. }
  55. ~Rect(){
  56. // cout<<"Destrutor Rect"<<endl;
  57. }
  58.  
  59. };
  60. void ex(){
  61. Rect x(1,2);
  62. }
  63. std::istream & operator>> (std::istream & in, Triangle & x) {
  64.  
  65. cout<<"Hello2222";
  66. int a,b,c;
  67. in >> a>> b>>c;
  68. x = Triangle(a,b,c);
  69. return in;
  70. }
  71. int main(void)
  72. {
  73. Figure f;
  74. cout<<f<<" dfsfghsyj";
  75. Rect y(10,5);
  76. cout<<y;
  77. ex();
  78. Triangle t(1,1,1);
  79. cin>>t;
  80. cout<<t;
  81. return 0;
  82. }
  83.  
  84.  
Success #stdin #stdout 0s 5288KB
stdin
3 3 3
stdout
S=0
Hello dfsfghsyjS=50
HelloConstructor Tri
Hello2222Constructor Tri
S=9
Hello