Cpp クラス 継承 アップキャスト 新しいページはコチラ
提供: yonewiki
(→クラス 継承 アップキャスト) |
(→クラス 継承 アップキャスト) |
||
53行: | 53行: | ||
int m_iBaseMoney = 0; | int m_iBaseMoney = 0; | ||
int m_iBaseMonth = 0; | int m_iBaseMonth = 0; | ||
+ | int m_iMoney = 0; | ||
int mf_iBaseSumMoney(); | int mf_iBaseSumMoney(); | ||
public: | public: | ||
72行: | 73行: | ||
} | } | ||
− | CBaseInheritance::CBaseInheritance(int iArgBaseMoney, int iArgBaseMonth) | + | CBaseInheritance::CBaseInheritance(int iArgBaseMoney, int iArgBaseMonth) |
− | + | :m_iBaseMoney(iArgBaseMoney) | |
− | + | ,m_iBaseMonth(iArgBaseMonth) | |
+ | ,m_iMoney(0) { | ||
printf("Constructor:CBaseInheritance(int,int)\n"); | printf("Constructor:CBaseInheritance(int,int)\n"); | ||
} | } | ||
83行: | 85行: | ||
int CBaseInheritance::mf_iBaseSumMoney() { | int CBaseInheritance::mf_iBaseSumMoney() { | ||
− | + | m_iMoney = m_iBaseMoney * m_iBaseMonth; | |
+ | return m_iMoney; | ||
} | } | ||
115行: | 118行: | ||
~CDeriveInheritance(); | ~CDeriveInheritance(); | ||
void mf_vDeriveDispValue(); | void mf_vDeriveDispValue(); | ||
+ | int mf_iDeriveOption(); | ||
int mf_iDeriveSumMoney(); | int mf_iDeriveSumMoney(); | ||
void mf_vDeriveSetOptionValue(int iArgOptionValue); | void mf_vDeriveSetOptionValue(int iArgOptionValue); | ||
152行: | 156行: | ||
m_iDeriveOption = iArgOptionMoney; | m_iDeriveOption = iArgOptionMoney; | ||
} | } | ||
+ | |||
+ | int CDeriveInheritance::mf_iDeriveOption() { | ||
+ | return m_iDeriveOption; | ||
+ | } | ||
+ | |||
int CDeriveInheritance::mf_iDeriveSumMoney() { | int CDeriveInheritance::mf_iDeriveSumMoney() { | ||
− | + | m_iMoney = mf_iBaseSumMoney() + m_iDeriveOption; | |
+ | return m_iMoney; | ||
} | } | ||
180行: | 190行: | ||
int m_iSize = 0; | int m_iSize = 0; | ||
int* m_piDeriveOptionArr = nullptr; | int* m_piDeriveOptionArr = nullptr; | ||
− | |||
public: | public: | ||
CDeriveArrInheritance(int iArgMoney, int iArgMonth); | CDeriveArrInheritance(int iArgMoney, int iArgMonth); | ||
188行: | 197行: | ||
void mf_vDeriveSetArrOption(int* piArgOption); | void mf_vDeriveSetArrOption(int* piArgOption); | ||
+ | int mf_iDeriveSumMoney(); | ||
int mf_iDeriveGetArrOption(); | int mf_iDeriveGetArrOption(); | ||
}; | }; | ||
227行: | 237行: | ||
} | } | ||
− | + | int CDeriveArrInheritance::mf_iDeriveSumMoney() { | |
for (int iScan = 0; iScan < m_iSize; iScan++) { | for (int iScan = 0; iScan < m_iSize; iScan++) { | ||
m_iDeriveOption += m_piDeriveOptionArr[iScan]; | m_iDeriveOption += m_piDeriveOptionArr[iScan]; | ||
} | } | ||
+ | m_iMoney = m_iDeriveOption + mf_iBaseSumMoney(); | ||
+ | return m_iMoney; | ||
} | } | ||
238行: | 250行: | ||
m_piDeriveOptionArr[iScan] = piArgOption[iScan]; | m_piDeriveOptionArr[iScan] = piArgOption[iScan]; | ||
} | } | ||
− | + | mf_iDeriveSumMoney(); | |
} | } | ||
+ | |||
+ | |||
</syntaxhighlight2> | </syntaxhighlight2> | ||
269行: | 283行: | ||
void mf_iDeriveSetDiscount(double dRate); | void mf_iDeriveSetDiscount(double dRate); | ||
+ | int mf_iDeriveSumMoney(); | ||
}; | }; | ||
#endif | #endif | ||
287行: | 302行: | ||
printf("Constructer:CDeriveDiscountInheritance(int,int,double)\n"); | printf("Constructer:CDeriveDiscountInheritance(int,int,double)\n"); | ||
m_dRate = dArgRate; | m_dRate = dArgRate; | ||
+ | mf_iDeriveSumMoney(); | ||
} | } | ||
292行: | 308行: | ||
printf("Destructer:~CDeriveDiscountInheritance()\n"); | printf("Destructer:~CDeriveDiscountInheritance()\n"); | ||
} | } | ||
+ | |||
void CDeriveDiscountInheritance::mf_iDeriveSetDiscount(double dArgRate) { | void CDeriveDiscountInheritance::mf_iDeriveSetDiscount(double dArgRate) { | ||
m_dRate = dArgRate; | m_dRate = dArgRate; | ||
+ | mf_iDeriveSumMoney(); | ||
} | } | ||
void CDeriveDiscountInheritance::mf_vDeriveDiscountDispValue() { | void CDeriveDiscountInheritance::mf_vDeriveDiscountDispValue() { | ||
− | int iSumMoney = ( | + | int iSumMoney = mf_iDeriveSumMoney(); |
printf("DeriveMoney=%d\n", iSumMoney); | printf("DeriveMoney=%d\n", iSumMoney); | ||
+ | } | ||
+ | |||
+ | int CDeriveDiscountInheritance::mf_iDeriveSumMoney() { | ||
+ | m_iMoney = (int)(m_dRate * mf_iBaseSumMoney() + 0.5); | ||
+ | return m_iMoney; | ||
} | } | ||
</syntaxhighlight2> | </syntaxhighlight2> |