Answer to Question #174671 in C++ for zain ul abdeen

Question #174671

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.


1
Expert's answer
2021-03-26T12:39:03-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS