[ create a new paste ] login | about

Link: http://codepad.org/VFIsTbJh    [ raw code | output | fork ]

C++, pasted on Dec 8:
#include <iostream>
 
 
class point{
public:
        point(int _x = 0, int _y = 0)
                : x(_x), y(_y) {}
        virtual ~point() {}
 
        virtual void out_point(){
                std::cout << "x: " << x << std::endl
                        << "y: " << y << std::endl;
        }
 
        virtual void set_param(){
                std::cout << "x-> "; std::cin >> x;
                std::cout << "y-> "; std::cin >> y;
        }
 
        virtual void set_x(int _x) { x = _x;}
        virtual void set_y(int _y) { y = _y;}
 
        virtual void draw_point(){
                std::cout << "draw point\n";
        }
private:
        int x;
        int y;
};
 
class color_point: public point{
public:
        color_point(int _x = 0, int _y = 0, int _color = 0)
                : point(_x, _y), color(_color) {}
 
        void out_point(){
                this->point::out_point();
                std::cout << "color: " << color << std::endl;
        }
 
        void set_param(){
                this->point::set_param();
                std::cout << "color-> "; std::cin >> color; 
        }
 
        void set_color(int _color) { color = _color;}
 
        void draw_point(){
                std::cout << "draw color point\n";
                //.....
        }
private:
        int color;
};
 
 
void draw_all (point& rhs){
        rhs.draw_point();
}
int main(){
 
 
        point arr[10];
        color_point arr_c[10];
 
        //.....
 
 
        for(int i = 0; i < 10; ++i){
                draw_all(arr[i]);
                draw_all(arr_c[i]);
        }
        return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
draw point
draw color point
draw point
draw color point
draw point
draw color point
draw point
draw color point
draw point
draw color point
draw point
draw color point
draw point
draw color point
draw point
draw color point
draw point
draw color point
draw point
draw color point


Create a new paste based on this one


Comments: