هذا البرنامج كنت اقوم بإعداده للرد على احد الاستفسارات ولكن عندما انتهيت منه وجدت ان الموضوع تم إغلاقه من قبل الادارة نظرا لمخالفته قواعد الطرح في المنتدى
أتمنى ان يكون ذا فائدة ونظرا لكوني مبتدئ في برمجة السي بلس بلس أتمنى ان يقوم الخبراء بطرح انتقاداتهم وتقديم آراءهم والشكر مقدما
البرنامج عبارة عن برنامج لحساب العمر . فقط قم باعطاء تاريخ الميلاد .
#include <iostream.h>
#include <dos.h>
/*
this Code Written by Omani
www.arabteam2000-forum.com
C++ forum
//
*/
/* getdate example */
class calander
{
int d,m,y,m_days;
public:
void set_date ()
{
cin>>d>>m>>y;
}
void display()
{
cout<<d<<"\\"<<m<<"\\"<<y<<endl;
}
void get_age(calander C_Date,calander B_Date)
{
d=(C_Date.d - B_Date.d);
if(d<0)
{
d=mdays(m)+d;
C_Date.m-=1;
}
m=C_Date.m-B_Date.m;
if(m<0)
{
m=12+m;
C_Date.y-=1;
}
y= C_Date.y- B_Date.y;
}
void Show_Age(calander C_Date,calander B_Date)
{
cout<<"\n Birth Date=";
B_Date.display();
cout<<"\n Today Date=";
C_Date.display();
cout<<"\nThe Age is="<<y<<" Year(s)"<<m<<" Month(s)"<<d<<" Day(s)";
}
int mdays(int);
void today_date();
};
//to get today Date by using DOS.H Header file.
void calander::today_date()
{
struct date today;
getdate(&today);
d=today.da_day;
m=today.da_mon;
y=today.da_year;
}
// to get the Current Month Days;
int calander::mdays(int m)
{
int m_days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
return m_days[m-1];
}
int main()
{
calander C_Date,B_Date,age;
//Get the Date of Today
C_Date.today_date();
cout<<"Enter date of birth as day,month,year:\n";
//Get the Birth day
B_Date.set_date();
//Cout the Age by passing 2 dates
age.get_age(C_Date,B_Date);
//Show Total years months and Days.
age.Show_Age(C_Date,B_Date);
return(0);
}size]
