Online Examination System for all learner!!! coming soon..

C++: Program to calculate age in years, months and days.

Input the date of birth of a person and find his age in terms of year, month and days. using class.

Age Calculator of a Person

Code:

//for more program please visit www.programtubenotes.blogspot.in 
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#define WELCOME "WELCOME TO AGE CALCULATOR"

using namespace std;


class Age
{
    private:
        int day,month,year;
    public:
        void getdata();   //input date
        friend void show(Age t, Age b, Age a);//calculate age
};
void Age::getdata()
{
    cin>>day>>month>>year;
}
void show(Age t, Age b, Age a)
{
    if(t.day<b.day)
    {
        t.month--;
        t.day+=30;
    }
    a.day=t.day-b.day;
    if(t.month<b.month)
    {
        t.year--;
        t.month+=12;
    }
    a.month=t.month-b.month;
    a.year=t.year-b.year;
    cout<<"\nYour Age is  "<<a.year<<" year "<<a.month<<" month "<<a.day<<" day ";
   
    cout<<"\n\n\nCreated By:- Mr. Maheswar Sahoo\nFor more application please contact:-maheswarsahoo47@gmail.com";
    cout<<"\nThank You...\n\n\n";
}
int main()
{
    system("COLOR 4C");  //for background color
    Age birth;
    Age today,age;
    cout<<"\t\t\t\t"<<WELCOME;
    cout<<"\n\n\nEnter date of today (dd mm yyyy) : ";
    today.getdata();
    system("COLOR 1C");   //change background color
    cout<<"\nEnter date of birth (dd mm yyyy) : ";
    birth.getdata();
    show(today,birth,age);
    return 0;
}



We suggest this video to watch:




Related word:
Class



Popular codes:

C Programming Online Test 1

Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answ...