Okay I am writing a database type of program, which will store data about people.
I want to create a class:
class Person {
public:
int age;
int weight;
int height;
};
Okay now I want to do something like this:
cout << " Enter name of person.\n";
cin >> name;
//create an object for the class "Parent" and name the object using the user inputed name
Person ("name");
//add information to that object
cout << " Enter age.\n";
cin >> age;
age.("name") = age;
cout << " Enter height.\n";
cin >> height;
height.("name") = height;
cout << "Enter weight.\n";
cin >> weight;
weight.("name") = weight;
But that doesn't work.
Oh and the purpose of this is so that I can do something like this:
cout << "Enter name of person you want to view info about.\n";
cin >> person;
cout << age.("person") << height.("person") << weight.("person");
I having been googling for the past half hour and can't find any answer.
So how do I create an object with a name that is inputed by the user?
Also I wrote the same program using arrays(when my C++ book talked about arrays) now I am learning about classes and I am rewriting it. So when it comes to performance...is it better to store data into objects that are part of a class or store them in arrays and use indexing? Also which will require more sys resources? Right now the only advantages I see to doing it this way than using arrays is that there is a limit to how much arrays can store and the program is much easier to write.
Any help would be greatly appreciated.