Total members 11894 |It is currently Mon Nov 25, 2024 12:51 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Program that make u know your age by input your birth day(get your age from birth-date code c++).
cpp code
#include<iostream>
using namespace std;
class AgeGetter
{
private:
int day;
int month;
int year;
public:
AgeGetter():day(1), month(1), year(1)
{}
void enterBirthdate()
{
cout<<"Get your age from birthdate:";
cout<<endl;
cout<<"Now you have to enter your birthdate";
cout<<endl;
cout<<"day(dd):";
cin>>day;
cout<<"month(mm):";
cin>>month;
cout<<"year(yyyy):";
cin>>year;
cout<<endl;
}
void Calculate_age(AgeGetter a1, AgeGetter a2)
{
if(a1.day>a2.day && a1.month>a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<a1.day-a2.day<<"-"<<a1.month-a2.month<<"-"<<a1.year-a2.year;
cout<<endl<<endl;
}
else if(a1.day<a2.day && a1.month>a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<(a1.day+30)-a2.day<<"-"<<(a1.month-1)-a2.month<<"-"<<a1.year-a2.year;?
cout<<endl<<endl;
}
else if(a1.day>a2.day && a1.month<a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<a1.day-a2.day<<"-"<<(a1.month+12)-a2.month<<"-"<<(a1.year-1)-a2.year;
cout<<endl<<endl;
}
else if(a1.day<a2.day && a1.month<a2.month)
{
cout<<"your age is :"<<endl;
cout<<"\t\t"<<(a1.day+30)-a2.day<<"-"<<(a1.month+11)-a2.month<<"-"<<(a1.year-1)-a2.year;
cout<<endl<<endl;
}
else if(a1.year<a2.year)
{
cout<<"The birthdate you have entered is invalid."<<endl;
}
}
};
int main()
{
AgeGetter a1, a2, a3;
cout<<"\t Entry Today date: ";
cout<<endl<<endl;
a1.enterBirthdate();
cout<<endl<<endl;
a2.enterBirthdate();
a3.Calculate_age(a1,a2);
return 0;
}





Author:
Newbie
User avatar Posts: 14
Have thanks: 0 time

Thanks General for your efforts.

_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 109
Have thanks: 5 time
Post new topic Reply to topic  [ 2 posts ] 




cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com