/* 	
	Student's Name	: Tee Hui You
	Matric no. 		: A19EC0170 
*/ 

#include <iostream>
#include <string>
using namespace std;

class Address
{
	private:
		string registrar;
		string country;
	public:
		Address();
		void set(string, string);
		string getRegistrar() const
		{return registrar;}
		
		string getCountry() const
		{return country;}
};

class Ship
{
	private:
		string name;
		string yearMade;
		Address *address;
	public:
		Ship();
		void read();
		void print();
};

Address::Address()
{
	registrar = "";
	country = "";
}

void Address::set(string r, string c)
{
	registrar = r;
	country = c;
}

Ship::Ship()
{
	name = "";
	yearMade = "";
	address = new Address;
	address->set("", "");
}

void Ship::read()
{
	string n, y, c, r;
	cout << "<<< Enter the information of the ship >>>\n\n"
		 << "Ship Name: ";
	getline(cin, name);
	
	cout << "Year Built: ";
	getline(cin, yearMade); 
	cout << endl;
	
	cout << "The address the ship was registered:\n"
		 << "Registrar Office: ";
	getline(cin, r);
	
	cout << "Country: ";
	getline(cin, c);
	cout << endl;
	
	address->set(r, c);
}

void Ship::print()
{
	cout << "Ship Name: " << name << "\n"
		 << "Year Built: " << yearMade << "\n"
		 << "Registered at:\n" << "\t" << address->getRegistrar() << ", " << address->getCountry() << endl;
}

int main ()
{
	int numShip = 0;
	Ship *ship = new Ship[5]; 
	int choice;
	
	cout << "======== MENU ========\n"
		 << "1. Add a ship\n"
		 << "2. Display ships\n"
		 << "3. Exit\n\n"
		 << "Choose an operation => ";
		cin >> choice;
		cin.ignore();
		cout << endl;
	
	while((choice == 1) || (choice == 2) || (choice == 3))
	{
		if(choice == 1)
		{
			ship[numShip].read();
			numShip++;
		}
		else if(choice == 2)
		{
			cout << "<<< Inventory of ships >>>\n\n"
				 << "Total ships: " << numShip << "\n\n";
			cout << "==== Ship List ====\n\n";
		 
			for (int j = 0; j < numShip; j++)
			{
				ship[j].print();
				cout << endl;
			}
		}
		else if(choice == 3)
		{
			return 0;
		}
		
		cout << "Press any key to continue . . ." << endl << endl;
		
		cout << "======== MENU ========\n"
		 << "1. Add a ship\n"
		 << "2. Display ships\n"
		 << "3. Exit\n\n"
		 << "Choose an operation => ";
		
		cin >> choice;
		cin.ignore();
		cout << endl;
	}
		
	delete [] ship;
	ship = NULL;
	
	return 0;
}
