I am trying to figure out how to find the axis of class Square's axis as shown below? But I've been trying for hours and still did not managed to solve it. Can someone with their high level expertise show me the ropes to do it? Because both center function call and axis function call in main() does call the same x() and y(), hence brought me to a state of confusion. I know the inheritance of square from circle is weird. But it is what my school wants. Note: Main() CANNOT be modified! Thanks!
Output:
Square::axis test failed
8.87627 0.284967
3.82567 0.958537
Tests passed: 50%
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
class Object
{
public:
private:
float d;
public:
Object(float n) : d(n){}
Object(){}
float depth() const
{
return d;
}
struct PointType
{
float x2;
float y2;
PointType( float x1, float y1) :x2(x1),y2(y1){}
PointType(){}
float x()
{
return x2;
}
float y()
{
return y2;
}
PointType center()
{
return *this;
}
};
struct VectorType
{
float tx;
float ty;
VectorType( float tx1, float ty1) :tx(tx1),ty(ty1){}
VectorType( ){}
};
virtual ~Object()
{}
};
class Point :public Object
{
private:
PointType mpoint;
public:
Point(const PointType& pt, float& y1) :Object(y1), mpoint(pt) {}
Point(const PointType& pt):mpoint(pt){}
Point(){}
Point center() const
{
return *this;
}
float x()
{
return mpoint.x2;
}
float y()
{
return mpoint.y2;
}
virtual ~Point(){}
};
class Circle : public Point
{
private:
Object::PointType m_pt;
float r;
public:
Circle(const PointType pts, float rad, float dep)
: Point(m_pt,dep),m_pt(pts),r(rad) {}
Circle(const PointType pts, float rad):m_pt(pts),r(rad){}
Circle(){}
float radius() const
{
return r;
}
Circle center() const
{
return *this;
};
float x()
{
return m_pt.x2;
}
float y()
{
return m_pt.y2;
}
};
class Square: public Circle
{
private:
Object::PointType s_pt;
Object::VectorType v_pt;
float a=getRadius();
public:
Square(const PointType spts,const VectorType vpts,float depth) :
Circle(spts,a,depth),s_pt(spts),v_pt(vpts){}
Square(const Object::PointType& spts, const VectorType vpts):s_pt(spts),v_pt(vpts){}
Square axis() const
{
return Square(s_pt,v_pt,getRadius());
}
Square center() const
{
return *this;
}
float radius() const
{
return a;
}
float getRadius() const
{
float rad= sqrt(v_pt.tx * v_pt.tx + v_pt.ty * v_pt.ty);
return rad;
}
float x() const
{
return s_pt.x2;
// v_pt.tx/radius();
}
float y() const
{
return s_pt.y2;
// v_pt.ty/radius();
}
};
const float EPSILON = 1e-5f;
bool is_near(float x, float y)
{
return std::abs(x - y) < EPSILON;
}
float frand()
{
return 10.0f * float(rand()) / float(RAND_MAX);
}
int main()
{
srand(unsigned(time(0)));
int count = 0;
int max_count = 0;
float x = frand();
float y = frand();
float sx = frand();
float sy = frand();
float depth = frand();
Square square(Square::PointType(x, y), Square::VectorType(sx, sy), depth);
if (is_near(square.center().x(), x) &&
is_near(square.center().y(), y))
{
++count;
}
else
{
std::cout << " - Square::center test failed" << std::endl;
}
++max_count;
float radius = std::sqrt(sx * sx + sy * sy);
if (is_near(square.axis().x(), sx / radius) &&
is_near(square.axis().y(), sy / radius))
{
++count;
}
else
{
std::cout << " - Square::axis test failed" << std::endl;
}
++max_count;
std::cout << square.axis().x()<< " " << sx / radius<<std::endl;
std::cout << square.axis().y()<< " " << sy / radius<<std::endl;
int result = static_cast<int>(
100.0f * static_cast<float>(count) / static_cast<float>(max_count) + 0.5f
);
std::cout << "Tests passed: " << result << "%" << std::endl;
return result;
}
Related
I am experimenting with lambda functions and managed to recreate a "get" functionality in C++. I can get the return value of a function without using parentheses. This is an example class, where I implement this:
using namespace std;
struct Vector2 {
float x;
float y;
float length = [&]()-> float {return sqrt(x * x + y * y); }();
float angle = [&]()-> float {return atan2(y, x); }();
Vector2() : x(0), y(0) {}
Vector2(float a, float b) : x(a), y(b) {}
~Vector2() {}
Vector2(Vector2& other) : x(other.x), y(other.y) {}
Vector2(Vector2&& other) = delete;
void operator =(Vector2&& other) noexcept{
x = other.x;
y = other.y;
}
};
int main()
{
Vector2 vec = Vector2(10, 17);
printf("%f\n%f\n%f\n%f\n", vec.x, vec.y, vec.length, vec.angle);
}
However, I am currently trying to also recreate the "set" functionality that C# has. But I'm failing. I tried to add this:
void angle = [&](float a)->void {
float l = length;
x = cos(a) * l;
y = sin(a) * l;
};
But am getting "Incomplete type is not allowed" error. I'm not sure if that's how it should look, even if I wasn't getting the error. Is it even possible to recreate the "set" functionality C# has in C++?
I know that I can just use a method SetAngle(float a){...}, but that's not really the point.
TL;DR: Don't
What you have isn't a getter, it's just a normal data member that's calculated once when the object is initialized.
In general, C++ doesn't support C#-style properties. The usual C++-style solution is to just use a pair of member functions (and maybe a data member, if you need to save the value separately), i.e.
struct Vector2 {
// ...
float length() const { return sqrt(x * x + y * y); }
void length(float l) {
float angle = angle();
float new_x = l * cos(angle);
float new_y = l * sin(angle);
x = new_x;
y = new_y;
}
// ...
};
You can get something close to a C#-style property, but you'll always run into edge-cases where they don't work perfectly. For example, here's something that will work in many cases:
template <typename T>
class Property
{
private:
std::function<T()> getter_;
std::function<void(const T&)> setter_;
public:
Property(std::function<T()> getter, std::function<void(const T&)> setter)
: getter_{getter},
setter_{setter}
{}
operator T()
{
return getter_();
}
const T& operator=(const T& val)
{
setter_(val);
return val;
}
};
struct Vector2
{
float x;
float y;
Property<float> length{
[this]() { return sqrt(x * x + y * y); },
[this](float l) {
float new_x = l * cos(angle);
float new_y = l * sin(angle);
x = new_x;
y = new_y;
}
}
Property<float> angle{
[this]() { return atan2(y, x); },
[this](float a) {
float l = length;
x = cos(a) * l;
y = sin(a) * l;
}
}
// ...
};
int main() {
Vector2 v;
v.x = 1;
v.y = 1;
v.angle = std::numbers::pi / 2;
std::cout << "(" << v.x << ", " << v.y << ")\n";
}
But this still falls apart in the edge cases, especially when you mix it with templates and/or auto type-deduction. For instance:
Vector2 v;
v.x = 1;
v.y = 1;
auto old_angle = v.angle;
v.angle = std::numbers::pi / 2;
// oops, this prints pi/2, not pi/4 like you probably expected
// because old_angle isn't a float, it's a Property<float> that
// references v
std::cout << old_angle << '\n';
Note also that there's a bug here. Consider this:
int main() {
Vector2 v1;
v1.x = 1;
v1.y = 1;
Vector2 v2 = v1;
v2.angle = std::numbers::pi / 2;
// Oops, assigning to v2.angle modified v1
std::cout << "(" << v1.x << ", " << v1.y << ")\n";
}
You could work around these issues by making Property non-copyable, but then you force any class that uses it to implement a custom copy-constructor. Also, while that would make the auto case "safe", it does so by turning it into a compile error. Still not ideal.
I agree with Miles. This is not the greatest idea, because it's unnatural for C++ developers, and you should write code that is first and foremost easy to read.
However, as an engineering challenge, here's a possible implementation:
#include <math.h>
#include <iostream>
template <typename T>
class Member
{
public:
operator T() const { return _value; }
void operator =(const T& value) const { _value = value; } void operator =(T&& value) { _value = std::move(value); }
private:
T _value;
};
class Angle
{
public:
Angle(const Member<float>& x, const Member<float>& y) :
_x(x), _y(y) {}
operator float() const { return atan2(_y, _x); }
private:
const Member<float>& _x, _y;
};
class Obj
{
public:
Member<float> x, y;
Angle angle;
Obj() : angle(this->x, this->y) {}
};
int main()
{
Obj o;
o.x = 3;
o.y = 5;
std::cout << o.x << ", " << o.y << " -> " << o.angle << std::endl;
}
While other solutions also seem to be possible, this one seems to be the most elegant :P
using namespace std;
struct Vector2 {
float x;
float y;
float init_length = [&]()-> float {return sqrt(x * x + y * y); }();
float init_angle = [&]()-> float {return atan2(y, x); }();
__declspec(property(get = GetAngle, put = SetAngle)) float angle;
__declspec(property(get = GetLength, put = SetLength)) float length;
Vector2() : x(0), y(0) {}
Vector2(float a, float b) : x(a), y(b) {}
~Vector2() {}
Vector2(Vector2& other) : x(other.x), y(other.y) {}
Vector2(Vector2&& other) = delete;
void operator =(Vector2&& other) = delete;
void Display() {
printf("%f\n%f\n%f\n%f\n\n", x, y, length, angle);
}
float GetLength() {
return sqrt(x * x + y * y);
}
float GetAngle() {
return atan2(y, x);
}
void SetLength(float l) {
float a = GetAngle();
x = cos(a) * l;
y = sin(a) * l;
}
void SetAngle(float a) {
float l = GetLength();
x = cos(a) * l;
y = sin(a) * l;
}
};
int main()
{
Vector2 vec = Vector2(10, 17);
vec.Display();
vec.length = 5;
vec.Display();
}
I need to count how many times class members were printed using function Print which is inspector. Constructor should set private elements of class.
#include <cmath>
#include <iostream>
class Vector3d {
double x, y, z;
mutable int count = 0;
public:
Vector3d();
Vector3d(double x, double y, double z);
void Print() const;
int GetCount() const;
};
Vector3d::Vector3d() {
count = 0;
}
Vector3d::Vector3d(double x, double y, double z) {
count = 0;
Vector3d::x = x;
Vector3d::y = y;
Vector3d::z = z;
}
void Vector3d::Print() const {
count++;
std::cout << "{" << x << "," << y << "," << z << "}";
}
int Vector3d::GetCount() const {
return count;
}
int main() {
Vector3d v1(1, 2, 3);
v1.Print();v1.Print();v1.Print();
Vector3d v2(v1);
v2.Print();v2.Print();
std::cout << v2.GetCount();
return 0;
}
I used mutable int to enable changing element of const function. For v1.GetCount() I get output 3, which is correct. However, for v2.GetCount() I get output 5, which is wrong (correct is 2).
Could you help me to fix this? Where am I making mistake?
You need to overload copy constructor and copy assign operator for Vector3d class.
Now you are copying state of count field into v2 object, therefore it starts from 3 not from 0.
#include <cmath>
#include <iostream>
class Vector3d {
double x, y, z;
mutable int count = 0;
public:
Vector3d(double x, double y, double z);
Vector3d(const Vector3d&);
Vector3d& operator=(const Vector3d&);
Vector3d(Vector3d&&) = delete;
Vector3d& operator=(Vector3d&&) = delete;
void Print() const;
int GetCount() const;
};
Vector3d::Vector3d(double x, double y, double z) {
Vector3d::x = x;
Vector3d::y = y;
Vector3d::z = z;
}
Vector3d::Vector3d(const Vector3d& that)
: Vector3d(that.x, that.y, that.z)
{
}
Vector3d& Vector3d::operator=(const Vector3d& that)
{
x = that.x;
y = that.y;
z = that.z;
return *this;
}
void Vector3d::Print() const {
count++;
std::cout << "{" << x << "," << y << "," << z << "}";
}
int Vector3d::GetCount() const {
return count;
}
int main() {
Vector3d v1(1, 2, 3);
v1.Print();v1.Print();v1.Print();
Vector3d v2(v1);
v2.Print();v2.Print();
std::cout << v2.GetCount();
return 0;
}
UPDATE:
Someone mentioned that explicitly deleted move ctor and operator is not ok, I understand that, but for me it is not clear should we move counter to other instance or not. Therefore here possible implementation:
#include <cmath>
#include <iostream>
class Vector3d {
double x, y, z;
mutable int count = 0;
public:
Vector3d(double x, double y, double z);
Vector3d(const Vector3d&);
Vector3d(Vector3d&&);
Vector3d& operator=(Vector3d);
void Print() const;
int GetCount() const;
private:
void swap(Vector3d&);
};
Vector3d::Vector3d(double x, double y, double z) {
Vector3d::x = x;
Vector3d::y = y;
Vector3d::z = z;
}
Vector3d::Vector3d(const Vector3d& that)
: Vector3d(that.x, that.y, that.z)
{
}
Vector3d::Vector3d(Vector3d&& that)
: Vector3d(that.x, that.y, that.z)
{
count = that.count;
}
Vector3d& Vector3d::operator=(Vector3d that)
{
swap(that);
return *this;
}
void Vector3d::swap(Vector3d& that)
{
std::swap(x, that.x);
std::swap(y, that.y);
std::swap(z, that.z);
std::swap(count, that.count);
}
void Vector3d::Print() const {
count++;
std::cout << "{" << x << "," << y << "," << z << "}";
}
int Vector3d::GetCount() const {
return count;
}
int main() {
Vector3d v1(1, 2, 3);
v1.Print();v1.Print();v1.Print();
Vector3d v2 = std::move(v1);
v2.Print();v2.Print();
std::cout << v2.GetCount();
return 0;
}
But these more for commenters than for question author.
I have the following C++ structure
struct voxel {
const std::vector<Eigen::ArrayXf>& getVoltage() const { return m_voltage; }
const std::vector<int>& getChannelIndex() const { return m_channelIndex; }
float getx() { return m_x; }
float gety() { return m_y; }
float getz() { return m_z; }
void appendVoltage(Eigen::ArrayXf v) { m_voltage.push_back(v); }
void appendChannelIndex(int c) { m_channelIndex.push_back(c); }
void setPosition(float x, float y, float z) { m_x = x; m_y = y; m_z = z; }
void change(int c) { m_voltage.at(c)(0) = -100; std::cout << m_voltage.at(c) << "\n"; }
private:
std::vector<Eigen::ArrayXf> m_voltage;
std::vector<int> m_channelIndex;
float m_x;
float m_y;
float m_z;
};
An array of the above structure is used in the following class
class voxelBuffer {
public:
std::vector<voxel> voxels;
voxel getVoxel(ssize_t voxelId) { return voxels.at(voxelId); };
const std::vector<Eigen::ArrayXf>& getVoltage2(ssize_t voxelId) const { return voxels.at(voxelId).getVoltage(); };
ssize_t getNumVoxels() { return voxels.size(); }
};
As an example:
voxel vx1;
vx1.setPosition(1.1, 2.1, 3.1);
vx1.appendChannelIndex(1);
vx1.appendVoltage(Eigen::ArrayXf::LinSpaced(10, 0.0, 10 - 1.0));
vx1.appendChannelIndex(2);
vx1.appendVoltage(Eigen::ArrayXf::LinSpaced(20, 0.0, 20 - 1.0));
vx1.appendChannelIndex(3);
vx1.appendVoltage(Eigen::ArrayXf::LinSpaced(30, 0.0, 30 - 1.0));
voxelBuffer vxbuffer;
vxbuffer.voxels.push_back(vx1);
I try to change the first array of voxel
vxbuffer.getVoxel(0).change(0);
std::cout << vxbuffer.getVoltage2(0).at(0) << "\n";
But the element is still not modified. Could someone please help me with this issue?
vxbuffer.getVoxel(0) is not returning a reference to the voxel in the container. You are returning a copy of it, because your return type of voxel getVoxel(ssize_t voxelId) is voxel, not voxel&.
Then you call .change(0) on that temporary object of type voxel, not on the voxel object in the container.
My code isn't working. I'm trying simple inheritance Shape as base class and two classes under Shape "Two Dimension" and "Three Dimension" and shapes under that classes. Here's my code but when I try to define a new class as Triangle it gives me error LNK2001 LNK1120. It looks complicated but I must get area, volume and perimeter for every each object.
My full error:
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: virtual double __thiscall TwoDimensionShape::Area(void)" (?Area#TwoDimensionShape##UAENXZ) Shape c:\Users\aleyn\documents\visual studio 2015\Projects\Shape\Shape\Source.obj 1
That's .h
#pragma once
#define M_PI 3.14159265358979323846
class Shape
{
private:
double width, height, depth;
public:
Shape(double w, double h, double d);
virtual void Display() = 0;
virtual double Area() = 0;
virtual double Perimeter() = 0;
virtual double Volume() = 0;
};
class TwoDimensionShape: public Shape
{
public:
TwoDimensionShape(double w, double h, double d = 0) :
Shape(w, h, d)
{
}
double Area();
double Perimeter();
double Volume();
void Display();
};
class ThreeDimensionShape: public Shape
{
private:
double width, height, depth;
public:
ThreeDimensionShape(double w, double h, double d) :
Shape(w, h, d)
{
depth = d;
}
double Area();
double Volume();
double Perimeter();
void Display();
};
class Triangle: public TwoDimensionShape
{
private:
double side1, side2, base;
public:
Triangle(double w, double h, double d = 0) :
TwoDimensionShape(w, h, d)
{
}
double Area()
{
return Area() / 2;
}
void setTriangleSides(double s1, double s2, double b);
double Perimeter()
{
return side1, side2, base;
}
double Volume()
{
return 0;
}
};
class Square: public TwoDimensionShape
{
public:
Square(double w, double h, double d = 0) :
TwoDimensionShape(w, h, d)
{
}
double Volume()
{
return 0;
}
};
class Rectangle: public TwoDimensionShape
{
public:
Rectangle(double w, double h, double d = 0) :
TwoDimensionShape(w, h, d)
{
}
double Volume()
{
return 0;
}
};
class Circle: public TwoDimensionShape
{
private:
double radius;
public:
Circle(double r, double a = 0, double d = 0) :
TwoDimensionShape(r, a, d)
{
radius = r;
}
double Area()
{
return M_PI * (radius) * (radius);
}
double Perimeter()
{
return 2 * M_PI * radius;
}
double Volume()
{
return 0;
}
};
class Sphere: public ThreeDimensionShape
{
private:
double radius;
public:
Sphere(double r, double a = 0, double b = 0) :
ThreeDimensionShape(r, a, b)
{
radius = r;
}
double Volume()
{
return (4 / 3 * M_PI * (radius * radius * radius));
}
double Area()
{
return 4 * M_PI * radius * radius;
}
double Perimeter()
{
return 0;
}
};
class Cylinder: public ThreeDimensionShape
{
private:
double radius, height;
public:
Cylinder(double r, double h, double a = 0) :
ThreeDimensionShape(r, h, a)
{
}
double Volume()
{
return M_PI * radius * radius * height;
}
double Area()
{
return (2 * M_PI * radius * height) + 2 * M_PI * radius * radius;
}
double Perimeter()
{
return 0;
}
};
class Cone: public ThreeDimensionShape
{
private:
double radius, height, side;
public:
Cone(double r, double h, double s) :
ThreeDimensionShape(r, h, s)
{
}
double Volume()
{
return 1 / 3 * M_PI * radius * radius * height;
}
double Area()
{
return (M_PI * radius * side) + M_PI * radius * radius;
}
double Perimeter()
{
return 0;
}
};
class RectPrism: public ThreeDimensionShape
{
public:
RectPrism(double w, double h, double d) :
ThreeDimensionShape(w, h, d)
{
}
double Area();
double Volume();
double Perimeter();
};
my .cpp
#include "Shape.h"
#include <iostream>
using namespace std;
Shape::Shape(double w, double h, double d)
{
width = w;
height = h;
depth = d;
}
double Shape::Area()
{
return width * height;
}
double Shape::Perimeter()
{
return (width + height) * 2;
}
double Shape::Volume()
{
return width * height * depth;
}
double ThreeDimensionShape::Area()
{
return (2 * (height * width) + 2 * (depth * width) + 2 * (depth * height));
}
double ThreeDimensionShape::Volume()
{
return width * height * depth;
}
double ThreeDimensionShape::Perimeter()
{
return (4 * width + 4 * height + 4 * depth);
}
void Triangle::setTriangleSides(double s1, double s2, double b)
{
side1 = s1;
side2 = s2;
base = b;
}
void TwoDimensionShape::Display()
{
cout << "Perimeter: " << Perimeter() << endl;
cout << "Area: " << Area() << endl;
cout << "Volume: " << Volume() << endl;
}
main .cpp
#include <iostream>
#include "Shape.h"
using namespace std;
int main()
{
Triangle t1(8, 5, 0);
system("pause");
return 0;
}
the error message says it all
LNK2001 unresolved external symbol "public: virtual double __thiscall TwoDimensionShape::Area(void)"
You have not written TwoDimenionalShape::Area
In your header file you promised to write one, but you didnt
I'm trying to fill a vector of an object Point 3D. My app read a csv file to load the vector by the three cordinate x, y, z. I use the type float.
This is my code.
main.cpp
int main(int argc, char** argv) {
char *theFileName = "file.csv"; //[100];
vector<Point> v = getPointCloud(theFileName);
for (int i = 0; i < v.size(); ++i) {
v.at(i).print(cout);
}
}
getPointCloud
vector<Point> getPointCloud(char *fileName) {
string line;
string token;
vector<Point> v;
double tab[3];
ifstream file(fileName);
if (file.is_open()) {
while (getline(file, line)) {
int cpt = 0;
stringstream stream(line);
while (getline(stream, token, ',')) {
tab[cpt] = ::atof(token.c_str());
cpt++;
}
Point p(tab[0], tab[1], tab[2]);
p.print(cout); <-- the display works
p.setColor(255, 0, 0);
v.push_back(p);
}
file.close();
} else {
cout << "Unable to open " << fileName << '\n';
exit(0);
}
return v;
}
I have two problems:
1 - when I try to display points in the main method, I found that the three coordinates are null ( == 0) but in the displaying in the getPointCloud method works very well.
2 - Can someone give a simple method to conserve my coordinates without loss precision after mathematical operations. I have searched in the net but I don't understand haw to solve it. I'm newbie with c++.
Point.h
#ifndef POINT_H
#define POINT_H
#include <math.h>
#include <iostream>
class Point {
protected:
float x;
float y;
float z;
// color RGB
float r;
float g;
float b;
public:
// Constructors
Point();
// Point(const Point& orig);
Point(std::ostream &strm);
Point(float x, float y, float z);
Point(const Point& orig);
virtual ~Point();
//getters
float getX() const {
return this->x;
}
float getY() const {
return this->y;
}
float getZ() const {
return this->z;
}
float getR() const {
return this->r;
}
float getG() const {
return this->g;
}
float getB() const {
return this->b;
}
//setters
void setX(float x) {
this->x = x;
}
void setY(float y) {
this->y = y;
}
void setZ(float z) {
this->z = z;
}
void setR(float r) {
this->r = r;
}
void setG(float g) {
this->g = g;
}
void setB(float b) {
this->b = b;
}
void setColor(float r, float g, float b) {
this->r = r;
this->g = g;
this->b = b;
}
/**
* Print the point
* #param strm
*/
void print(std::ostream &strm);
//Other methods
float dist2D(Point &other);
float dist3D(Point &other);
Point swap(Point p);
// Point operator-(const Point &other) const;
};
#endif /* POINT_H */
Point.cpp
#include <iostream>
#include <math.h>
#include <ostream>
using namespace std;
#include "Point.h"
Point::Point(const Point& orig) {
}
Point::Point(ostream &strm) {
strm << "Type the abscissa: ", cin >> this->x;
strm << "Type the ordinate: ", cin >> this->y;
strm << "Type the applicate: ", cin >> this->z;
}
Point::Point(float x, float y, float z) : x(x), y(y), z(z) {
// The default point color is blue
this->r = 0;
this->g = 0;
this->b = 255;
}
/**
* Destructor
*/
Point::~Point() {
}
//Other methods
float Point::dist2D(Point &other) {
float xd = x - other.x;
float yd = y - other.y;
return sqrt(xd * xd + yd * yd);
}
float Point::dist3D(Point &other) {
float xd = x - other.x;
float yd = y - other.y;
float zd = z - other.z;
return sqrt(xd * xd + yd * yd + zd * zd);
}
Point Point::swap(Point p) {
Point aux(x, y, z);
x = p.x;
y = p.y;
z = p.z;
return aux;
}
//Point Point::operator-(const Point &other) const {
// return Point(other.getX() - this->x, other.getY() - this->y, other.getZ() - this->z);
//}
void Point::print(ostream &strm) {
strm << "Point(" << this->x << "," << y << "," << z << ")" << endl;
}
Thanks in advance.
Point::Point(const Point& orig) {
}
is incorrect.
It does not copy data from orig to *this
Please copy each of the member in this constructor.
This would look like this:
Point::Point(const Point& orig) {
x = orig.x ;
y = orig.y ;
x = orig.z ;
r = orig.r ;
g = orig.g ;
b = orig.b ;
}