0

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++,

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by ayesha91
0

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.

Edited by Ancient Dragon: n/a

0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.