Code:
class House
{
int age;
public:
House();
int rooms;
private:
double price;
};
This is a simple class. age, rooms, and price are all data members of the class and that they are declared just like any other non class variables, except they are grouped according to access rights. age is private by default declaration of access rights in all class objects, price is private by explicit declaration of access rights, and rooms is public (public access must always be declared explicity in a class). The problem with this class is that no one but the programmer writing the program or member functions of the class itself can access age and price because they are private. That's also the good news, since you probably don't want people/functions outside the class mucking around with the data like they can with public data members like rooms. To grant access to this information you need to declare some functions to access age, price. Maybe add something like:
int get_age();
void set_age(int);
to the public section. Then you need to define get_age() just like you need to define non member functions. You do that outside the class declaration as a general rule (there is always an exception of course).
Code:
int House::get_age()
{
return age;
}
void House::set_age(int Age)
{
age = Age;
}
Note the slight twist in these declarations in that you have to indicate which class the funtions are members of, if they are member functions to begin with.
These public member functions are the interface that the directions talk about.
To include a data member that's an array, you just declare it in the usual way and grant it some sort of access: private by default
private by explicit, or public (there's also protected access but let's skip that for now).
To use dynamic memory to declare an array, declare the array as a pointer to the appropriate type, then in the constructor or one of the other public accessor methods declare memory dynamically using the new operator just like you would outside the class environment. You delete this dynamically allocated memory just like you ordinarily would, but generally you do it in the destructor of the class, although I suppose you could do it elsewhere if you have a valid reason to do so.
To keep track of the size of and the number of elements in a dynamically declared array so you can resize the array as appropriate, you will need appropriate data members in the class. If you make these data elements private but you want them accessable outside the class then you need to provide the appropriate interface to do so.