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

Create a class called birthday. The class should store the birthday of a person

ID: 672906 • Letter: C

Question

Create a class called birthday. The class should store the birthday of a person in the 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. Notes: please take your time, no rush. please follow the directions, it must have an array, create separate header for class definitions. language is: C++

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;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote