실습과제 모음
CPP 0722 실습과제
TanSanC
2012. 7. 22. 13:17
#include <iostream>
#include <string>
using namespace std;
class ImaginaryNumber
{
public:
int real;
int imag;
ImaginaryNumber(int r, int i)
{
real = r;
imag = i;
}
void Display()
{
if(imag > 0 )
{
cout << real << " +" << imag << " * i"<< endl;
}
else
{
cout << real << " " << imag << " * i"<< endl;
}
}
ImaginaryNumber operator*(const ImaginaryNumber object)
{
// 계산 1
// 계산결과 리턴 2
ImaginaryNumber temp;
temp.real = ?;
temp.imag = ?;
return temp;
}
};
int main( )
{
ImaginaryNumber iNum1 ( 3 , 2 ); // 3 + 2i
ImaginaryNumber iNum2 ( 4 , -3 ); // 4 - 3i
iNum1.Display(); // 3 +2 * i
iNum2.Display(); // 4 +-3 * i
ImaginaryNumber iNum3 = iNum1 * iNum2;
iNum3.Display(); // 18 +-1 * i
return 0;
}