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

Question #174673

Make a 3DPoint class with 2 constructors and a destructor. Constructor should take input from file_name passed, Constructor 2 should input from user. Destructor should output id of destructed object.


1
Expert's answer
2021-03-26T17:08:38-0400
#include <fstream>
#include<iostream>


using namespace std;


class Point3D
{
private:
	int x;
	int y;
	int z;
	static int id;
public:
	//Constructor should take input from file_name passed
	Point3D(string file_name)
	{
		ifstream _ifstream(file_name);
		_ifstream>>this->x>>this->y>>this->z;
		//close the file
		_ifstream.close();
		id++;
	}
	//Constructor 2 should input from user.
	Point3D(int x,int y,int z)
	{
		this->x=x;
		this->y=y;
		this->z=z;
		id++;
	}
	~Point3D() {
		cout<<"id of destructed object: "<<id<<"\n";
	}


};
int Point3D::id = 0;


int main() {
	int x;
	int y;
	int z;
	
	cout << "Enter X Y Z: ";
	cin >> x>>y>>z;
	Point3D* point3D=new Point3D(x,y,z);
	delete point3D;
	Point3D* point3DFile=new Point3D("Point3D.txt");
	delete point3DFile;
	system("pause");
	return 0;
}



Create the file Point3D.txt with the following values:


5 6 8


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