Çʵå Å×½ºÆ®

 

1. Æ÷ÇÔ°ú »ó¼ÓÀÇ °æ¿ì¿¡´Â »ý¼ºÀÚ¿Í ¼Ò¸êÀÚÀÇ È£Ãâ ½ÃÁ¡ÀÌ Áß¿äÇÏ´Ù. °¢°¢ÀÇ °æ¿ì¿¡ Á¤¸»·Î ÇÊÀÚ°¡ ¸»ÇÑ ¼ø¼­´ë·Î È£ÃâµÇ´ÂÁö È®ÀÎÇØº¸ÀÚ. (ÈùÆ® : »ý¼ºÀÚ¿Í ¼Ò¸êÀÚ¿¡¼­ ¹®ÀÚ¿­À» Ãâ·ÂÇØº¸¸é µÈ´Ù)

 

Á¤´ä->

#include <iostream>

using namespace std;

 

class Base

{

public:

             Base()

             {

                           cout << "Base::Base()\n";

             }

             ~Base()

             {

                           cout << "Base::~Base()\n";

             }

};

 

class Child : public Base

{

public:

             Child()

             {

                           cout << "Child::Child()\n";

             }

             ~Child()

             {

                           cout << "Child::Child()\n";

             }

};

 

class Contained

{

public:

             Contained()

             {

                           cout << "Contained::Contained()\n";

             }

             ~Contained()

             {

                           cout << "Contained::~Contained()\n";

             }

};

 

class Container

{

public:

             Container()

             {

                           cout << "Container::Container()\n";

             }

             ~Container()

             {

                           cout << "Container::~Container()\n";

             }

 

public:

             Contained c;

};

 

// »ó¼Ó Å×½ºÆ®

void InheritanceTest()

{

             Child ch;

}

 

// Æ÷ÇÔ Å×½ºÆ®

void ContainmentTest()

{

             Container co;

}

int main()

{

             cout << "»ó¼Ó Å×½ºÆ®\n";

             InheritanceTest();

 

             cout << "\nÆ÷ÇÔ Å×½ºÆ®\n";

             ContainmentTest();

 

             return 0;

}

 

2. Rect Ŭ·¡½º¿¡´Â ¹®Á¦Á¡ÀÌ ÀÖ´Ù. ¿¹¸¦ µé¾î¼­ _topLeftÀÇ °ªÀÌ (10, 10)À̰í,  _bottomRightÀÇ °ªÀÌ (0, 0)À̶ó¸é, GetWidth() ÇÔ¼ö¿Í GetHeight() ÇÔ¼ö´Â °¢°¢ -10À» ¹ÝȯÇÑ´Ù. ÀÌ·± °æ¿ì¿¡µµ ¾ç¼öÀÇ °ªÀ» ¹ÝȯÇÒ ¼ö ÀÖ°Ô °íÃĺ¸ÀÚ.

 

Á¤´ä->

 ÀÌ ¹®Á¦¸¦ ÇØ°áÇϴµ¥´Â Å©°Ô 2°¡Áö ¹æ¹ýÀÌ ÀÖ´Ù. Çϳª´Â Rect °´Ã¼¿¡ °ªÀÌ ´ëÀ﵃ ¶§¸¶´Ù °Ë»çÇØ¼­ ³»ºÎ »óŸ¦ ¿Ã¹Ù¸£°Ô À¯ÁöÇÏ´Â ¹æ¹ýÀ̰í, ´Ù¸¥ Çϳª´Â GetWidth()³ª GetHeight()°¡ È£ÃâµÉ ¶§¸¸ ¿Ã¹Ù¸¥ °á°ú°¡ ¹ÝȯµÇ°Ô ¸¸µå´Â ¹æ¹ýÀÌ´Ù. °³ÀÎÀûÀÎ »ý°¢À¸·Î´Â ÈÄÀÚÀÇ ¹æ¹ýÀÌ ´õ °£´ÜÇÑ °Í °°±â ¶§¹®¿¡ GetWidth()¿Í GetHeight() ÇÔ¼ö¸¸ ´ÙÀ½°ú °°ÀÌ ¼öÁ¤Çß´Ù.

 

int Rect::GetWidth() const

{

       int width = _bottomRight.GetX() - _topLeft.GetX();

       if (width < 0)

             width = -width;

 

       return width;

}

 

int Rect::GetHeight() const

{

       int height =  _bottomRight.GetY() - _topLeft.GetY();

       if (height < 0)

             height = -height;

            

       return height;

}

 

3. HTMLWriter Ŭ·¡½ºÀÇ µÎ »ý¼ºÀÚ¿¡¼­ µðÆúÆ® ÆùÆ®¸¦ ÁöÁ¤ÇÏ´Â Äڵ尡 Áߺ¹µÇ¾ú´Ù. ±â´ÉÀº ±×´ë·Î À¯ÁöÇϸ鼭 ÄÚµåÀÇ Áߺ¹À» ¾ø¾Öº¸ÀÚ.

 

Á¤´ä->

¸â¹ö ÇÔ¼ö¸¦ Çϳª Ãß°¡Çؼ­ Áߺ¹µÈ Äڵ带 °øÀ¯ÇÏ°Ô ¸¸µé ¼ö ÀÖ´Ù.

 

HTMLWriter::Init()

{

             // µðÆúÆ® ÆùÆ®¸¦ ÁöÁ¤ÇÑ´Ù.

             _fontName = "±¼¸²";

             _fontSize = 3;

             _fontColor = "black";

}

 

HTMLWriter::HTMLWriter(const string& fileName, const string& content)

: DocWriter( fileName, content)

{

             Init();

}

 

HTMLWriter::HTMLWriter()

{

             // µðÆúÆ® ÆÄÀÏ À̸§¸¸ ¹Ù²Û´Ù.

             _fileName = "NoName.html";

 

Init();

}