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.
#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
Comments
Leave a comment