Mon May 21, 2007 11:10 pm
#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;
}
Sat Jun 09, 2007 1:52 pm
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
Powered by phpBB © phpBB Group.