الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كيفة فصل الملفات الى cpp و h.

مغلق
بدأه حزينه في 2 يناير 2007 · 12 رد · 1,133 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

عندي مشروع بسيط ومحتاجه مساعدتكم

وعندي امل كبير ان الكل هنا ماراح يقصر معي

عندي كلاس فيه بعض الاخطاء حاولت اعدلها ومن ثم افصله الى ملفات cpp. و h.

لكن مازالت الاخطاء موجوده ..!!

راح اكتب الكود قبل افصله بوجود الاخطاء ..

#include <iostream>
using namespace std;
#include <ctime>//used to det 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::Date(){
  char today [10];
  _strdate(today);

  char *tokenPtr;

  tokenPtr = strtok(today, "/");
  setMonth(tokenPtr);

  tokenPtr = strtok(NULL, "/");
  setDay(tokenPtr);

  tokenPtr = strtok(NULL, "/");
  char s[5] = {'2', '0', *tokenPtr, *(tokenPtr+1)};
  setYear(s);
}

Date::Date (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::operator ==(const Date& d){	
	return (day == d.day && month == d.month && year == d.year); 
}

Date Date::operator + (const Date& d)
	{	Date date(*this);
		date.addDays(d.day);
		date.addMonths(d.month);
		date.addYears(d.year);
		return date;
	}

Date & Date::operator ++ (){
		nextDay(); 
		return *this;
	}

Date Date::operator ++ (int){
		Date d(*this);
		nextDay(); 
		return d;
	}

int Date::operator [] (int index) const
	{	switch (index){
		case (DAY): return day;
		case (MONTH): return month;
		case (YEAR): return year;
		default: exit(1);
		}
	}



int Date::validatePartOfDate(char * toBeValidated, int partOfDate){

	int i = atoi(toBeValidated);

	if (i > 0)
	{
	 switch (partOfDate){
		case (DAY): 
			if (i < 31) return i;
			else return 0;

		case (MONTH):
			if (i < 13) return i;
			else return 0;

		case (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;


system("PAUSE");
return 0;
}

وهذي محاولتي في التعديل قبل فصل الكود الى ملفات ...

#include <iostream>
using namespace std;
#include <ctime>//used to det today's date

 static const int DAY = 1;
 static const int MONTH = 2;
 static const int YEAR = 3;

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:




//========================================================================
//---------------------------- M E T H O D S -----------------------------
//========================================================================

public:


		 int day;
		 int month;
		 int year;
		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::Date(){
  char today [10];
  _strdate(today);

  char *tokenPtr;

  tokenPtr = strtok(today, "/");
  setMonth(tokenPtr);

  tokenPtr = strtok(NULL, "/");
  setDay(tokenPtr);

  tokenPtr = strtok(NULL, "/");
  char s[5] = {'2', '0', *tokenPtr, *(tokenPtr+1)};
  setYear(s);
}

Date::Date (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::operator ==(const Date& d){	
	return (day == d.day && month == d.month && year == d.year); 
}

Date Date::operator + (const Date& d)
	{	Date date(*this);
		date.addDays(d.day);
		date.addMonths(d.month);
		date.addYears(d.year);
		return date;
	}

Date & Date::operator ++ (){
		nextDay(); 
		return *this;
	}

Date Date::operator ++ (int){
		Date d(*this);
		nextDay(); 
		return d;
	}

int Date::operator [] (int index) const
	{	switch (index){
		case (DAY): return day;
		case (MONTH): return month;
		case (YEAR): return year;
		default: exit(1);
		}
	}



int Date::validatePartOfDate(char * toBeValidated, int partOfDate){

	int i = atoi(toBeValidated);

	if (i > 0)
	{
	 switch (partOfDate){
		case (DAY): 
			if (i < 31) return i;
			else return 0;

		case (MONTH):
			if (i < 13) return i;
			else return 0;

		case (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;


system("PAUSE");
return 0;
}

و لما طفشت فصلت الكود الى الملفات :wacko: راح احطها في ملف مرفق

الله يخليكم انا محتاجه معاي احد فاهم وباله طويل

لاني لازم اسلمه بعد العيد مباشره

2.zip

#2

يللا وين المبرمجين ؟؟

معقول مافي احد يساعدني !!!

ترى لازم اسلم مشروعي الاسبوع القادم :(

#3

اش هي الأخطاء اللي تطلعلك..بالضبط..يعني المشكلة في فصل الملفات ولا؟؟؟

الافضل انك تطبعيها هنا عشان نشوفها..

بعدين..وش رايك نمسك ال header أول وندرسه!!

هذا فقط الheader file

include <iostream>
using namespace std;
#include <ctime>//used to det 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);
};

What a Wonderful World

#4

طبعا يوجد مجموعة كبيرة من الاخطاء ,

من نظرتي الاولى للكود وجدت

static const int DAY = 1;

static const int MONTH = 2;

static const int YEAR = 3;

لا يمكن اعطاء قيم ابتدائية للمعطيات الاعضاء " المتغيرات " سواء كان عام ام خاص , الا قيمة واحده فقط وهي pure اي نساويها بالصفر وهذا تأخذيه في دراستك المتقدمة في مايتعلق بتعدد الاشكال .

بالنظر لما قمت بتعديله : اجد بان الاخطاء تدول حول عمليتي << و >>

والسبب هو طريقة استدعاء ostream و istream

في اول البرنامج امسحي السطر

using namespace std واكتبي بدلا منه استدعاء كل دالة ستستخدم داخل البرنامج .

اي اكتبي بدلا منه :

#include <iostream>

using std::ostream;

using std::istream;

using std::cin;

using std::cout;

using std::endl;

وان شاء الله سيكون الحل صحيح .

بالنسبة لفصل الملفات :

الملف الرأسي يكون فيه الاعلان عن الداوال , ثم نكتب صف لكتابة تعريف ادوال والاخير هو البرنامج main ونستعدي فيه الملف الرأسي .

تحياتي .

llback.jpg

اشهد ان لا إله إلا الله وان محمدا ً رسول الله

#5

اخوي طريقة الفصل جدا سهلة و تنقسم إلى ثلاث اقسم :

1-ملف header و يحتوي فقط فقط فقط على تعريف الكلاس

2-ملف implementaion و يحتوي على دوال الكلاس (cpp)

3-ملف رئيسي cpp

:)

:::كوت بو 6:::

IDE : Microsoft Visual Studio 2005 Pro

#6

اختي دانتيلا .. مشكوره وري يسعدك

كفايه انك جيتي تساعدني :)

انا سويت الـheader file كذا

وفعلا مثل ماقال اخوي time1

مااقدر اعطي قيم ابتدائيه للمتغيرات داخل الكلاس فلذالك طلعتهم برى

وحاولت استخدم الطريقه اللي قالها بس زادات معي الاخطاء :wacko:

#ifndef DATE_H
#define DATE_H

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:

		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);
};

#endif
#7

اخوي 1 time

مشكور وربي يوفقك على مساعدتك

اخوي Ferrum

ربي يعطيك العافيه على مساعدتك

#8
اقتباس
وحاولت استخدم الطريقه اللي قالها بس زادات معي الاخطاء

لا لم تحاولي استخدام الطريقة التي ذكرتها لك والا لما زادت الاخطاء .

انا قلت استخدمي استدعاء الانماط ostream & istream عند الحاجة لها وانت لم تستعديها في ملف الهيدر

#include <iostream>
using std::ostream;
using std::istream;

حاولي اضافة هذا الكود في ملف الهيدر وتلاحظي انه لا يوجد ولا خطأ :)

llback.jpg

اشهد ان لا إله إلا الله وان محمدا ً رسول الله

#9

اخوي time 1

والله حقك علي .. انا من الاول ماحطيتها بالمكان الصحيح :(

الحين ضبط معاي بس طلع معي بعض الاخطاء ..

--------------------Configuration: main - Win32 Debug--------------------

Linking...

main.obj : error LNK2001: unresolved external symbol "public: int __thiscall Date::operator[](int)const " (??ADate@@QBEHH@Z)

main.obj : error LNK2001: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class Date &)" (??5@YAAAV?$basic_istream@DU?$cha

r_traits@D@std@@@std@@AAV01@AAVDate@@@Z)

main.obj : error LNK2001: unresolved external symbol "public: class Date & __thiscall Date::addDays(int)" (?addDays@Date@@QAEAAV1@H@Z)

main.obj : error LNK2001: unresolved external symbol "public: class Date & __thiscall Date::operator++(void)" (??EDate@@QAEAAV0@XZ)

main.obj : error LNK2001: unresolved external symbol "public: class Date __thiscall Date::operator+(class Date const &)" (??HDate@@QAE?AV0@ABV0@@Z)

main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Date::operator==(class Date const &)" (??8Date@@QAE_NABV0@@Z)

main.obj : error LNK2001: unresolved external symbol "public: __thiscall Date::Date(int,int,int)" (??0Date@@QAE@HHH@Z)

main.obj : error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Date &)" (??6@YAAAV?$basic_ostream@DU?$cha

r_traits@D@std@@@std@@AAV01@AAVDate@@@Z)

main.obj : error LNK2001: unresolved external symbol "public: __thiscall Date::Date(void)" (??0Date@@QAE@XZ)

Debug/main.exe : fatal error LNK1120: 9 unresolved externals

Error executing link.exe.

main.exe - 10 error(s), 0 warning(s)

وربي يوفقك ويسعدك

دانتيلا .. time 1

خلووكم معاي بكمل الجزيئه الباقيه

لو صعب علي شي مااقدر الا الجأ لكم :rolleyes:

تم تعديل هذه المشاركة بواسطة حزينه في 4 يناير 2007 في 19:46

#10

حسنا ضعي لنا الاكواد التي قمتي بتعديلها :

الملف الرأسي - وملف تعريف الدوال - والبرنامج .

llback.jpg

اشهد ان لا إله إلا الله وان محمدا ً رسول الله

#11
#include <iostream>
using std::ostream;
using std::istream;

#include"date.h"
using namespace std;
#include <ctime>//used to det today's date

 static const int DAY = 1;
 static const int MONTH = 2;
 static const int YEAR = 3;

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;


system("PAUSE");
return 0;
}

******************************

#include"date.h"

//Default construcor sets the date to be today's date
Date::Date(){
  char today [10];
  _strdate(today);

  char *tokenPtr;

  tokenPtr = strtok(today, "/");
  setMonth(tokenPtr);

  tokenPtr = strtok(NULL, "/");
  setDay(tokenPtr);

  tokenPtr = strtok(NULL, "/");
  char s[5] = {'2', '0', *tokenPtr, *(tokenPtr+1)};
  setYear(s);
}

Date::Date (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::operator ==(const Date& d){	
	return (day == d.day && month == d.month && year == d.year); 
}

Date Date::operator + (const Date& d)
	{	Date date(*this);
		date.addDays(d.day);
		date.addMonths(d.month);
		date.addYears(d.year);
		return date;
	}

Date & Date::operator ++ (){
		nextDay(); 
		return *this;
	}

Date Date::operator ++ (int){
		Date d(*this);
		nextDay(); 
		return d;
	}

int Date::operator [] (int index) const
	{	switch (index){
		case (DAY): return day;
		case (MONTH): return month;
		case (YEAR): return year;
		default: exit(1);
		}
	}



int Date::validatePartOfDate(char * toBeValidated, int partOfDate){

	int i = atoi(toBeValidated);

	if (i > 0)
	{
	 switch (partOfDate){
		case (DAY): 
			if (i < 31) return i;
			else return 0;

		case (MONTH):
			if (i < 13) return i;
			else return 0;

		case (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;
	}

**********************************

#include <iostream>
using std::ostream;
using std::istream;
#ifndef DATE_H
#define DATE_H


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:


		 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);
};

#endif

بالكومبايلر مايطلع اخطاء لكن بالرن :wacko:

#12

الاخطاء :

يوجد دالة مستخدمة لا يوجد لها تعريف .

_strdate(today);

ايضا يوجد متغيرات غير معرفة وكان من المفروض تعريفها داخل ملف الهيدر .

DAY & MONTH & YEAR

تم تعديل هذه المشاركة بواسطة time1 في 4 يناير 2007 في 23:22

llback.jpg

اشهد ان لا إله إلا الله وان محمدا ً رسول الله

#13

واخيرا .. اشتغل معاي الكود كويس

بس ظهر لي خطأ بسيط في القيمه اثناء التشغيل

واشكر الجميع على المساعده :)

لي عودة

هذا الموضوع مغلق.

مواضيع مشابهة