Commit 670a600f authored by Hans Buchmann's avatar Hans Buchmann

6-cia/rc/geo2d-bb.cc

 class Line
exams/2020-12-03/bb
 some solutions
parent a05c5929
......@@ -24,8 +24,20 @@ class Point
double yc; //y-coordinate
};
// implementation
//-------------------------------------------------- Line
// declaration
class Line
{
public:
Line(const Point& p0,const Point& p1);
~Line();
private:
Point p; //by value
Point q; //by value
};
//------------------------------------------------- Point
// implementation
Point::Point(double x,double y)
:xc(x),yc(y) //init list
//xc=x;yc=y
......@@ -61,23 +73,31 @@ double Point::distance(const Point& other) const
other.yc - yc);
}
//-------------------------------------------------- Line
// implementation
Line::Line(const Point& p0,const Point& p1)
:p(p0) //p by value copy constructor
,q(p1) //q by value copy constructor
{
std::cout<<"constructor Line\n";
}
/*
no copy constructor
constructor Point 5,7
constructor Point 8,11
d=5
destructor Point 8,11
destructor Point 5,7
*/
Line::~Line()
{
std::cout<<"destructor Line\n";
}
//--------------------------- use case
int main(int argc,char** args)
{
Point p(5, 7);
Point q(8,11);
auto d=p.distance(q); //other = c++ reference to q
std::cout<<"d="<<d<<"\n";
Point p(5, 7); //instance birth p constructor Point 5,7
Point q(8,11); //instance birth q constructor Point 8,11
Line l(p,q); //copy constructor Point 5,7
//copy constructor Point 8,11
//constructor Line
return 0;
}
} //death l destructor Line
//death l.q destructor Point 8,11
//death l.p destructor Point 5,7
//death q destructor Point 8,11
//death p destructor Point 5,7
......@@ -4,11 +4,11 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- see http://www.w3.org/TR/SVG11/ -->
<circle cx="100" cy="100" r="50" fill="white" stroke-width="5" stroke="green"/>
<line x1="0" y1="0" x2="150" y2="100"
stroke-width="20" stroke="yellow"></line>
<line x1="150" y1="100" x2="300" y2="400"
stroke-width="5" stroke="red"></line>
<circle cx="100" cy="100" r="50" stroke="green"/>
<rect x="100" y="200" width="200" height="50"/>
<rect x="100" y="200" width="200" height="50" fill="white" stroke="blue"/>
</svg>
......@@ -15,7 +15,36 @@ static unsigned PI=(1<<31);
static const SCALE SC=
{
use program cos-sin-table.cc to generate the table
/* 0 */ 5.41196100146197012215e-01,
/* 1 */ 5.09795579104159179984e-01,
/* 2 */ 5.02419286188155678197e-01,
/* 3 */ 5.00602998235196383625e-01,
/* 4 */ 5.00150636020651018221e-01,
/* 5 */ 5.00037651915547720627e-01,
/* 6 */ 5.00009412535887820539e-01,
/* 7 */ 5.00002353106286046014e-01,
/* 8 */ 5.00000588274841284431e-01,
/* 9 */ 5.00000147068602074363e-01,
/* 10 */ 5.00000036767143773986e-01,
/* 11 */ 5.00000009191785554918e-01,
/* 12 */ 5.00000002297946388730e-01,
/* 13 */ 5.00000000574486569427e-01,
/* 14 */ 5.00000000143621670112e-01,
/* 15 */ 5.00000000035905389772e-01,
/* 16 */ 5.00000000008976375199e-01,
/* 17 */ 5.00000000002244093800e-01,
/* 18 */ 5.00000000000561106717e-01,
/* 19 */ 5.00000000000140332190e-01,
/* 20 */ 5.00000000000035083048e-01,
/* 21 */ 5.00000000000008770762e-01,
/* 22 */ 5.00000000000002220446e-01,
/* 23 */ 5.00000000000000555112e-01,
/* 24 */ 5.00000000000000222045e-01,
/* 25 */ 5.00000000000000111022e-01,
/* 26 */ 5.00000000000000000000e-01,
/* 27 */ 5.00000000000000000000e-01,
/* 28 */ 5.00000000000000000000e-01,
/* 29 */ 5.00000000000000000000e-01,
};
void cos_sin8(unsigned alfa,double* c,double* s) //0<=alfa<pi/4
......@@ -54,7 +83,34 @@ void cos_sin8(unsigned alfa,double* c,double* s) //0<=alfa<pi/4
//cos_sin{
//your code
void cos_sin(unsigned alfa,double* c,double* s)
{
if (alfa<PI/4)
{
cos_sin8(alfa,c,s);
return;
}
//PI/4<=alfa<2*PI
if (alfa<PI/2)
{
auto a=PI/2-alfa; //0<=a<PI/4
cos_sin8(a,s,c);
return;
}
//PI/2<=alfa<2*PI
if (alfa<PI)
{
auto a=alfa-PI/2; //0<=a<PI/2
cos_sin(a,s,c);
*c=-*c;
return;
}
//PI<=alfa<2*PI
auto a=alfa-PI; //0<=a<PI
cos_sin(a,c,s);
*c=-*c;
*s=-*s;
}
//cos_sin}
//****** DO NOT CHANGE BELOW THIS LINE
......
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