목차
Complex.cpp 1.28KB
Complex.h 991바이트
main.cpp 2.88KB
Task09(연산자오버로딩).ncb 1.11MB
Task09(연산자오버로딩).sln 923바이트
Task09(연산자오버로딩).vcproj 3.79KB
Complex.h 991바이트
main.cpp 2.88KB
Task09(연산자오버로딩).ncb 1.11MB
Task09(연산자오버로딩).sln 923바이트
Task09(연산자오버로딩).vcproj 3.79KB
본문내용
#include
using namespace std;
//===================================================================================//
// ※ 연산자 오버로딩
// - 프로그래머가 만든 클래스를 기본타입처럼 사용하기 위해 연산자 오버로딩이 필요.
// - 학습내용 : 사칙연산(+,-,*,/), ++,--연산자
//===================================================================================//
#include "Complex.h"
int main(void)
{
Complex c1(1, 2); // 인자값 받아 생성
Complex c2(3, 4);
Complex c3; // 일반생성
cout << "<< 생성자 테스트 >>" << endl;
cout << "인자값 받은 생성자 - \tc1.real : " << c1.GetReal() << ", c1.imaginary : "<< c1.GetImaginary() << endl;
cout << "인자값 받은 생성자 - \tc2.real : " << c2.GetReal() << ", c2.imaginary : "<< c2.GetImaginary() << endl;
cout << "일반 생성자 - \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 + c2;
cout << endl;
cout << "<< + 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 + c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 - c2;
cout << endl;
cout << "<< - 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 - c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 * c2;
cout << endl;
cout << "<< * 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 * c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 / c2;
cout << endl;
cout << "<< / 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 / c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
using namespace std;
//===================================================================================//
// ※ 연산자 오버로딩
// - 프로그래머가 만든 클래스를 기본타입처럼 사용하기 위해 연산자 오버로딩이 필요.
// - 학습내용 : 사칙연산(+,-,*,/), ++,--연산자
//===================================================================================//
#include "Complex.h"
int main(void)
{
Complex c1(1, 2); // 인자값 받아 생성
Complex c2(3, 4);
Complex c3; // 일반생성
cout << "<< 생성자 테스트 >>" << endl;
cout << "인자값 받은 생성자 - \tc1.real : " << c1.GetReal() << ", c1.imaginary : "<< c1.GetImaginary() << endl;
cout << "인자값 받은 생성자 - \tc2.real : " << c2.GetReal() << ", c2.imaginary : "<< c2.GetImaginary() << endl;
cout << "일반 생성자 - \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 + c2;
cout << endl;
cout << "<< + 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 + c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 - c2;
cout << endl;
cout << "<< - 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 - c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 * c2;
cout << endl;
cout << "<< * 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 * c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
c3 = c1 / c2;
cout << endl;
cout << "<< / 연산자 오버로딩 테스트 >>" << endl;
cout << "c3 = c1 / c2 >> \tc3.real : " << c3.GetReal() << ", c3.imaginary : "<< c3.GetImaginary() << endl;
소개글