# arrow class [fltk]

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 13 Exercise 3
Using GUI library called FLTK (Fast Light Tool Kit, “full tick”).

```Output:

```

[code language=”cpp”]
// Philipp Siedler
// Bjarne Stroustrup’s PP
// Chapter 13 Exercise 3

#define _USE_MATH_DEFINES
#include "Simple_window.h"
#include "Graph.h"
#include <cmath>
using namespace Graph_lib;

double pointVecMag(Point vec) {
return sqrt(pow(vec.x, 2) + pow(vec.y, 2));;
}

struct MyArrow : public Shape
{
MyArrow(Point start, Point end, bool s, bool e, int size)
:start(start), end(end), s(s), e(e), size(size)
{
if (s) {
//end-start vector: c
c = Point(end.x – start.x, end.y – start.y);
cMag = pointVecMag(c);
cUnit = Point(c.x / cMag * size, c.y / cMag * size);
cTrans = Point(cUnit.x, cUnit.y);

cPerp = Point(-cTrans.y, cTrans.x);
arrowhead01 = Point(start.x + cPerp.x + cTrans.x, start.y + cPerp.y + cTrans.y);
arrowhead02 = Point(start.x – cPerp.x + cTrans.x, start.y – cPerp.y + cTrans.y);
}
if (e) {
//start-end vector: d
d = Point(start.x – end.x, start.y – end.y);
dMag = pointVecMag(d);
dUnit = Point(d.x / dMag * size, d.y / dMag * size);
dTrans = Point(dUnit.x, dUnit.y);

dPerp = Point(-dTrans.y, dTrans.x);
arrowhead03 = Point(end.x + dPerp.x + dTrans.x, end.y + dPerp.y + dTrans.y);
arrowhead04 = Point(end.x – dPerp.x + dTrans.x, end.y – dPerp.y + dTrans.y);
}
};

void draw_lines() const;

private:
//Line
Point start;
Point end;

Point c;
Point cUnit;
Point cTrans;
Point cPerp;
double cMag;

Point d;
Point dUnit;
Point dTrans;
Point dPerp;
double dMag;

bool s;
bool e;
int size;
};

void MyArrow::draw_lines() const{

if (color().visibility()) {
//Line
fl_line(start.x,start.y, end.x, end.y);
if (s) {
}
if (e) {
}
}
}

int main()
try
{
Point tl(100, 100);
Simple_window win(tl, 600, 400, "Simple Window");

MyArrow ma(Point(100, 150), Point(200, 250), true, true, 10);
ma.set_color(Color::red);

win.attach(ma);
win.wait_for_button();
}
catch (exception& e) {
cout << e.what() << endl;
return 1;
}
catch (…) {
cout << "Exiting" << endl;
return 2;
}
[/code]