
Файл Graph.H:
//---------------------------------------------------------------------------
#ifndef GraphH
#define GraphH
#include <vector>
#include <iostream>
#include <fstream>
#include <C:\Users\Freddy\Desktop\OOP_2014\LAB6_3\LAB6_3\Dot.h>
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
using namespace std;
class Graph
{
public:
//Dot t;
vector<Dot> dots;
TImage *img;
TListBox *list;
enum GraphType{DOT, LINE, POLY} type;
Graph(TImage *Image, TListBox *ListBox);
virtual void Draw();
void Clear();
void AddDot(Dot *dot);
void AddLine(Dot *A, Dot *B);
void Save(string path);
void Load(string path, TListBox *list);
};
#endif
файл GraphDot.cpp :
//---------------------------------------------------------------------------
#pragma hdrstop
#include "GraphDot.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
void GraphDot::Draw()
{
Clear();
img->Canvas->Pen->Color = clBlack;
for(int i=0; i<dots.size(); ++i)
img->Canvas->Rectangle(dots[i].X-1, dots[i].Y-1, dots[i].X+1, dots[i].Y+1);
}
файл GraphDot.h:
//---------------------------------------------------------------------------
#ifndef GraphDotH
#define GraphDotH
#include <C:\Users\Freddy\Desktop\OOP_2014\LAB6_3\LAB6_3\Graph.h>
class GraphDot : Graph
{
public:
void Draw();
GraphDot(TImage *Image, TListBox *ListBox):Graph(Image, ListBox) {}
};
#endif
файл GraphLine.cpp:
//---------------------------------------------------------------------------
#pragma hdrstop
#include "GraphLine.h"
void GraphLine::Draw()
{
Clear();
img->Canvas->Pen->Color = clBlack;
for(int i=0; i<dots.size(); ++i)
{
if(i%2==0)
img->Canvas->MoveTo(dots[i].X, dots[i].Y);
else
img->Canvas->LineTo(dots[i].X, dots[i].Y);
}
}
#pragma package(smart_init)
файл GraphLine.h:
//---------------------------------------------------------------------------
#ifndef GraphLineH
#define GraphLineH
#include <C:\Users\Freddy\Desktop\OOP_2014\LAB6_3\LAB6_3\Graph.h>
class GraphLine : Graph
{
public:
void Draw();
GraphLine(TImage *Image, TListBox *ListBox):Graph(Image, ListBox) {}
};
#endif
файл GraphPoly.cpp:
//---------------------------------------------------------------------------
#pragma hdrstop
#include "GraphPoly.h"
void GraphPoly::Draw()
{
Clear();
img->Canvas->Pen->Color = clBlack;
img->Canvas->MoveTo(dots[0].X, dots[0].Y);
for(int i=0; i<dots.size(); ++i)
img->Canvas->LineTo(dots[i].X, dots[i].Y);
img->Canvas->LineTo(dots[0].X, dots[0].Y);
}
#pragma package(smart_init)
файл GraphPoly.h:
//---------------------------------------------------------------------------
#ifndef GraphPolyH
#define GraphPolyH
#include <C:\Users\Freddy\Desktop\OOP_2014\LAB6_3\LAB6_3\Graph.h>
class GraphPoly : Graph
{
public:
void Draw();
GraphPoly(TImage *Image, TListBox *ListBox):Graph(Image, ListBox) {}
};
#endif
файл Project1.cpp:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Unit1.cpp", DotForm);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TDotForm), &DotForm);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------