【C++】簡単なクラスを作成します.コンストラクション関数、メンバー関数などが含まれます.


//        。      ,     。
#include <iostream>
using namespace std;
class Rec
{
	public:
		Rec(int l,int w);
		int Area();
		void Print();
	private:
		int length,wide;
};
Rec::Rec(int l,int w)
{
	length=l;
	wide=w;
}
int Rec::Area()
{
	return length*wide;
}
void Rec::Print()
{
	cout<<"     :"<<length<<","<<wide<<endl;
}
int main()
{
	Rec rec1(8,5),rec2(18,6);
	cout<<"   1";
	rec1.Print();
	cout<<"      :"<<rec1.Area();
	cout<<endl;
	cout<<"   2";
	rec2.Print();
	cout<<"      :"<<rec2.Area();
	cout<<endl;
	return 0;
}