fork download
  1. #include <iostream>
  2. using namespace std;
  3. class Square
  4. {
  5. public:
  6. double length; // Довжина квадрата
  7. double width; // Ширина квадрата
  8.  
  9. Square(double l, double w) // Конструктор
  10. {
  11. length = l;
  12. width = w;
  13. }
  14.  
  15. double Area()
  16. {
  17. return length * width;
  18. }
  19. };
  20.  
  21. int main(void)
  22. {
  23. Square a(2.0, 3.0), b(6.5, 7.2), *c;
  24. c = &a;
  25. cout<< c->Area()<<endl;
  26. //cout<<(*c).Area(); // Альтернативний запис
  27. c = &b;
  28. cout<< c->Area()<<endl;
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
6
46.8