Make a 3DPoint class with constructor and destructor. The constructor should take input from the user. Destructor should output the id of the destructed object.
#include <iostream>
using namespace std;
class Point3D
{
int id;
static int count;
public:
void set_x(float x) {
m_x = x;
}
void set_y(float y) {
m_y = y;
}
void set_z(float z) {
m_z = z;
}
Point3D()
{
float i;
cout << "enter x coordinate"<< endl;
cin >> i;
set_x(i);
cout << "enter y coordinate" << endl;
cin >> i;
set_y(i);
cout << "enter z coordinate" << endl;
cin >> i;
set_z(i);
}
~Point3D()
{
cout << "destructor for id " << id << endl;
}
private:
float m_x{ 0 };
float m_y{ 0 };
float m_z{ 0 };
};
int Point3D::count = 0;
int main() {
Point3D example;
return 0;
}
Comments
Leave a comment