In my project work i need to create a cubical box and have to place particular number of atoms randomly in the box. For that purpose i have created an array of atom objects. I want to give names for each atom object for their identity...
using namespace std;
//Defining two classes..one for silicon(Si) atoms and another one for Oxigen(O2) atoms...
const int m=100; //numbr of silicon atoms...
const int n=200; //number of oxygen atoms...
//end of the silicon class
//end of the oxygen class
private: float depth,length,width:
float x,y,z //these are three axes with respect to the dimensions of the box.
public: Box(float d, float l, float w )
x=y=z=d; //because all three dimensions are equal..
}//end of the box class
silicon si[m]; //array of M number of silicon atoms
oxygen o2[n]; //array of N number of oxygen atoms
Box cube(1.0,1.0,1.0); //Cubic box with the given dimensions
well you cant really name the elements of an array, they need to be accessed using the subscript.However to identify each object you can add a unique field in the class and set it for each object. Then when you fetch the object just check for that value to identify it. Or else use a map, so you can add a key for each object stored and then fetch it based on the key.