1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <iostream>
enum FIGURE_TYPE { LINE, RECTANGLE, ELLIPSE };
struct Line { FIGURE_TYPE t; int x1, y1, x2, y2; };
struct Rectangle { FIGURE_TYPE t; int left, top, right, bottom; };
struct Ellipse { FIGURE_TYPE t; int x, y, r; };
union FIGURE { FIGURE_TYPE t; Line line; Rectangle rect; Ellipse ellipse; };
void draw_line(Line line);
void draw_rect(Rectangle rect);
void draw_ellipse(Ellipse ellipse);
int main() { FIGURE figure; figure.ellipse = {ELLIPSE, 3, 3, 3}; figure.rect = {RECTANGLE, 2, 2, 2, 2}; figure.line = {LINE, 1, 1, 1, 1}; int t; while (std::cin >> t) { switch (t) { case LINE: std::cout << figure.line.x1 << std::endl; draw_line(figure.line); break; case RECTANGLE: std::cout << figure.rect.top << std::endl; draw_rect(figure.rect); break; case ELLIPSE: std::cout << figure.ellipse.x << std::endl; draw_ellipse(figure.ellipse); break; default: std::cerr << "No Match Pattern!" << std::flush; return 0; } } }
void draw_line(Line line) { std::cout << "Draw Line" << std::endl; }
void draw_rect(Rectangle rect) { std::cout << "Draw Rect" << std::endl; }
void draw_ellipse(Ellipse ellipse) { std::cout << "Draw Ellipse" << std::endl; }
|