السلام عليكم
انا ابي اعرف كيف اضيف على هذا البرنامج
انه يطرح تاريخ اليوم من تاريخ الميلاد
#include <iostream>
using namespace std;
#include <ctime>//used to set today's date
class Date{
//---------------- F R I E N D F U N C T I O N S ---------------------
//------------------------------------------------------------------------
//Overloading insertion operator must be as a friend funciton
friend ostream& operator << (ostream& outs, Date& d);
//Overloading extraction operator must be as a friend funciton
friend istream& operator >> (istream& ins, Date& d);
//
//------------------------- A T T R I B U T E S --------------------------
//
private:
static const int DAY = 1;
static const int MONTH = 2;
static const int YEAR = 3;
int day;
int month;
int year;
//
//---------------------------- M E T H O D S -----------------------------
//
public:
Date(); //Default constructor
Date (int d, int m, int y); //Constructor
//Getter methods.
int getDay(){return day;}
int getMonth(){return month;}
int getYear(){return year;}
//Setter methods
bool setDay(int d){
if (d > 0 && d < 31){
day = d;
return true;
}
else return false;
}
bool setMonth(int m){
if (m > 0 && m < 13){
month = m;
return true;
}
else return false;
}
bool setYear(int y){
if (y > 1990){
year = y;
return true;
}
else return false;
}
bool setDay(char * d){return setDay(atoi(d));}
bool setMonth(char * m){return setMonth(atoi(m));}
bool setYear(char * y){return setYear(atoi(y));}
//Other methods
Date& addDays(int days);
Date& addMonths(int months);
Date& addYears(int years);
Date& nextDay();
//Operator Overloaders
bool operator ==(const Date& d);
Date operator + (const Date& d);
Date & operator ++ ();
Date operator ++ (int);
int operator [] (int index) const;
//
//------------------ H E L P E R F U N C T I O N S -------------------
//
//helper function: if given string is an int and not larger than the
//max, return it. Otherwise, return 0;
static int validatePartOfDate(char * toBeValidated, int sec);
};
//Default construcor sets the date to be today's date
Date[img=http://www.arabmoheet.net/forum/editor/smiles/biggrin2.gif]ate(){
time_t tt = time(NULL); /* Get the current date in seconds */
tm ttm = *localtime(&tt); /* Convert to structure */
setDay(ttm.tm_mday);
setMonth(ttm.tm_mon + 1);
setYear(ttm.tm_year + 1900);
}
Date[img=http://www.arabmoheet.net/forum/editor/smiles/biggrin2.gif]ate (int d, int m, int y){ setDay(d); setMonth(m); setYear(y);}
Date& Date::addDays(int days){
if (!setDay(this->day + days)){
setDay( ((this->day + days) % 30));
addMonths( (this->day + days) / 30);
}
return *this;
}
Date& Date::addMonths(int months){
if (!setMonth(this->month + months)){
setMonth((this->month + months) % 12);
addYears( (this->month + months) / 12);
}
return *this;
}
Date& Date::addYears(int years){
setYear(year + years);
return *this;
}
Date& Date::nextDay(){
addDays(1);
return *this;
}
bool Date:[img=http://www.arabmoheet.net/forum/editor/smiles/redface2.gif]perator ==(const Date& d){
return (day == d.day && month == d.month && year == d.year);
}
Date Date:[img=http://www.arabmoheet.net/forum/editor/smiles/redface2.gif]perator + (const Date& d)
{ Date date(*this);
date.addDays(d.day);
date.addMonths(d.month);
date.addYears(d.year);
return date;
}
Date & Date:[img=http://www.arabmoheet.net/forum/editor/smiles/redface2.gif]perator ++ (){
nextDay();
return *this;
}
Date Date:[img=http://www.arabmoheet.net/forum/editor/smiles/redface2.gif]perator ++ (int){
Date d(*this);
nextDay();
return d;
}
int Date:[img=http://www.arabmoheet.net/forum/editor/smiles/redface2.gif]perator [] (int index) const
{ switch (index){
case (Date[img=http://www.arabmoheet.net/forum/editor/smiles/biggrin2.gif]AY): return day;
case (Date::MONTH): return month;
case (Date::YEAR): return year;
default: return -1;
}
}
int Date::validatePartOfDate(char * toBeValidated, int partOfDate){
int i = atoi(toBeValidated);
if (i > 0)
{
switch (partOfDate){
case (Date[img=http://www.arabmoheet.net/forum/editor/smiles/biggrin2.gif]AY):
if (i < 31) return i;
else return 0;
case (Date::MONTH):
if (i < 13) return i;
else return 0;
case (Date::YEAR):
if (i > 1900) return i;
else return 0;
default: return 0;
}
}
return 0;
}
ostream& operator << (ostream& outs, Date& d){
outs << d.day <<"-" << d.month << "-" << d.year;
return outs;
}
istream& operator >> (istream& ins, Date& d){
ins >> d.day;
ins >> d.month;
ins >> d.year;
return ins;
}
int main(){
Date today;
cout<<today<<endl;
Date d1(1,2,1950);
Date d2(3,5, 2004);
cout << "dates equal? " << (d1 == d2)<< endl;
Date difference(10,2,0);
cout << " d1 after 10 days and two months " << (d1 + difference) << endl;
cout << d2;
cout << " after prefix increment " << (++d2) << endl;
cout << d2;
cout << " after adding 29 days " << d2.addDays(29) << endl;
cout << "please enter the difference you wish:" << endl;
cin >> difference;
cout << "difference is now " << difference<< endl;
cout << "days: " << d2[1] << endl;
/////////////////////////////////////////////////
ابي ادخل هذي في المين
بس الاشكالية السطر الاخير
Date dateOfBirth(8, 5, 1982);
Date today;
Date myAge;
myAge = today – dateOfBirthتكفوون ردو بسرعه لان عندي اختبار وهذي النقطه ماشرحتها الاستاذة

