//Program 7.1

//In my own words, such output is printed because
/*uni-directional arrow and line without arrow show Associations relationship.
 
 Concept of Associations : 
Association always focus on activities.
The regCourse(Course)is activity that links 2 classes and it will become one of the method of the class Student.
Since there is an arrow pointed to class Course, 
We must define the object of Course as data member(using pointer variable) in enclosing data. 
Association always declare attributes as object pointer and allow object to call methods through pointer variable.
Below shows object of Student class call methods in Course class through pointer variable, subject.

 Output Explanation:
When we call this display() function of class Student, actually we will call getName() and getCode() of the class Course.
We can call these 2 methods from Course class because 
we already have pointer object that we already defined as data member for class Student.
void Student::display()
{
	cout<<name<<" ("<<matrix<<") register "
		<<subject->getName()<<" ("
		<<subject->getCode()<<") "<<endl;
}
Because of Associations, we declare the object of class Course as object pointer(can be used by every students).
Firstly, we can directly write name and matrix only without adding pointer because 
name and matrix is the private member variable in class Student.
Secondly, in order to link 2 classes, we apply pointer concept.
We have to declare subject (pointer variable) with dataType Course as data member in private,
when we want to access the public member of Course, we have to use pointer variable to call.*/

#include<iostream>
#include<string>
using namespace std;

class Course
{
	private:
		string name,code;
		
	public:
		Course(string n,string c);
		string getName() 
		{
			return name;
		}
		string getCode()
		{
			return code;
		}
};

class Student
{
	private:
		string name,matrix;
		Course *subject;
		
	public:
		Student(string n,string m);
		void regCourse(Course *subject); //= activity between 2 classes wll link these 2 classes
		void display();
};

Student::Student(string n,string m)
{
	name=n;
	matrix=m;
	subject=NULL;  //assume this student has not registered any course yet
}

void Student::regCourse(Course *c)  
{
	subject=c;
}

void Student::display()
{
	cout<<name<<" ("<<matrix<<") register "
		<<subject->getName()<<" ("
		<<subject->getCode()<<") "<<endl;
}

Course::Course(string n,string c)
{
	name=n;
	code=c;
}


int main()
{
	Course *c=new Course("PT2","SCSJ1023");
	Student s("Ainul Hashim","A18CS0044");
	
	s.regCourse(c);
	s.display();
	
	return 0;
}
