class cube { public: cube(int s) { side=s; } void move(int x, int y, int z) { xcord = x; ycord = y; zcord = z; } bool interferes_with(cube c) { // uses xcord, ycord, and zcord. } private: int side; int xcord, ycord, zcord; };
move()
isn't implemented right.
xcord
, ycord
, and zcord
aren't defined until moved.
Make Sure Variables are Initialized
class cube{ public: cube(int s){ int myX = s; int myY = s; int myZ = s; } void move(int x, int y, int z){ // whatever } bool interferes_with(cube c){ // whatever } private: int myX, myY, myZ; };
$ g++ -g -ansi -pedantic -Wall -c game.cc In file included from game.cc:3: cube.h: In method cube::cube(int): cube.h:8: warning: unused variable int myZ cube.h:7: warning: unused variable int myY cube.h:6: warning: unused variable int myX
if (((xbeg >= c.xbeg) && (xbeg < c.xend) || (xend > c.xbeg) && (xend <= c.xend)) && ((ybeg >= c.ybeg) && (ybeg < c.yend) || (yend > c.ybeg) && (yend <= c.yend)) && ((zbeg >= c.zbeg) && (zbeg < c.zend) || (zend > c.zbeg) && (zend <= c.zend))) return true;
if ((c.a <= a && c.a >= d) || (c.d >= d && c.d <= a)) if ((c.b <= b && c.b >= e) || (c.e >= e && c.e <= b)) if ((c.r <= r && c.r > f) || (c.f >= f && c.f < r)) return 1;
if (((c.lOne >= lTwo) && (c.lOne <= lOne)) || ((c.lTwo >= lTwo) && (c.lTwo <= lOne))) flag1 = true; if (((c.bOne >= bTwo) && (c.bOne <= bOne)) || ((c.bTwo >= bTwo) && (c.bTwo <= bOne))) flag2 = true; if (((c.hOne > hTwo) && (c.hOne <= hOne)) || ((c.hTwo >= hTwo) && (c.hTwo < hOne))) flag3 = true;
return ((c.x_coorda > x_coordb && c.x_coordb < x_coorda) && (c.y_coorda > y_coordb && c.y_coordb < y_coorda) && (c.z_coorda > z_coordb && c.z_coordb < z_coorda));
// The problem statement says that "One cube interferes // with another if there exists some point p in the // environment such that p is part of both cubes." // Therefore, if the cubes touch they should interfere // unless we assume that a point on the edge of a cube // is not part of the cube. I will assume that this is // true so that there's no interference if the cube touch.
if (((c.lOne >= lTwo) && (c.lOne <= lOne)) || ((c.lTwo >= lTwo) && (c.lTwo <= lOne))) flag1 = true; if (((c.bOne >= bTwo) && (c.bOne <= bOne)) || ((c.bTwo >= bTwo) && (c.bTwo <= bOne))) flag2 = true; if (((c.hOne > hTwo) && (c.hOne <= hOne)) || ((c.hTwo >= hTwo) && (c.hTwo < hOne))) flag3 = true;
return ((c.x_coorda > x_coordb && c.x_coordb < x_coorda) && (c.y_coorda > y_coordb && c.y_coordb < y_coorda) && (c.z_coorda > z_coordb && c.z_coordb < z_coorda));
This page last modified on 3 July 2001.