fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. class Equal {
  7. protected:
  8. int a;
  9. public:
  10. Equal(int x):a(x){}
  11. int perim() {
  12. return 3*a;
  13. }
  14. double square() {
  15. return ((a*a)*sqrt(3))/4;
  16. }
  17. };
  18.  
  19. int main() {
  20. int n;
  21. cin >> n;
  22. Equal eq(n);
  23. cout<<eq.perim()<<" ";
  24. cout<<fixed<<setprecision(4)<<eq.square();
  25. }
Success #stdin #stdout 0.01s 5308KB
stdin
2 3 4
stdout
12 6.9282