// EEL3801C.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

class Person {
public:
	Person(char *name);
	~Person();
	char* getName();
	virtual void print() = 0;
protected:
	char *name;
};

Person::Person(char *name) {
	cout << "\tPerson constructor\n";
	this->name = new char[strlen(name)+1];
	strcpy(this->name, name);
}

Person::~Person() {
	delete[] name;
}

char* Person::getName() {
	return name;
}

class Student : public Person {
public:
	Student(char *name, int year);
	int getYear();
	int getGrade();
	void setGrade(int grade);
	void print();
protected:
	int year;
	int grade;
};

Student::Student(char *name, int year) : Person(name) {
	this->year = year;
	this->grade = -1;
}

int Student::getYear() {
	return year;
}

int Student::getGrade() {
	return grade;
}

void Student::setGrade(int grade) {
	this->grade = grade;
}

void Student::print() {
	cout << "Student\n";
	cout << "\tname = " << name << "\n";
	cout << "\tyear = " << year << "\n";
	if (grade == -1) {
	   cout << "\tno grade assigned yet \n";
	} else {
	   cout << "\tgrade = " << grade << "\n";
	}
}

class TA : public Student {
public:
	TA(char *name, int year, int pay);
	int getPay();
protected:
	int pay;
};

TA::TA(char *name, int year, int pay) : Student(name, year) {
	this->pay = pay;
}

int TA::getPay() {
	return pay;
}

class Professor: public Person {
public:
	Professor(char *name, char *specialization);
	~Professor();
	char* getSpecialization();
	void  setSpecialization(char *specialization);
	void print();
protected:
    char *specialization;
};

Professor::Professor(char *name, char *specialization) :
Person(name) {
	this->specialization = new char[strlen(specialization) + 1];
	strcpy(this->specialization, specialization);
}

Professor::~Professor() {
	delete[] specialization;
}

char* Professor::getSpecialization() {
	return specialization;
}

void  Professor::setSpecialization(char *specialization) {
	if (this->specialization != NULL) {
		delete[] this->specialization;
	}
	this->specialization = new char[strlen(specialization) + 1];
	strcpy(this->specialization, specialization);
}

void Professor::print() {
	cout << "Professor:\n";
    cout << "\tname =" << name << "\n";
    cout << "\tspecialization =" << specialization << "\n";
}

class Class {
public:
	Class();
	void assignProfessor(Professor *professor);
	//void assignTA1(TA *ta);
	//void assignTA2(TA *ta);
	void join(Student *student);
	//void drop(Student *student);
	int enrollment();
	void print();
protected:
	Professor *professor;
	TA *ta1, *ta2;
	Student *students[25];
};

Class::Class() {
	professor = NULL;
	ta1 = NULL;
	ta2 = NULL;
	for(int i=0; i!=25; i++) {
		students[i] = NULL;
	}
}

void Class::assignProfessor(Professor *professor) {
	this->professor = professor;
}

int Class::enrollment() {
	int counter = 0;
	for(int i = 0; i!= 25; i++) {
		if (students[i] != NULL) {
			counter++;
		}
	}
	return counter;
}

void Class::join(Student *student) {
	for(int i = 0; i!= 25; i++) {
		if (students[i] == NULL) {
			students[i] = student;
			return;
		}
	}
	cout << "Class is full, not enrolled\n";
}

void Class::print() {
	if(professor == NULL) {
		cout << "No professor assigned yet\n";
	} else {
		professor->print();
	}
	// enrolled students
	int counter = 1;
	for(int i = 0; i!= 25; i++) {
		if (students[i] != NULL) {
			cout << "Student nr: " << counter << " " << students[i]->getName() << "\n";
			counter++;
		}
	}

}

int _tmain(int argc, _TCHAR* argv[]) {
	Class eel3801c;
	cout << "Enrollment:" << eel3801c.enrollment() << "\n";
    Student joe("Joe", 3);
	eel3801c.join(&joe);
	cout << "Enrollment:" << eel3801c.enrollment() << "\n";
	eel3801c.print();
    Student joy("Joy", 3);
	eel3801c.join(&joy);
	eel3801c.print();

	return 0;
}


