I was wondering how you can define an array of the same class. Pretend we have 10 different cars and they all have the same properties. (This isn't really what I'm doing, but just a made up example).
Code:
class Car
{
public:
unsigned int year;
unsigned char color[256];
unsigned short weight;
}
Now say I want to create multiple instances of Car class in an array. Would I do something like this?:
If this is correct, could I do something like this to loop through and get information from a user? Just an example:
Code:
for( unsigned int i = 0; i < 10; i++ )
{
cout << "Enter a cars year: \n";
cin >> cars[i].year;
cout << "Enter a cars color: \n";
cin >> cars[i].color;
cout << "Enter a cars weight: \n";
cin >> cars[i].weight;
}
for( unsigned int i = 0; i < 10; i++ )
{
cout << "Year: " << cars[i].year;
cout << "\tColor: " << cars[i].color;
cout << "\tWeight: \n" << cars[i].weight;
}