Commit 62d60730 authored by Hans Buchmann's avatar Hans Buchmann

Point all public very bad

parent a5cde559
......@@ -6,6 +6,62 @@
#include <cmath>
#include <fstream>
//---------------------------- class SVG
class SVG //Singleton
{
public:
static void line(double x0,double y0,
double x1,double y1);
static void dot(double x0,double y0,double r=3);
// |default radius
private:
static SVG svg; // the Singleton declared
static const char File[];
std::ofstream out;
SVG();
~SVG();
};
//------------------- implementation SVG(
const char SVG::File[]="geo2d.svg";
SVG SVG::svg; //constructor defined and initialized
SVG::SVG()
:out(File)
{
out<<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\"\n"
" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
"<svg xmlns=\"http://www.w3.org/2000/svg\"\n"
" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
"<g stroke=\"black\">\n";
}
SVG::~SVG()
{
std::cout<<"figure in file '"<<File<<"'\n";
out<<"\n</g>\n"
"</svg>\n";
}
void SVG::line(double x0,double y0,double x1,double y1)
{
svg.out<<"<line x1=\""<<x0<<"\" "
"y1=\""<<y0<<"\" "
"x2=\""<<x1<<"\" "
"y2=\""<<y1<<"\"/>\n";
}
void SVG::dot(double x0,double y0,double r)
{
svg.out<<"<circle cx=\""<<x0<<"\" "
"cy=\""<<y0<<"\" "
"r=\""<<r<<"\"/>\n";
}
//------------------- implementation SVG)
//---------------------------------------------- Point
// declaration
class Point
......@@ -20,9 +76,10 @@ class Point
//other cannot be changed
static double distance(Point p,Point q);
private:
double xc; //x-coordinate
double yc; //y-coordinate
// private: Suende
void svg(); //draw the point
double xc; //x-coordinate
double yc; //y-coordinate
};
//----------------------------------------------- Line
......@@ -34,6 +91,7 @@ class Line
// |--------------|-------------- by C++ reference
~Line();
private:
void svg(); //draw the line
Point pp; //by value
Point qq; //by value
};
......@@ -45,7 +103,7 @@ Point::Point(double x,double y) //x,y parameter
:xc(x),yc(y) //init list:only for construtors
//xc=x,yc=y
{
std::cout<<"constructor of Point "<<xc<<","<<yc<<"\n";
svg();
}
Point::Point(const Point& other)
......@@ -59,6 +117,12 @@ Point::~Point()
std::cout<<"destructor of Point "<<xc<<","<<yc<<"\n";
}
void Point::svg()
{
// SVG::dot(xc,yc,3);
SVG::dot(xc,yc); //with default radius
}
double Point::distance(Point p,Point q) //is not a member of Point
{
return std::hypot(q.xc-p.xc,q.yc-p.yc);
......@@ -85,7 +149,7 @@ double Point::distance(const Point& other) const //is a member of Point
Line::Line(const Point& p,const Point& q)
:pp(p),qq(q) //copy constructor p->pp and copy constructo q->qq
{
std::cout<<"constructor Line\n";
svg();
}
Line::~Line()
......@@ -93,18 +157,16 @@ Line::~Line()
std::cout<<"destructor Line\n";
}
void Line::svg()
{
SVG::line(pp.xc,pp.yc, //x0,y0
qq.xc,qq.yc); //x1 y1
}
int main(int argc,char**args)
{
Point p(3,4); //constructor of Point 3,4
Point q(6,8); //constructor of Point 6,8
/*
copy constructor of Point 3,4 see pp by value
copy constructor of Point 6,8 see qq by value
*/
Point p(150,200); //constructor of Point 3,4
Point q(300,400); //constructor of Point 6,8
Line l(p,q); //constructor Line
return 0;
} //destructor Line
// destructor of Point 3,4
// destructor of Point 6,8
//destructor of Point 6,8
//destructor of Point 3,4
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment