C++ Program to calculate Date of Birth with Age given using Class

Concept: In this C++ program, problem is to calculate date of birth with Age and present date given using concepts of class in c++. This program calculates and prints date of birth in Year/Month/Day format. Function calc_DOB in this program first finds age in (YY/MM/DD) format

year = Days/365;
month = (Days % 365)/30;
day = (Days % 365) % 7;

and then, subtracts the age in that format with the present date provided by the user.

birthYear= persentYear - year;
birthMonth= persentMonth - month;
birthDay= persentDay - day;

See Also:C++ Program to find Age and Days With Date of Birth Given using Class

Note:This Program was tested in Dev C++ compiler.

/*

* Program to calculate Date of birth

* Given

* --- days

* Results

* --- Finds out your date of birth in format of Year/Month/Day

* Note: I have not calculated the days with refrence to Leap Year that occurs in 4 Years gap.

* Author: Luzan Baral

* Twitter: http://twitter.com/luzanb

*/

#include<iostream>

#include<conio.h>

using namespace std;

class Find_DOB{

public:

int birthYear; // The Year

int persentYear; // The Year (Current)

int birthMonth; // The Month

int persentMonth; // The Month (Current)

int birthDay; // The Day

int persentDay; // The Day (Current)

int year;

int month;

int day;

int Days;

//default constructur

Find_DOB(){

birthYear=0;

persentYear=0;

birthMonth=0;

persentMonth=0;

birthDay=0;

persentDay=0;

year=0;

month=0;

day=0;

Days=0;

}

//fuction to get today's date

void get_todayDate(){

cout << "Please enter the current date. (In Numeral)" << endl;

cout << "" << endl;

cout << "" << endl;

cout << "Enter the current year: ";

cin >> persentYear; // Enter current year of date and hold in persentYear.

cout << "Enter the current month: ";

cin >> persentMonth; // Enter current month of date and hold in persentMonth.

cout << "Enter the current day: ";

cin >> persentDay; // Enter current day of date and hold in persentDay.

cout << "" << endl;

cout << "" << endl;

}

void get_days(){

cout << "Please enter your Days in Earth : ";

cin>>Days;

}

void calc_DOB(){

year = Days/365;

month = (Days % 365)/30;

day = (Days % 365) % 7;

cout<<"Year: "<<year<<" Month: "<<month<<" Days: "<<day;

birthYear= persentYear - year;

birthMonth= persentMonth -  month;

birthDay= persentDay - day;

cout<<endl;

cout<<"Date of Birth (YY/MM/DD) : "<<birthYear<<" / "<<M<<" / "<<birthDay;

}

};

int main()

{

Find_DOB obj;

// The Date.

cout << "This is a progran to tell your date of birth..." << endl;

obj.get_todayDate();

obj.get_days();

obj.calc_DOB();

getch();

return 0;

}

This program was taken from my lab work, feel free to suggest me other easy and simple methods for to solve this problem.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>