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
|
#include <iostream>//C++ header file
#include <vector>
//USE INDENTATIONS AND SPACING TRHOUGHOUT!!!
struct TPoint
{
TPoint (const double& ax, const double& ay, const double& az)//const qualify, pass by ref
: x(ax), y(ay), z(az) {}
double x; double y; double z;
};
struct TTwoPoint
{
const TPoint* SP;//be consistent, either declare data members first or methods first
const TPoint* EP;
TTwoPoint(const double& x1, const double& y1, const double& z1,
const double& x2, const double& y2, const double& z2)
:SP (new TPoint(x1,y1,z1)), EP (new TPoint(x2,y2,z2)) {}
TTwoPoint(const TPoint* S, const TPoint* E)
:SP(S), EP(E) {}
};
class TObject
{
public:
virtual void Draw() = 0 ;
TObject() {}
~TObject() {}
};
class TLine : public TObject
{
private:
TTwoPoint* Loc;
public:
TLine(const TPoint* StP, const TPoint* EndP)
{
// Loc -> SP = StP;
// Loc -> EP = EndP;
Loc = new TTwoPoint(StP, EndP);
}
void Draw() {}
};
class TObjGroup : public TObject
{
private:
std::vector<TObject*> Objects;
public:
TObjGroup(TObject* Obj) {}
~TObjGroup() {}
void Draw();
void AddObject(TObject* AnObj);
};
void TObjGroup::Draw()
{
for (unsigned i=0; i< Objects.size();i++)
{
Objects[i]->Draw();
};
};
void TObjGroup::AddObject(TObject *AnObj)
{
Objects.push_back(AnObj);
};
int main( int argc, const char* argv[] )
{
//TObjGroup *Objs = TObjGroup(TLine(new TPoint(0,0,0),new TPoint(100,100,0)));
TLine line(new TPoint(0,0,0), new TPoint(100,100,0));
TObject* Obj = &line;
};
|