ÇÁ·Î±×·¡¹Ö

 3204, 155/161 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   jkh0721
   c++ µµÇü¹®Á¦

http://www.hackerschool.org/HS_Boards/zboard.php?id=QNA_programming&no=3430 [º¹»ç]



¾Æ·¡ Äڵ忡¼­ ¹ØÀ¸·Î ³»·Á°¡¸é void main()  ÆÄÆ®°¡ Àִµ¥ ±× ÆÄÆ®¸¸ ÁÖ¼® Á» ´Þ¾ÆÁÖ¼¼¿ä
³ª¸ÓÁø ÀÌÇØ°¡ °¡´Âµ¥ °Å±â¸¸ Àß ¸ð¸£°Ú¾î¿ä

#include <iostream>
#include <string>
using namespace std;

class Shape{
protected:
        int x, y;
public:
        virtual ~Shape() {}
        virtual void draw()=0;
};
class TwoDimShape:public Shape{
public:
        virtual double getArea()=0;
};
class ThreeDimShape:public Shape{
public:
        virtual double getVolume()=0;
};
class Rectangle : public TwoDimShape{
private:
        int width, height;
public:
        
        void setWidth(int w){width = w;}
        void setHeight(int h){height = h;}
        void draw() {cout << "Ractangle Draw"<<endl;}
        double getArea(){return width*height;}
};
class Ellipse : public TwoDimShape{
private:
        double LongAxis, ShortAxis;
public:
Ellipse() {}
        ~Ellipse() {}
        void setLongAxis(int l){LongAxis=l;}
        void setShortAxis(int s){ShortAxis=s;}
        void draw() {cout << "Ellipse Draw"<<endl;}
        double getArea(){return 3.14*LongAxis*ShortAxis/4;}
};
class Triangle : public TwoDimShape{
private:
        int width, height;
public:
        
        void setWidth(int w){width = w;}
        void setHeight(int h){height = h;}
        void draw() {cout << "Triangle Draw"<<endl;}
        double getArea(){return (double)width*height/2;}
};
class Shpere : public ThreeDimShape{
private:
        int radius;
public:
        void setRadius(int r){radius = r;}
        double getVolume(){return 3.14*radius*radius*radius*4/3;}
        void draw() {cout << "Shpere Draw"<<endl;}
};
class Cube : public ThreeDimShape{
private:
        int length;
        int width;
        int height;
public:
        void setLength(int l){length=l;}
        void setWidth(int w){width=w;}
        void setHeight(int h){height=h;}
        double getVolume(){return length*width*height;}
        void draw() {cout << "Cube Draw"<<endl;}
};
class Cylinder : public ThreeDimShape{
private:
        int radius;
        int height;
public:
        void setRadius(int r){radius = r;}
        void setHeight(int h){height = h;}
        double getVolume(){return 3.14*radius*radius*height;}
        void draw() {cout << "Cylinder Draw"<<endl;}
};
void main() {
        Shape *arrayOfShapes[6];
        arrayOfShapes[0] = new Rectangle;
        ((Rectangle*)arrayOfShapes[0])->setWidth(10);
        ((Rectangle*)arrayOfShapes[0])->setHeight(10);
        arrayOfShapes[1] = new Ellipse;
        ((Ellipse*)arrayOfShapes[1])->setLongAxis(10);
        ((Ellipse*)arrayOfShapes[1])->setShortAxis(10);
        arrayOfShapes[2] = new Triangle;
        ((Triangle*)arrayOfShapes[2])->setWidth(10);
        ((Triangle*)arrayOfShapes[2])->setHeight(10);
        arrayOfShapes[3] = new Shpere;
        ((Shpere*)arrayOfShapes[3])->setRadius(10);
        arrayOfShapes[4] = new Cube;
        ((Cube*)arrayOfShapes[4])->setWidth(10);
        ((Cube*)arrayOfShapes[4])->setHeight(10);
        ((Cube*)arrayOfShapes[4])->setLength(10);
        arrayOfShapes[5] = new Cylinder;
        ((Cylinder*)arrayOfShapes[5])->setRadius(10);
        ((Cylinder*)arrayOfShapes[5])->setHeight(10);
        cout << "¸ðµç±æÀ̹ÝÁö¸§°¡·Î¼¼·Î³ôÀÌÀDZæÀ̸¦10À̶ó°¡Á¤<<endl;
        for(int i=0; i<6;i++){
                arrayOfShapes[i]->draw();
                if(i<3) cout << "µµÇüÀdzÐÀÌ: " << ((TwoDimShape *)arrayOfShapes[i])->getArea() <<endl;
                else cout <<"µµÇüÀǺÎÇÇ: " << ((ThreeDimShape *)arrayOfShapes[i])->getVolume() <<endl;
        }
};

  Hit : 6453     Date : 2012/06/03 09:56



    
124   C¾ð¾î¸¦ °øºÎÇϴµ¥ °è¼Ó ¿¡·¯°¡¶ß³×¿ä;;[2]     tjdgh4688
02/18 6346
123   2Â÷¿ø ¹è¿­À» malloc()À¸·Î ó¸®ÇÏ´Â ¹æ¹ý[2]     powermilk
05/16 6366
122   [C¾ð¾î] ¿­Ç÷°­ÀÇ C ¸¶Áö¸· ¹®Á¦ Áú¹®ÀÌ¿ä.[4]     ¿µ¿øÇÑ°øºÎ
06/13 6366
121   0xffffffff°¡ ¹«½¼ ¶æÀΰ¡¿ä??[1]     socks
03/02 6381
120     [re] memset() ÇÔ¼öÁ» ¾ËÄÑÁÖ¼¼¿ë^^     ¼ÒÀ¯
09/13 6403
119   C¾ð¾î, ¼ýÀÚ°¡ Å« ¼ø¼­´ë·Î ³ª¿­ÇÏ´Â ÇÁ·Î±×·¥ ÄÚµå (Á»ºÁÁּſä)[2]     rocket07
02/14 6407
  c++ µµÇü¹®Á¦     jkh0721
06/03 6452
117   8051 ÇÁ·Î±×·¡¹Ö[MICOM]     ¾ÆÀÌÇÁ¸®µå
04/23 6458
116   ´Ü¾îÀå¿¡ ´Ü¾î¸¦ Ãß°¡ÇÏ°Ô ÇØÁÖ´Â ÇÁ·Î±×·¥Àä...´Ü¾îÃß°¡°¡ ¾ÈµË´Ï´Ù..[6]     JJang777
06/18 6482
115   C¾ð¾î ¸· ½ÃÀÛÇߴµ¥ °£´ÜÇÑ Áú¹®Á»[8]     Lunatie
10/06 6559
114   [ÃʱÞ] DEV-C++ »ç¿ëÇϽôºеé ÄÄÆÄÀÏ ¿¡·¯¹®Á¦[3]     radical31
03/14 6566
113   [¾¾¾ð¾î]¿­Ç÷°­ÀǸ¦ Microsoft Visual Studio 2010¿¡¼­ µû¶ó ÇÏ°í ½ÍÀºµ¥¿ä...[3]     ssama333
02/09 6608
112   c++ ÀÏÁ¤½Ã°£µÇ¸é ½ÇÇàµÇ´Â ÇÁ·Î±×·¥[1]     shinss2129
08/08 6640
111   ³ªÇÁÀß À̶ó´Â Ã¥¿¡ ´ëÇØ..[2]     selbe2
10/30 6643
110   ºí·ç½ºÅ©¸° ¼Ò½º[5]     h@cking2013
03/23 6675
109   MFC¿¡¼­ setTimer()°ü·Ã Áú¹®ÀÔ´Ï´Ù.[1]     haha0913
10/02 6678
108   ¿¬±¸ÇÏ·Á°í Æۿ¾¾Ë¼ö¾ø´Â ¼Ò½º....[3]     tlqaksqhr
07/31 6693
107   º£¸®ÁîÀ¥½¦¾îÀÇ ¿ø¸®°¡ ¹«¾ùÀΰ¡¿ä[1]     attainer
03/20 6714
106   JSP ÆÄÀÏ ¾÷/´Ù¿î·Îµå °ü·Ã Áú¹®ÀÖ½À´Ï´Ù.     hsg0154
07/30 6765
105   2¹ø¤Š ÇÁ·Î±×·¡¹Ö Àε¥¿ä ¤Ð¤Ð[1]     ¸¸µçÀÌ
06/09 6803
[1]..[151][152][153][154] 155 [156][157][158][159][160]..[161]

Copyright 1999-2024 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org