shape_class.cpp
来自「清华关于C++ 的程序讲义 值得一看 关于算法」· C++ 代码 · 共 64 行
CPP
64 行
#ifndef WINDOWOBJECT_H
#define WINDOWOBJECT_H
#include "ezwin.h"
// WindowObject base class for objects that can be
// displayed in a window
class WindowObject {
public:
WindowObject(SimpleWindow &w, const Position &p);
Position GetPosition() const;
SimpleWindow& GetWindow() const;
void SetPosition(const Position &p);
private:
SimpleWindwo &Window;
Position Location;
};
#endif
==========================================================
#ifndef SHAPE_H
#define SHAPE_H
#include "windowobject.h"
// shape class derived from WindowObject class
class Shape : public WindowObject {
public:
Shape(SimpleWindow &w, const Position &p, const color &c = Red);
color GetColor() const;
void SetColor(const color &c);
private:
color Color;
};
#endif
==========================================================
#ifndef ELLIPSESHAPE_H
#define ELLIPSESHAPE_H
#include "shape.h"
class EllipseShape : public Shape {
public:
EllipseShape(SimpleWindow &Window, const Position &Center, const color &c =Red, float Length = 1.0, float Height = 2.0);
float GetWidth() const;
float GetHeight() const;
void Draw();
void SetSize(float Width, float Height);
private:
float Width;
float Height;
};
#endif
==========================================================
#ifndef RECTANGLESHAPE_H
#define RECTANGLESHAPE_H
#include "shape.h"
class RectangleShape : public Shape {
public:
RectangleShape(SimpleWindow &Window, const Position &Center, const color &c = Red, float Width = 1.0, float Height = 2.0);
float GetWidth() const;
float GetHeight() const;
void Draw();
void SetSize(float Width, float Height);
private:
float Width;
float Height;
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?