// Student Name : Ng Jing Er
// Course : 1-SECV
// Matric No: A19EC0115
//Exercise pg91 question 1

#include <iostream>
#include <string>
using namespace std;

class Address {
	private:
		string registrar;
		string country;

	public:
		Address() {
			string r,c;
			set(r, c);}
		void set(string r, string c) {
			registrar = r;
			country = c;}
		string getRegistrar() {	return registrar; }
		string getCountry() { return country; }
};

class Ship {
	private:
		string name;
		string yearMade;
		Address address;

	public:
		Ship() {
			string n,y;
			name = n;
			yearMade = y;}
		void print() {
			cout<<"Ship Name: "<<name<<endl;
			cout<<"Year Built: "<<yearMade<<endl;
			cout<<"Registered at:\n   "<< address.getRegistrar()<<", "<<address.getCountry()<<endl;
	}
	void read() {
		string r, c;
		
		cout << "Ship Name: ";
		cin.ignore();
		getline(cin,name);

		cout << "Year Built: ";
		getline(cin, yearMade);

		cout << "\nThe address the ship was registered:\n";
		cout << "Registrar Office: ";
		getline(cin,r);

		cout << "Country: ";
		cin >> c;
		cout<<endl;

		address.set(r, c);
	}
};

	
int main() {
	int choice;
	int i = 0;

	Ship ship[50];
	do {
		cout<<"\n======== MENU ========"<<endl<<"1. Add a ship"<<endl<<"2. Display ships"<<endl<<"3. Exit\n"<<endl;
		cout<<"Choose an operation  => ";   		
		cin >> choice;
		
		switch(choice){
			case 1: cout<<"\n<<< Enter the information of the ship >>>\n"<<endl;
					ship[i].read();
					i++;
					system("pause");
					break;
					
			case 2:	cout<<"\n<<< Inventory of ships >>>"<<endl;
					cout<<"\nTotal ship: "<<i<<endl;
					cout<<"\n==== Ship List ====\n"<<endl;
					for (int n = 0; n < i; n++) {ship[n].print();	}
					system("pause");
					break;}
					
	} while (choice != 3);

return 0;
}
