// Programming Technique II (SCSJ1023)
// Semester 2, 2019/2020

// Student Name: NG JING ER
// Student Matric No :A19EC0115

// Exercise 3a: object as function parameter

#include <iostream>
using namespace std;

// * ---------------------------------------------------------------------------------------------
// * Task 1: Declare and define the class Date
// * ---------------------------------------------------------------------------------------------

class Date
{
  private:
	int day, month, year;

  public:
	// complete this class
	// 1a-Write the definition of the constructor Date(int =1,int=1,int=2019)
	// to initialize day, month and year
	
	Date(int a=1,int b=1,int c=2019){
		day=a;
		month=b;
		year=c;
	};
	
	// 1b-write the declaration for the accessor and mutator function for day, month year
	int getDay(){return day;}
	void setDay(int d){day=d;}
	int getMonth(){return month;}
	void setMonth(int m){month=m;}
	int getYear(){return year;}
	void setYear(int y){year=y;}
	void print() const // This method is given
	{
		cout << day << "-" << month << "-" << year << endl;
	}
	friend void setAppointment(Date &);
};

    // * ---------------------------------------------------------------------------------------------
	// * Task 2: Write the definition of the accessor, mutator and the constructors of class Date
	// * ---------------------------------------------------------------------------------------------
void dateDifference(Date,Date);
void setAppointment(Date& date);
		
     // * ---------------------------------------------------------------------------------------------
	// * Task 3: Write the definition for the function setAppointment to allow user 
	// * to set appoitment to certain date 
	// * --------------------------------------------------------------------------------------------
void setAppointment(Date& date){
	cout<<"Please set an appointment date.";
	cout<<"\nDay : ";
	cin>>date.day;
	cout<<"Month: ";
	cin>>date.month;
	cout<<"Year: ";
	cin>>date.year; 
}	
	// * ---------------------------------------------------------------------------------------------
	// * Task 4: Write the definition for the function dateDifference(Date,Date)
	// * to find the difference between the 2 date given
	// * this function can only find the difference of the date if the month and year is the same
	// * only substract the smaller day from the larger day
	// * Output : The difference for 1-10-2019 and 2-10-2019 is 1 day
	// *   OR
	// * OUTPUT : The difference for 1-11-2020 and 1-11-2019 cannot be found
	// * ---------------------------------------------------------------------------------------------
	
void dateDifference(Date date_1, Date date_2 ){
	int diff_day=0;
	
	if(date_1.getMonth()==date_2.getMonth() && date_1.getYear()==date_2.getYear()){
		if(date_2.getDay()>date_1.getDay()){
			diff_day=date_2.getDay()-date_1.getDay();}
		else{
			diff_day=date_1.getDay()-date_2.getDay();}
			
		cout<<"The difference for "
			<<date_1.getDay()<<"/"<<date_1.getMonth()<<"/"<<date_1.getYear()<<" and "
			<<date_2.getDay()<<"/"<<date_2.getMonth()<<"/"<<date_2.getYear()<<" is "
			<<diff_day<<endl;}
			
	else{
		cout<<"The difference for"
			<<date_1.getDay()<<"/"<<date_1.getMonth()<<"/"<<date_1.getYear()<<" and "
			<<date_2.getDay()<<"/"<<date_2.getMonth()<<"/"<<date_2.getYear()<<" cannot be found "<<endl;
		}
}

int main()
{
	// * ---------------------------------------------------------------------------------------------
	// * Task 5: Create a Date object for today's date and print suitable message for todays date
	// * Ouput: Todays date is : 1-10-2019
	// * ---------------------------------------------------------------------------------------------
	Date today(1,10,2019);
	cout<<"Today's date is: ";
	today.print();
	
	// * ---------------------------------------------------------------------------------------------
	// * Task 6: Create a Date object for tomorrow's date and print the date for tomorrow
	// * Ouput: Tomorrows date is : 2-10-2019
	// * ---------------------------------------------------------------------------------------------
    Date tomorrow(2,10,2019);
	cout<<"Tomorrow's date is: ";
	tomorrow.print();
	dateDifference(today,tomorrow);
    
// * ---------------------------------------------------------------------------------------------
	// * Task 7: Print the appoinment date 
	// * Ouput: The appoinment date is : xx-xx-2019
	// * Ensure that date is passed by reference to setAppoinment
	// * ---------------------------------------------------------------------------------------------
	Date anotherDay;
    setAppointment(anotherDay);
    cout<<"The appointment date is: ";
	anotherDay.print();
    

	return 0;
}
