4.Текст программы
Figures.h
#include <windows.h>
#include <fstream>
#include <string>
#include <windowsX.h>
#pragma once
class Figures
{
protected:
virtual POINT point_search() const =0;
public:
virtual void draw(HDC hdc,HWND hwnd) const = 0;
virtual void smeish (POINT enter,HDC hdc,HWND hwnd) = 0;
virtual void save (std::string enter) = 0;
virtual void lead (std::string enter)= 0;
};
Figure_contour.h
#include "Figures.h"
class Figure_contour : public Figures
{
protected:
POINT ppt[4];
int pixel_border;
int R_l;
int G_l;
int B_l;
bool paralell (const POINT first,const POINT second) const;
bool proverca (HWND hwnd) const;
POINT point_search() const;
public:
virtual void save_f(std::ofstream& in_file);
virtual void lead_f (std::ifstream& infile);
void Set_Pen(COLORREF rgb);
void Set_Border(int enter);
COLORREF Get_Pen() const;
friend std::ifstream& operator>>(std::ifstream& infile,Figure_contour &p);
int Get_Border() const;
Figure_contour ();
void draw(HDC hdc,HWND hwnd) const;
void Set_koord (POINT ppt[]);
void Get_koord(POINT ppt1[]) const;
virtual void lead (std::string enter);
virtual void save (std::string enter);
virtual void smeish (POINT enter,HDC hdc,HWND hwnd);
};
Paint.h
#include <windows.h>
#include <windowsX.h>
class Paint
{
protected:
int R_Z;
int G_Z;
int B_Z;
int R_B;
int G_B;
int B_B;
public:
void Set_Brush(COLORREF rgb);
void Set_Zaliv(COLORREF rgb);
COLORREF Get_Brush() const;
COLORREF Get_Zaliv() const;
};
Shaded_figure.h
#include "Figure_contour.h"
#include "Paint.h"
class Shaded_figure: public Paint, public Figure_contour
{
protected:
bool ris(HDC hdc) const;
public:
virtual void save_f (std::ofstream& infile);
virtual void lead_f (std::ifstream& infile);
void draw(HDC hdc,HWND hwnd) const;
void lead (std::string enter);
friend std::ifstream& operator>>(std::ifstream& infile,Shaded_figure &p);
void save (std::string enter);
Shaded_figure();
void smeish (POINT enter,HDC hdc,HWND hwnd);
};
Combined_figure.h
#include "Shaded_figure.h"
#include <math.h>
class Combined_figure : public Shaded_figure
{
private:
double Square (POINT point)const;
bool lie ()const;
Figure_contour second;
public:
void save_f(std::ofstream& in_file);
void lead_f (std::ifstream& infile);
friend std::ifstream& operator>>(std::ifstream& infile,Combined_figure &p);
Combined_figure();
void save (std::string enter);
void lead (std::string enter);
void smeish (POINT enter,HDC hdc,HWND hwnd);
void draw(HDC hdc,HWND hwnd) const;
void bla();
};
Defenition_Figure_contour.cpp
#include "Figure_contour.h"
void Figure_contour::Set_Pen (COLORREF rgb)
{
this->R_l=GetRValue(rgb);
this->G_l=GetGValue(rgb);
this->B_l=GetBValue(rgb);
}
void Figure_contour::Set_Border (int i)
{
this->pixel_border=i;
}
COLORREF Figure_contour::Get_Pen () const
{
COLORREF rgb=RGB(this->R_l,this->G_l,this->B_l);
return rgb;
}
int Figure_contour::Get_Border () const
{
return this->pixel_border;
}
void Figure_contour::Set_koord (POINT ppt1[])
{
for (int i=0;i<4;i++)
this->ppt[i]=ppt1[i];
}
void Figure_contour::Get_koord (POINT ppt1[]) const
{
for (int i=0;i<4;i++)
ppt1[i]=this->ppt[i];
}
void Figure_contour::draw (HDC hdc,HWND hwnd) const
{
if ( proverca (hwnd))
{
HPEN hGreenPen=CreatePen (PS_SOLID,pixel_border,RGB(R_l,G_l,B_l));
HBRUSH hWhite=GetStockBrush(WHITE_BRUSH);
HBRUSH holdBrush=SelectBrush (hdc,hWhite);
HPEN holdPen=SelectPen (hdc,hGreenPen);
Polygon (hdc,ppt,4);
SelectPen(hdc,hGreenPen);
DeletePen(hGreenPen);
}
else
throw 1;
}
void Figure_contour::smeish (POINT enter,HDC hdc,HWND hwnd)
{
HPEN hWhitePen=CreatePen(PS_SOLID,this->pixel_border,RGB(255,255,255));
HPEN hOldPen=SelectPen(hdc,hWhitePen);
HBRUSH hWhiteBrush=GetStockBrush(WHITE_BRUSH);
HBRUSH hOldBrush=SelectBrush(hdc,hWhiteBrush);
Polygon(hdc,ppt,4);
POINT point_s=this->point_search();
FloodFill(hdc,point_s.x,point_s.y,RGB(255,255,255));
for (int i=0;i<4;i++)
{
ppt[i].x=ppt[i].x+enter.x;
ppt[i].y=ppt[i].y+enter.y;
}
this->draw(hdc,hwnd);
}
void Figure_contour::lead (std::string enter)
{
std::ifstream infile;
infile.open(enter);
lead_f(infile);
infile.close();
}
void Figure_contour::lead_f (std::ifstream& infile)
{
for (int i=0;i<4;i++)
infile >> ppt[i].x >> ppt[i].y;
infile>>R_l>>G_l>>B_l;
infile>>pixel_border;
}
void Figure_contour::save (std::string enter)
{
std::ofstream infile;
infile.open(enter);
save_f(infile);
infile.close();
}
void Figure_contour::save_f (std::ofstream& infile)
{
for (int i=0;i<4;i++)
infile << ppt[i].x <<" "<< ppt[i].y<<"\n";
infile<<R_l<<" "<<G_l<<" "<<B_l<<"\n";
infile<<pixel_border<<"\n";
}
bool Figure_contour::paralell (const POINT first,const POINT second) const
{
double k=0;
if (first.x!=0)
{
k=second.x/double (first.x);
if (k*first.y!=second.y)
return 0;
else
return 1;
}
else
if (second.x!=0)
{
k=first.x/double (second.x);
if (k*second.y!=first.y)
return 0;
else
return 1;
}
else
if (second.y==first.y)
return 1;
else
return 0;
}
bool Figure_contour::proverca (HWND hwnd) const
{
RECT rt;
GetClientRect(hwnd,&rt);
int Xmax=rt.right,Ymax=rt.bottom;
bool flag=false;
if (Xmax>ppt[0].x&&Xmax>ppt[1].x&&Xmax>ppt[2].x&&Xmax>ppt[3].x&&0<=ppt[0].x&&0<=ppt[1].x&&0<=ppt[2].x&&0<=ppt[3].x&&Ymax>ppt[0].y&&Ymax>ppt[1].y&&Ymax>ppt[2].y&&Ymax>ppt[3].y&&0<=ppt[0].y&&0<=ppt[1].y&&0<=ppt[2].y&&0<=ppt[3].y)
if ((ppt[0].x!=ppt[1].x || ppt[0].y!=ppt[1].y)&&(ppt[0].x!=ppt[2].x || ppt[0].y!=ppt[2].y)&&(ppt[0].x!=ppt[3].x || ppt[0].y!=ppt[3].y)&&(ppt[1].x!=ppt[2].x || ppt[1].y!=ppt[2].y)&&(ppt[1].x!=ppt[3].x || ppt[1].y!=ppt[3].y)&&(ppt[2].x!=ppt[3].x || ppt[2].y!=ppt[3].y))
{
POINT one,two;
one.x=ppt[0].x-ppt[1].x;
one.y=ppt[0].y-ppt[1].y;
two.x=ppt[2].x-ppt[3].x;
two.y=ppt[2].y-ppt[3].y;
flag = paralell (one,two) ;
if (flag)
return true;
else
{
one.x=ppt[0].x-ppt[3].x;
one.y=ppt[0].y-ppt[3].y;
two.x=ppt[1].x-ppt[2].x;
two.y=ppt[1].y-ppt[2].y;
flag = paralell (one,two) ;
if (flag)
return true;
else
{
one.x=ppt[0].x-ppt[2].x;
one.y=ppt[0].y-ppt[2].y;
two.x=ppt[1].x-ppt[3].x;
two.y=ppt[1].y-ppt[3].y;
flag = paralell (one,two) ;
return flag;
}
}
}
else
return false;
else
return false;
}
POINT Figure_contour::point_search () const
{
POINT one,two,point1;
double k,l=0;
POINT point;
one.x=ppt[0].x-ppt[2].x;
one.y=ppt[0].y-ppt[2].y;
two.x=ppt[1].x-ppt[3].x;
two.y=ppt[1].y-ppt[3].y;
if (one.x!=0)
{
double u;
k=(-1)*(one.y)/double(one.x);
u=(-1)*((two.x*k) + two.y);
point1.x=ppt[1].x-ppt[0].x;
point1.y=ppt[1].y-ppt[0].y;
point1.y=point1.x*k + point1.y;
l=(point1.y/u);
point.x=ppt[1].x+l*two.x;
point.y=ppt[1].y+l*two.y;
}
else
{
l=(ppt[1].x-ppt[0].x)/double (-two.x);
point.x=ppt[1].x+l*two.x;
point.y=ppt[1].y+l*two.y;
}
return point;}
std::ifstream& operator>>(std::ifstream& infile,Figure_contour &p)
{
POINT ppt[4];
for (int i=0;i<4;i++)
infile >> p.ppt[i].x >> p.ppt[i].y;
infile>>p.R_l>>p.G_l>>p.B_l;
infile>>p.pixel_border;
return infile;
}
Figure_contour::Figure_contour ()
{
this->Set_Pen(RGB(0,255,0));
this->Set_Border(1);
POINT ppt1[]={{10,10},{10,20},{20,20},{20,10}};
this->Set_koord(ppt1);
}
Defenition_paint.cpp
#include "Paint.h"
void Paint::Set_Brush (COLORREF rgb)
{
this->R_B=GetRValue(rgb);
this->G_B=GetGValue(rgb);
this->B_B=GetBValue(rgb);
}
void Paint::Set_Zaliv (COLORREF rgb)
{
this->R_Z=GetRValue(rgb);
this->G_Z=GetGValue(rgb);
this->B_Z=GetBValue(rgb);
}
COLORREF Paint::Get_Brush () const
{
COLORREF rgb=RGB(this->R_B,this->G_B,this->B_B);
return rgb;
}
COLORREF Paint::Get_Zaliv () const
{
COLORREF rgb=RGB(this->R_Z,this->G_Z,this->B_Z);
return rgb;
}
Defenition_Shaded_figure.cpp
#include "Shaded_figure.h"
void Shaded_figure::draw (HDC hdc,HWND hwnd) const
{
Figure_contour::draw(hdc,hwnd);
this->ris(hdc);
}
void Shaded_figure::lead (std::string enter)
{
std::ifstream infile;
infile.open(enter);
lead_f(infile);
infile.close();
}
void Shaded_figure::lead_f (std::ifstream& infile)
{
Figure_contour::lead_f(infile);
infile>>R_Z>>G_Z>>B_Z;
infile>>R_B>>G_B>>B_B;
}
void Shaded_figure::save_f (std::ofstream& infile)
{
Figure_contour::save_f(infile);
infile<<R_Z<<" "<<G_Z<<" "<<B_Z<<"\n";
infile<<R_B<<" "<<G_B<<" "<<B_B<<"\n";
}
void Shaded_figure::save (std::string enter)
{
std::ofstream infile;
infile.open(enter);
save_f(infile);
infile.close();
}
void Shaded_figure::smeish (POINT enter,HDC hdc,HWND hwnd)
{
HBRUSH hWhiteBrush=GetStockBrush(WHITE_BRUSH);
HPEN hWhitePen=CreatePen(PS_SOLID,this->pixel_border,RGB(255,255,255));
HPEN hOldPen=SelectPen(hdc,hWhitePen);
HBRUSH hOldBrush=SelectBrush(hdc,hWhiteBrush);
Polygon(hdc,ppt,4);
POINT point_s=this->point_search();
FloodFill(hdc,point_s.x,point_s.y,RGB(0,0,0));
SelectBrush(hdc,hWhiteBrush);
for (int i=0;i<4;i++)
{
ppt[i].x=ppt[i].x+enter.x;
ppt[i].y=ppt[i].y+enter.y;
}
this->draw(hdc,hwnd);
this->ris(hdc);
}
bool Shaded_figure::ris(HDC hdc) const
{
HBRUSH kist = CreateSolidBrush (RGB(R_B,G_B,B_B));
POINT point= Figure_contour::point_search();
HBRUSH hOldBrush=SelectBrush (hdc,kist);
BOOL bxt=FloodFill(hdc,point.x,point.y,RGB(R_Z,G_Z,B_Z));
SelectBrush(hdc,hOldBrush);
DeleteBrush(kist);
return bxt;
}
std::ifstream& operator>>(std::ifstream& infile,Shaded_figure &p)
{
for (int i=0;i<4;i++)
infile >> p.ppt[i].x >> p.ppt[i].y;
infile>>p.R_l>>p.G_l>>p.B_l;
infile>>p.pixel_border;
infile>>p.R_Z>>p.G_Z>>p.B_Z;
infile>>p.R_B>>p.G_B>>p.B_B;
return infile;
}
Shaded_figure::Shaded_figure()
:Figure_contour()
{
this->Set_Brush(RGB(255,255,255));
this->Set_Zaliv(RGB(0,255,0));
}
Defenition_Combined_figure.cpp
#include "Combined_figure.h"
bool Combined_figure::lie () const
{
bool flag=true;
POINT point1,point2;
point1=point_search();
POINT ppt1[4],ppt2[4];
second.Get_koord(ppt2);
double plosh1=0,plosh2=0;
plosh1=Square(point1);
for (int i=0;i<4&&flag;i++)
if (!(plosh1<Square(ppt2[i])+0.0001&&plosh1>Square(ppt2[i])-0.0001))
flag=false;
return flag;
}
double Combined_figure::Square (POINT point) const
{
double square=0;
double side_vnut[4],side_vnesh[4];
side_vnut[0]=sqrt( double (((ppt[0].x-point.x)*(ppt[0].x-point.x)+(ppt[0].y-point.y)*(ppt[0].y-point.y))));
side_vnut[1]=sqrt( double (((ppt[1].x-point.x)*(ppt[1].x-point.x)+(ppt[1].y-point.y)*(ppt[1].y-point.y))));
side_vnut[2]=sqrt( double (((ppt[2].x-point.x)*(ppt[2].x-point.x)+(ppt[2].y-point.y)*(ppt[2].y-point.y))));
side_vnut[3]=sqrt( double (((ppt[3].x-point.x)*(ppt[3].x-point.x)+(ppt[3].y-point.y)*(ppt[3].y-point.y))));
side_vnesh[0]=sqrt( double (((ppt[0].x-ppt[1].x)*(ppt[0].x-ppt[1].x)+(ppt[0].y-ppt[1].y)*(ppt[0].y-ppt[1].y))));
side_vnesh[1]=sqrt( double (((ppt[1].x-ppt[2].x)*(ppt[1].x-ppt[2].x)+(ppt[1].y-ppt[2].y)*(ppt[1].y-ppt[2].y))));
side_vnesh[2]=sqrt( double (((ppt[2].x-ppt[3].x)*(ppt[2].x-ppt[3].x)+(ppt[2].y-ppt[3].y)*(ppt[2].y-ppt[3].y))));
side_vnesh[3]=sqrt( double (((ppt[3].x-ppt[0].x)*(ppt[3].x-ppt[0].x)+(ppt[3].y-ppt[0].y)*(ppt[3].y-ppt[0].y))));
double p=(side_vnut[0]+side_vnut[1]+side_vnesh[0])/2.0;
square = sqrt(p*(p-side_vnut[0])*(p-side_vnut[1])*(p-side_vnesh[0]));
p=(side_vnut[1]+side_vnut[2]+side_vnesh[1])/2.0;
square = sqrt(p*(p-side_vnut[1])*(p-side_vnut[2])*(p-side_vnesh[1]))+square;
p=(side_vnut[2]+side_vnut[3]+side_vnesh[2])/2.0;
square = sqrt(p*(p-side_vnut[2])*(p-side_vnut[3])*(p-side_vnesh[2]))+square;
p=(side_vnut[3]+side_vnut[0]+side_vnesh[3])/2.0;
square = sqrt(p*(p-side_vnut[3])*(p-side_vnut[0])*(p-side_vnesh[3]))+square;
return square;
}
void Combined_figure::draw(HDC hdc,HWND hwnd) const
{
if (lie())
{
Shaded_figure::draw(hdc,hwnd);
second.draw(hdc,hwnd);
}
else
throw 3;
}
std::ifstream& operator>>(std::ifstream& infile,Combined_figure &p)
{
POINT ppt[4];
for (int i=0;i<4;i++)
infile >> p.ppt[i].x >> p.ppt[i].y;
infile>>p.R_l>>p.G_l>>p.B_l;
infile>>p.pixel_border;
infile>>p.R_Z>>p.G_Z>>p.B_Z;
infile>>p.R_B>>p.G_B>>p.B_B;
infile>>p.second;
return infile;
}
Combined_figure::Combined_figure()
: Shaded_figure()
{
}
void Combined_figure::smeish (POINT enter,HDC hdc,HWND hwnd)
{
Shaded_figure::smeish(enter,hdc,hwnd);
POINT ppt2[4];
second.Get_koord(ppt2);
for (int i=0;i<4;i++)
{
ppt2[i].x=ppt2[i].x+enter.x;
ppt2[i].y=ppt2[i].y+enter.y;
}
second.Set_koord(ppt2);
second.draw(hdc,hwnd);
}
void Combined_figure::save (std::string enter)
{
std::ofstream infile;
infile.open(enter);
save_f(infile);
infile.close();
}
void Combined_figure::save_f (std::ofstream& infile)
{
Shaded_figure::save_f(infile);
second.save_f(infile);
}
void Combined_figure::lead (std::string enter) ///
{
std::ifstream infile;
infile.open(enter);
lead_f(infile);
infile.close();
}
void Combined_figure::lead_f (std::ifstream& infile) ///
{
Shaded_figure::lead_f(infile);
second.lead_f(infile);
}
binary_tree.h
#include <fstream>
#include <windowsX.h>
#include <windows.h>
#include "Combined_figure.h"
template <class T>struct spis_t
{
spis_t<T> *next;
const T* elem;
};
template <class T> struct spis_t2
{
spis_t2<T> *next;
T elem;
};
template <class T> class binary_tree
{
private:
struct binary_t
{
binary_t* right;
binary_t* left;
int key;
T elem;
};
binary_t* top;
void del_pr(binary_t* d);
void del_put1(int key,binary_t** enter,spis_t2<T>** resoult);
void del_el (binary_t **elem,spis_t2<T>** enter,int key);
void pram_ob(binary_t *elem,spis_t<T> **resoult);
void pram_ob_data(binary_t *elem,std::ofstream& fil);
public:
binary_tree();
void input(T& elem,int key);
spis_t<T>* output(int key);
spis_t<T>* print_all();
spis_t2<T>* del_put(int key);
void save_data(const char* name);
void lead_data(const char* name);
~binary_tree();
};
template <class T> binary_tree<T>::binary_tree ()
{
top = NULL;
}
template <class T> void binary_tree<T>::input(T& elem,int key)
{
bool flag=true;
binary_t *prom;
prom=NULL;
if (top==NULL)
{
top=new binary_t;
top->elem=elem;
top->key=key;
top->right=NULL;
top->left=NULL;
}
else
{
prom=top;
while (flag)
if (prom->key > key)
{
if (prom->left==NULL)
{
flag=false;
prom->left=new binary_t;
prom->left->elem=elem;
prom->left->key=key;
prom->left->right=NULL;
prom->left->left=NULL;
}
else
prom=prom->left;
}
else
if (prom->right==NULL)
{
flag=false;
prom->right=new binary_t;
prom->right->elem=elem;
prom->right->key=key;
prom->right->right=NULL;
prom->right->left=NULL;
}
else
prom=prom->right;
}
}
template <class T> spis_t<T>* binary_tree<T>::output(int key)
{
if (top==NULL)
return NULL;
else
{
binary_t *prom;
prom = top;
spis_t<T>* top_s,*sredn;
top_s=NULL;
bool flag=true;
while (flag)
if (prom->key==key)
{
if (top_s==NULL)
{
top_s=new spis_t<T>;
top_s->elem=&(prom->elem);
top_s->next=NULL;
sredn=top_s;
}
else
{
sredn->next=new spis_t<T>;
sredn->next->elem=&(prom->elem);
sredn->next->next=NULL;
sredn=sredn->next;
}
if (prom->right!=NULL)
prom=prom->right;
else
{
flag=false;
return top_s;
}
}
else
if(prom->key > key)
if (prom->left!=NULL)
prom=prom->left;
else
{
flag=false;
return top_s;
}
else
if (prom->right!=NULL)
prom=prom->right;
else
{
flag=false;
return top_s;
}
}
}
template <class T> void binary_tree<T>::del_pr(binary_t* d)
{
if (d!=NULL)
{this->del_pr(d->left);this->del_pr(d->right);delete d;}
}
template <class T> void binary_tree<T>::del_el (binary_t **elem,spis_t2<T>** enter,int key)
{
binary_t *elem2;
elem2=NULL;
if ((*elem)->right==NULL)
{
if ((*elem)->left!=NULL)
{
elem2=(*elem)->left;
(*elem)->elem=(*elem)->left->elem;
(*elem)->key=(*elem)->left->key;
(*elem)->right=(*elem)->left->right;
(*elem)->left=(*elem)->left->left;
delete elem2;
}
else
{
elem2=*elem;
*elem=NULL;
delete elem2;
}
}
else
{
if ((*elem)->right->left==NULL)
{
elem2=(*elem)->right;
(*elem)->elem=(*elem)->right->elem;
(*elem)->key=(*elem)->right->key;
(*elem)->left=(*elem)->right->left;
(*elem)->right=(*elem)->right->right;
delete elem2;
}
else
{
(*elem)->elem=(*elem)->right->left->elem;
(*elem)->key=(*elem)->right->left->key;
if ((*elem)->right->left->key!=key)
del_put1(key,&((*elem)->right->left),&(*enter));
del_el(&((*elem)->right->left),&(*enter),key);
}
}
}
template <class T> spis_t2<T>* binary_tree<T>::del_put(int key)
{
spis_t2<T>* resoult;
resoult=NULL;
del_put1(key,&top,&resoult);
return resoult;
}
template <class T> void binary_tree<T>::del_put1(int key,binary_t** enter,spis_t2<T>** resoult)
{
binary_t *prom,*pred_l,*pred_r;
prom = *enter;
pred_l=NULL;
pred_r=NULL;
spis_t2<T> *sredn;
bool flag=true;
while (flag)
if (prom!=NULL)
if (prom->key==key)
{
if (*resoult==NULL)
{
*resoult=new spis_t2<T>;
(*resoult)->elem=prom->elem;
(*resoult)->next=NULL;
}
else
{
sredn = new spis_t2<T>;
sredn->elem=prom->elem;
sredn->next=*resoult;
(*resoult)=sredn;
}
if (prom==*enter)
{
del_el(&(*enter),&(*resoult),key);
prom=*enter;
}
else
{
del_el(&prom,&(*resoult),key);
if (prom==NULL)
if (pred_l==NULL)
pred_r->right=NULL;
else
pred_l->left=NULL;
}
}
else
if(prom->key > key)
if (prom->left!=NULL)
{
pred_l=prom;
pred_r=NULL;
prom=prom->left;
}
else
flag=false;
else
if (prom->right!=NULL)
{
pred_l=NULL;
pred_r=prom;
prom=prom->right;
}
else
flag=false;
else
flag=false;
}
template <class T> binary_tree<T>::~binary_tree()
{
del_pr(top);
top=NULL;
}
template <class T> void binary_tree<T>::pram_ob(binary_t *elem,spis_t<T> **resoult)
{
if (elem!=NULL)
{
spis_t<T> *prom; prom=new spis_t<T>;
prom->elem=&(elem->elem);
prom->next=*resoult;
*resoult=prom;
pram_ob(elem->left,&(*resoult));
pram_ob(elem->right,&(*resoult));
}
}
template <class T> spis_t<T>* binary_tree<T>::print_all()
{
spis_t<T>* resoult;
resoult=NULL;
pram_ob(top,&resoult);
return resoult;
}
template <class T> void binary_tree<T>::pram_ob_data(binary_t *elem,std::ofstream& infile)
{
if (elem!=NULL)
{
infile<<elem->key<<"\n";
elem->elem.save_f(infile);
pram_ob_data(elem->left,infile);
pram_ob_data(elem->right,infile);
}
}
template <class T> void binary_tree<T>::save_data(const char * name)
{
std::ofstream fil;
fil.open(name);
pram_ob_data(top,fil);
fil.close();
}
template <class T> void binary_tree<T>::lead_data(const char * name)
{
std::ifstream infile;
infile.open(name);
T enter;
int key;
infile>>key;
while (infile)
{
enter.lead_f(infile);
this->input(enter,key);
infile>>key;
}
infile.close();
}
program.cpp
#include <iostream>
#include <windows.h>
#include <conio.h>
#include "binary_tree.h"
void one_program (HWND hwnd,HDC hdc,std::ifstream& in_file,std::ifstream& in_file2)
{
binary_tree<Figure_contour> top;
int key=0;
Figure_contour gran;
spis_t<Figure_contour> *start;
start=NULL;
in_file>>key;
while (in_file)
{
in_file>>gran;
top.input(gran,key);
in_file>>key;
}
int y;
in_file2>>y;
start=top.output(y);
while (start!=NULL)
{
start->elem->draw(hdc,hwnd);
start=start->next;
}
}
void two_program (HWND hwnd,HDC hdc,std::ifstream& in_file,std::ifstream& in_file2)
{
binary_tree<Shaded_figure> top;
int key=0;
Shaded_figure gran;
spis_t2<Shaded_figure> *start;
start=NULL;
in_file>>key;
while (in_file)
{
in_file>>gran;
top.input(gran,key);
in_file>>key;
}
int y;
in_file2>>y;
start=top.del_put(y);
while (start!=NULL)
{
start->elem.draw(hdc,hwnd);
start=start->next;
}
if (top.del_put(y))
std::cout<<"Not category";
}
void three_program (HWND hwnd,HDC hdc,std::ifstream& in_file)
{
binary_tree<Figure_contour> top;
int key=0;
Figure_contour gran;
spis_t<Figure_contour> *start;
start=NULL;
in_file>>key;
while (in_file)
{
in_file>>gran;
top.input(gran,key);
in_file>>key;
}
start=top.print_all();
while (start!=NULL)
{
start->elem->draw(hdc,hwnd);
start=start->next;
}
}
void four_program (HWND hwnd,HDC hdc,std::ifstream& in_file)
{
binary_tree<Combined_figure> top,top2;
int key=0;
Combined_figure gran;
spis_t<Combined_figure> *start;
start=NULL;
in_file>>key;
while (in_file)
{
in_file>>gran;
top.input(gran,key);
in_file>>key;
}
top.save_data("resoult.txt");
top2.lead_data("resoult.txt");
start=top.print_all();
while (start!=NULL)
{
start->elem->draw(hdc,hwnd);
start=start->next;
}
}
void menu (HWND hwnd,HDC hdc)
{
int l = 1;
std::ifstream in_file,in_file2,in_file3;
std::cout<<"1-Draw figures contour with a given key(search)\n"
<<"2-Draw figures shaded with a given key(delete)\n"
<<"3-Draw figures combined figure(print all)\n"
<<"4-Draw figures contour(save,lead)\n"
<<std::endl;
l=getchar();
in_file.open("1_3.txt");
in_file2.open("2.txt");
switch (l)
{
case '1':{one_program(hwnd,hdc,in_file,in_file2);};break;
case '2':{two_program(hwnd,hdc,in_file,in_file2);};break;
case '3':{three_program(hwnd,hdc,in_file2);};break;
case '4':{four_program(hwnd,hdc,in_file);};break;
}
}
void main()
{
try
{
HWND hwnd=FindWindowA("Notepad",NULL);
HDC hdc=GetDC(hwnd);
menu(hwnd,hdc);
ReleaseDC(hwnd,hdc);
getch();
}
catch (int i)
{
if (i==1)
{
std::cout<<"error gran";
}
else
{
std::cout<<"error vlog";
}
getch();
}
}