I have already wasted three questions on this and all that i
(I have already wasted three questions on this and all that is being done is copying and pasting my own code with deletions thereof. PLEASE MAKE SURE IT COMPILES AND INCLUDE A SCREEN SHOT OF OUTPUT.HTML SO I CAN SEE THE COMPLETED SHEET. PLEASE FOLLOW DIRECTIONS!)
Hex sheet in C++
Objective is to create a \"sheet\" of hexagons that is 13 hexes horizontal by 11 hexes vertical.
There are two files provided that provide the drawing library (Code 1), along with a sample program that draws a single hexagon (Code 2).
Download hexagon.h file here -> https://www.dropbox.com/s/67ojnylq567ge2s/hexagon.h?dl=0
To compile:
g++ -std=c++11 draw_hexes.cpp hexagon.cpp -o drawsheet
To run:
./drawsheet >output.html
Open output.html in your browser to see the results.
As with the original hexagon problem, there are two goals to strive for: creating the first solution, and creating a solution that uses the fewest number of \"constructs\". Constructs are defined as:
Each function call to one of the four functions provided
Each function call to a function you have written
Each while, do-while, or for-loop
Each if-statement
Code 1:
// Hexagon.cpp
// Version 2.0
#include \"hexagon.h\"
#include
#include
#include
#include
#include
#include
#include
#include //for: atexit
using namespace std;
const double POINTS_PER_INCH=96.0;
struct Point {
double x;
double y;
double inches;
double deg;
Point(double a, double b, double c, double in) : x(a), y(b), deg(c), inches(in){}
};
const double Pi=atan(1)*4;
const double DegPerRad=57.2957795;
static Point currentPoint(0.0,0.0,0.0/DegPerRad, 0.25);
static std::vector v;
void moveForward(double inches)
{
double x,y;
x=cos(currentPoint.deg)*POINTS_PER_INCH*inches;
y=-sin(currentPoint.deg)*POINTS_PER_INCH*inches;
v.push_back(Point(x,y,currentPoint.deg, inches));
currentPoint.x=x;
currentPoint.y=y;
}
void moveBackward(double inches)
{
double x,y;
x=cos(currentPoint.deg+Pi)*POINTS_PER_INCH*inches; //Add Pi Radians to reverse direction
y=-sin(currentPoint.deg+Pi)*POINTS_PER_INCH*inches; //Add Pi Radians to reverse direction
v.push_back(Point(x,y,currentPoint.deg, inches));
currentPoint.x=x;
currentPoint.y=y;
}
void turnRightBy(double deg)
{
currentPoint.deg=(currentPoint.deg-deg/DegPerRad);
}
void turnLeftBy(double deg)
{
currentPoint.deg=((currentPoint.deg+deg/DegPerRad));
}
static double ymax=0.0;//std::numeric_limits::min();
static double ymin=0.0;//std::numeric_limits::max();
static double xmax=0.0;//std::numeric_limits::min();
static double xmin=0.0;//std::numeric_limits::max();
double _yelem_min(double d, const Point& p)
{
double newsum=d+p.y;
ymin=(newsum < ymin) ? newsum : ymin;
return newsum;
}
double _yelem_max(double d, const Point& p)
{
double newsum=d+p.y;
ymax=(newsum > ymax) ? newsum : ymax;
return newsum;
}
double _xelem_min(double d, const Point& p)
{
double newsum=d+p.x;
xmin = (newsum < xmin) ? newsum : xmin;
return newsum;
}
double _xelem_max(double d, const Point& p)
{
double newsum=d+p.x;
xmax=(newsum > xmax) ? newsum : xmax;
return newsum;
}
static double verticalMarginInches=0.5*POINTS_PER_INCH;
static double horizontalMarginInches=0.5*POINTS_PER_INCH;
void printpage()
{
// A hack. Use this iterator to compute the summed minimum of each axis
std::accumulate(v.begin(), v.end(), 0.0, _yelem_min);
std::accumulate(v.begin(), v.end(), 0.0, _yelem_max);
std::accumulate(v.begin(), v.end(), 0.0, _xelem_min);
std::accumulate(v.begin(), v.end(), 0.0, _xelem_max);
double offx=0.0-xmin+horizontalMarginInches/2.0;
double offy=0.0-ymin+verticalMarginInches/2.0;
cout.precision(3);
cout << fixed;
cout << \"\" << endl;
cout << \"
\" << endl;
cout << \"Hexagon Challenge!
\" << endl;
cout << \"
\" << endl;
cout << \"\" << endl;
cout << \"
//starting point
cout << offx << \",\" << offy << \" \";
for(int j=0; j {
offx+=v[j].x;
offy+=v[j].y;
cout << offx << \",\" << offy << \" \";
}
cout << \'\\\"\' << endl;
cout << \"style=\\\"fill:white;stroke:black;stroke-width:2\\\" />\" << endl;
cout << \"\" << endl;
cout << \"\" << endl;
cout << \"\" << endl;
}
class Wrapper {
public:
Wrapper() {atexit(printpage);}
};
static Wrapper w; //force the atexit function to be set up
Code 2:
// draw_hexes.cpp
#include\"hexagon.h\"
int main()
{
for(int i=0; i<6; ++i)
{
moveForward();
turnRightBy(60);
}
return 0;
}
Solution
#include \"hexagon.h\"
#include
#include
#include
#include //for: atexit
using namespace std;
const double POINTS_PER_INCH=96.0;
struct Point {
double x;
double y;
double inches;
double deg;
Point(double a, double b, double c, double in) : x(a), y(b), deg(c), inches(in){}
};
const double Pi=atan(1)*4;
const double DegPerRad=57.2957795;
static Point currentPoint(0.0,0.0,0.0/DegPerRad, 0.25);
static std::vector v;
void moveForward(double inches)
{
double x,y;
x=cos(currentPoint.deg)*POINTS_PER_INCH*inches;
y=-sin(currentPoint.deg)*POINTS_PER_INCH*inches;
v.push_back(Point(x,y,currentPoint.deg, inches));
currentPoint.x=x;
currentPoint.y=y;
}
void moveBackward(double inches)
{
double x,y;
x=cos(currentPoint.deg+Pi)*POINTS_PER_INCH*inches; //Add Pi Radians to reverse direction
y=-sin(currentPoint.deg+Pi)*POINTS_PER_INCH*inches; //Add Pi Radians to reverse direction
v.push_back(Point(x,y,currentPoint.deg, inches));
currentPoint.x=x;
currentPoint.y=y;
}
void turnRightBy(double deg)
{
currentPoint.deg=(currentPoint.deg-deg/DegPerRad);
}
void turnLeftBy(double deg)
{
currentPoint.deg=((currentPoint.deg+deg/DegPerRad));
}
static double ymax=0.0;//std::numeric_limits::min();
static double ymin=0.0;//std::numeric_limits::max();
static double xmax=0.0;//std::numeric_limits::min();
static double xmin=0.0;//std::numeric_limits::max();
double _yelem_min(double d, const Point& p)
{
double newsum=d+p.y;
ymin=(newsum < ymin) ? newsum : ymin;
return newsum;
}
double _yelem_max(double d, const Point& p)
{
double newsum=d+p.y;
ymax=(newsum > ymax) ? newsum : ymax;
return newsum;
}
double _xelem_min(double d, const Point& p)
{
double newsum=d+p.x;
xmin = (newsum < xmin) ? newsum : xmin;
return newsum;
}
double _xelem_max(double d, const Point& p)
{
double newsum=d+p.x;
xmax=(newsum > xmax) ? newsum : xmax;
return newsum;
}
static double verticalMarginInches=0.5*POINTS_PER_INCH;
static double horizontalMarginInches=0.5*POINTS_PER_INCH;
void printpage()
{
// A hack. Use this iterator to compute the summed minimum of each axis
std::accumulate(v.begin(), v.end(), 0.0, _yelem_min);
std::accumulate(v.begin(), v.end(), 0.0, _yelem_max);
std::accumulate(v.begin(), v.end(), 0.0, _xelem_min);
std::accumulate(v.begin(), v.end(), 0.0, _xelem_max);
double offx=0.0-xmin+horizontalMarginInches/2.0;
double offy=0.0-ymin+verticalMarginInches/2.0;
cout.precision(3);
cout << fixed;
cout << \"\" << endl;
cout << \"
\" << endl;
cout << \"Hexagon Challenge!
\" << endl;
cout << \"
\" << endl;
cout << \"\" << endl;
cout << \"
//starting point
cout << offx << \",\" << offy << \" \";
for(int j=0; j {
offx+=v[j].x;
offy+=v[j].y;
cout << offx << \",\" << offy << \" \";
}
cout << \'\\\"\' << endl;
cout << \"style=\\\"fill:white;stroke:black;stroke-width:2\\\" />\" << endl;
cout << \"\" << endl;
cout << \"\" << endl;
cout << \"\" << endl;
}
class Wrapper {
public:
Wrapper() {atexit(printpage);}
};
static Wrapper w; //force the atexit function to be set up
Code 2:
// draw_hexes.cpp
#include\"hexagon.h\"
int main()
{
for(int i=0; i<6; ++i)
{
moveForward();
turnRightBy(60);
}
return 0;
}





