Classes and arrays

Can someone help me write this code?

This is my header file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class  Scheduler
{
	public:
   		Scheduler();  						// Default Constructor
   		Scheduler(Event E[10], int size); 	// Constructor
   		Scheduler(Scheduler &OtherS);       // Copy Constructor
   		~Scheduler();                       // Destructor
   		void GetSchedule(Event E[10]) const;
   		float GetScheduleDuration() const;
   		void Print();
 	private:
		string schName;
   		Event schedule[10];
   		int size;
};

What im stuck on is trying to create the function call thing in the cpp file. I got this:
1
2
3
4
Scheduler::Scheduler(Event E[10], int size)
{
    
}

but i dont know what goes inside. Ive been stuck on this part of the assignment and would really appreciate any help.
Well, it looks as if you are attempting to write the constructor for your class. You are passing in some values, and you probably want to save them so that you can work on them later. So my guess is that the function should be written as:

1
2
3
4
5
Scheduler::Scheduler(Event E[10], int size)
{
	this->schedule = E;
	this->size = size;
}
Shouldn't it be like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class  Scheduler
{
	public:
   		Scheduler();  						// Default Constructor
   		Scheduler(Event E[], int size); 	// Constructor
   		Scheduler(Scheduler &OtherS);       // Copy Constructor
   		~Scheduler();                       // Destructor
   		void GetSchedule(Event E[]) const;
   		float GetScheduleDuration() const;
   		void Print();
 	private:
		string schName;
   		Event schedule[10];
   		int size;
};

Scheduler::Scheduler(Event E[], int size)
{
    schedule = E;
    size = size;
}
Well, that would almost work.

size = size

sets the value of the parameter to its own value. You want to set the "size" class variable to the "size" parameter value. Since the code is somewhat ambiguous, the compiler defaults to working on the parameters.

To make the code unambiguous, and to make it work correctly, you need to tell the compiler you are attempting to set the class variable, not the function parameter. You can do this via

this->size = size
Topic archived. No new replies allowed.