![]()
| ファイル名 | 説明 |
|---|---|
| Lcm.cpp | class を継承 |
using namespace System;
//☆GCM Class の定義
ref class GCM
{
private:
int w1,w2;
public:
int Gcm(int v1, int v2)
{
w1 = v1;
w2 = v2;
while(w1 != w2)
{ if (w1 > w2) w1-= w2;
else w2-= w1;
}
return w1;
}
};
|
//☆LCM Class の定義
ref class LCM : public GCM
{
public:
int Lcm(int v1, int v2)
{
return v1*v2/Gcm(v1,v2);
}
};
|
//★ main
void main(void)
{ GCM^ gcm;
LCM^ lcm;
gcm = gcnew GCM();
Console::WriteLine("GCM Object Class を使います");
Console::WriteLine("24 と 32 の GCM は {0} です", gcm->Gcm(24,32));
delete gcm;
Console::WriteLine("\nLCM Object Class を使います");
lcm = gcnew LCM();
Console::WriteLine("24 と 32 の GCM は {0} で、LCM は {1} です", lcm->Gcm(24,32), lcm->Lcm(24,32));
delete lcm;
System::Console::ReadLine();
}
|
| 導出クラス:アクセスコントロール 基本クラス {...}; |
![]()