Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Language is c++ Please keep it simple and create a separate header. Create a cla

ID: 672758 • Letter: L

Question

Language is c++

Please keep it simple and create a separate header.

Create a class called birthday. The class should store the birthday of a person in three integers: month, day, and year. birthday class has member functions to get these values and return them to the user. birthday class takes the three values through the constructor. Outside the class, define a function called compareBDs that finds who is older among two persons. Create an array of four objects in the main function. search the array to find the youngest person.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;

#define GI ({int t; scanf("%d", &t); t;})
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << " "
#define mpr make_pair
#define pb push_back
const int mod = 1000000007;

typedef pair<int,int> pii;

void init(){
  
}

class birthDay
{int day, month, year;
public:
   birthDay(){

   }

   birthDay(int day, int month, int year){
       this->day = day;
       this->month = month;
       this->year = year;
   }

   bool operator <(birthDay B){
       if(year == B.year){
           if(month == B.month)
               return day > B.day;
           else
               return month > B.month;
       }
       return year > B.year;
   }

   int getDay(){
       return day;
   }

   int getMonth(){
       return month;
   }

   int getYear(){
       return year;
   }
  
   /* data */
};


int main(){
   vector<birthDay> arr(4);
   arr[0] = birthDay(10,12,1970);
   arr[1] = birthDay(1,2,1999);
   arr[2] = birthDay(11,4,1997);
   arr[3] = birthDay(1,12,1992);

   sort(arr.begin(), arr.end());

   debug(arr[0].getDay());
   debug(arr[0].getMonth());
   debug(arr[0].getYear());

   cout << "Youngest : " << arr[0].getDay() << " " << arr[0].getMonth() << " " << arr[0].getYear() << endl;

}