Hello,

I am having a problem with an assignment that I have to submit tomorrow which is to let a user construct an object. in the assignment it is asked from me to create a DVDshop class where the user can create a DVD object. Also, in this class I should have an array of actors but I don't know how to deal with array in objects(how to initialize them).

If I am letting the user set the values of the data member, do I still have to have a constructor for the class? because when I don't include a constructor I get an error!

Please help me out here, I am new to object-oriented C++,

When you instantiate a single instance of a c++ class the constructor is called, and that's where the class is initialized. The same thing happens when you create an array of c++ classes.

>>do I still have to have a constructor for the class?
Depends on the class, but in most cases you would create a constructor, and possibly more than one constructor, including the copy constructor. This is where you will initialize class data objects, such as initializing them to 0 or NULL.

Can I use the following set functin for the user entering the info the DVD object:

int DVD::setAddedActors()
{
	int n;
	cout<<"Enter the number of actors to be added: ";
	cin>>n;
	return n;
}
void DVD::setTitle()
{
	cout<<"Enter the title: ";
	cin>>title;
}
void DVD::setPrice()
{
	cout<<"Enter the price: ";
	cin>>price;
}
void DVD::setActors(int n)
{
	cout<<"Enter the actor(s): "<<endl;
	for(int i=0; i<n; i++)
	{
		cout<<i+1<<") ";
		cin>>actors[i];
	}		
}
void DVD::setDuration()
{
	cout<<"Enter the duration (min): ";
	cin>>duration;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.