코드 접기..
// ubic.h: interface for the Cubic class. // //////////////////////////////////////////////////////////////////////
#if !defined(AFX_UBIC_H__6FB820A1_44DE_4ABC_8A7B_222AC31E28A1__INCLUDED_) #define AFX_UBIC_H__6FB820A1_44DE_4ABC_8A7B_222AC31E28A1__INCLUDED_
#if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000
#include "ThreeD.h"
class Cubic : public ThreeD { public: void m_PrintVol(); void m_PrintArea(); Cubic(int, int, int); Cubic(); virtual ~Cubic();
};
#endif // !defined(AFX_UBIC_H__6FB820A1_44DE_4ABC_8A7B_222AC31E28A1__INCLUDED_)
코드 접기.. 코드 접기..
// ubic.cpp: implementation of the Cubic class. // //////////////////////////////////////////////////////////////////////
#include "ubic.h" #include <iostream>
using namespace std;
////////////////////////////////////////////////////////////////////// // Construction/Destruction //////////////////////////////////////////////////////////////////////
Cubic::Cubic() {
}
Cubic::~Cubic() {
}
Cubic::Cubic(int aHeight, int aLength, int aWidth) : ThreeD(aHeight, aLength, aWidth) {
}
void Cubic::m_PrintArea() { cout << "표면적 : " << i_Width * i_Height * 2 + i_Width * i_Length * 2 + i_Length * i_Height * 2 << endl; return;
}
void Cubic::m_PrintVol() { cout << "부 피 : " << i_Width * i_Height *i_Length << endl; return;
}
코드 접기.. 코드 접기..
#include <iostream> #include "ubic.h"
using namespace std;
int main(void) { unsigned int i = 1; int iWidth, iLength, iHeight; iWidth = iLength = iHeight = 1;
Cubic *CCubic = NULL;
while(iWidth != 0 && iLength != 0 && iHeight != 0) { cout << i << "번째 직육면체의 가로,세로,높이 입력 : "; cin >> iWidth >> iLength >> iHeight; CCubic = new Cubic(iWidth, iLength, iHeight); // 이전 객체는 중요하지 않기 때문에 포인터 배열로 선언하지 않습니다.
if(iWidth == 0 || iLength == 0 || iHeight == 0) { cout << "프로그램을 종료합니다...";
}
else { CCubic->m_PrintVol(); CCubic->m_PrintArea(); i++; }
cout << endl;
} CCubic = NULL; delete CCubic;
return 0; }
코드 접기..