[ create a new paste ] login | about

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

C++, pasted on Jul 21:
#include <stdio.h>
#include <math.h>
// クラス Shape
class Shape {
	protected:
		int n; // 辺の数
		double l; // 辺の長さ
	public:
		Shape(int, double); // コンストラクタ
		double hen(); // 辺の長さの合計
		virtual double menseki() = 0; // 面積の計算(純粋仮想関数)
};

//問題箇所start この行よりも前は一切変更していない
Shape::Shape(int n, double l) : n(n), l(l) {}
double Shape::hen() { return n * l; }

// クラス Rectangle
class Rectangle : public Shape
{
	public:
		Rectangle(int n, double l ) : Shape(n, l) {} // コンストラクタ
		virtual double menseki(){ return l * l; }
};
//問題箇所end この行よりも後ろは一切変更していない

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


Output:
1
0.000 0.000


Create a new paste based on this one


Comments: