I've been lost in this class for weeks and I have no idea how to even do this assignment.

please help! It's in the attachment

Recommended Answers

All 10 Replies

What part of the assignment is giving you difficulty.. ?

After breifly looking at your attachment, it seems that the assignment is already well outlined for you.. all you have to do is create a simple child class with one additional attribute that will identify the primary work on the cd. Even the main() driver has been written for you. It seems like all you have to do is to create a simple child class, and write the function definitions.. which shouldn't be too difficult.

One thing to consider though, there are some rules about passing pointers to child classes, although I can't remember specificially but I know that there are some issues that can arise.

Also, if I am not mistaken, parent class functions that will be used in child classes need to be prototyped as 'virtual.'

Parent class functions that need to be different than their parent class counterparts must be labeled virtual. This lets the compiler know that the method will be attached dynamically (i.e., depending on the type of the object at runtime). If I have a class called hasmotoroutside I can derive and create a car and a lawnmower from it, which can both be stored in a garage (or an array of hasmotoroutside objects) but when it comes to the start function of hasmotoroutside, it must be virtual because in the mower it consists of pullcord and the car it conisists of turnkey.

So really all you have to do is declare your virtual function with that keyword. It's important for things like destructors when if you allocate memory in a derived class you sure don't want the compiler to leak that memory if the parent's destructor were to step in.

Just remember the underlying assumption to all this. An array can hold objects (or pointers to objects) that have the same base class even if they are of a derived class.

I don't understand how to add a char * member to points to a string.

>I don't understand how to add a char * member to points to a string.
Look at the Cd class and do the same thing with your child class. The Cd class has char* members as well, so it's not like you don't have an example to work from. :icon_rolleyes:

//child class
class classic{
protected:
         char* member;

then what do I do?
when I say I'm lost in this class, I'm really lost.

>then what do I do?
Well, it's not a child class until you actually derive from a base:

class Classic: public Cd {
  char *primary_work;
public:
  //...
};

The assignment is kind of stupid in that it says "if the base class required that any functions be virtual", as if that weren't the case. :icon_rolleyes: You need to make the report member function virtual, and the override it in the Classic class. Presumably you also need to implement the base class as well.

>when I say I'm lost in this class, I'm really lost.
That's not a feeling that will go away. Get used to it if you have any plans of a career in programming.

class Classic: public Cd {
char *primary_work;
public:
virtual void func() { cout << "Classic" << endl; }
};

Is that right?

>Is that right?
I'm not going to do your homework with you as the middle man. If you can't write a few lines of code without having your hand held the whole time, you need to seriously re-evaluate whether you're suited for programming.

Go read your book, study your notes from class, and if you still can't figure it out, ask a smart question.

I'm not doing programming as a career. I'm just required to take this course. I don't ever have to take C++ again and I'm just trying to barely make it through.

>I'm not doing programming as a career.
That's a relief.

>I'm just required to take this course.
Then I suppose you still have a vested interest in learning the material. It doesn't change the fact that I'm not going to help you breeze your way through the class. If you put forth the effort, I'll help you along, but if you expect me to do most of the work, you can expect no help in return.

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.