[ create a new paste ] login | about

Link: http://codepad.org/4sstpRbo    [ raw code | output | fork ]

C++, pasted on Jul 19:
#include <cstdio>
#include <cmath>
using namespace std;

class Shape {
protected:
  int n;
  double l;
public:
  Shape(int n, double l) { this->n = n; this->l = l; };
  double hen();
  virtual double menseki() = 0;
};

class Rectangle : public Shape
{
public:
  Rectangle(int n, double l ) : Shape(n, l) {}
  double hen(){ return n * l; }
  double menseki(){ return l * l; }
};

int main()
{
  double x;
  scanf("%lf", &x);
  Rectangle r(4, x);
  printf("%.3f %.3f\n", r.hen(), r.menseki());
}
/* end */


Output:
1
0.000 0.000


Create a new paste based on this one


Comments: