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

تصحيح في ال Overloading

بدأه شعاع الأمل في 11 مايو 2009 · 2 رد · 984 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

هذه حلول وحاولاتي لبعض الأسئله عن الأوفر لودنق..

أتمنى التصحيح أو إبداء معلومات إن كان هناك أخطاء..

Overload the pre/post decrement, negation, and subscript operators of the DiscountCard class. The operators should be overloaded such that the following main function can run properly as specified in the comments

int main(){

DiscountCard myCard (500);

DiscountCard yourCard(100);

myCard--; //Exchange one voucher

Discountcard operator—-(Discountcard ob)

{

Discountcard temp=ob;

Ob.voucher--;

Return temp;

}

--myCard; // Exchange one voucher

Discountcard operator—- (Discountcard &ob)

{

Ob.voucher++;

Return ob;

}

!myCard// returns true if points are not enough to be exchanged.

Bool operator!(Discountcard ob)

{

If(!ob)

Return true;

Else

Return false

\\or return(!ob);

myCard [3]//returns the same card after exchanging 3 vouchers from it

int&operator[](int index)

{

Return card;

}

return 0;

}

Overload prefix decrement, negation, and two forms of plus operators of the Book class. The operators should be overloaded such that the following main function can run properly as specified in the comments

Book myBook;

myBook + 1936 //Borrower with id 1936 borrows myBook

Book operator+(Book&ob)

{

Ob+1963;

Return ob;

}

--myBook; //Returns the myBook

Book operator-- (Book &ob)

{

Return ob;

}

7395 + myBook //Borrower with id 7395 borrows myBook

Book oprator+ (Book ob)

{

7395+ob;

Return ob;

}

!myBook; //Ture if the book available (not borrowed)

Bool operator!(book ob)

{

If(!ob)

Return true;

Else

Return false;

}

Optional (difficult)

Overload the subtraction operator of the Date class to return a new Date object, which contains the differences in years, months, and days, between the two dates.

Date dateOfBirth(8, 5, 1982);

Date today;

Date myAge;

myAge = today – dateOfBirth;

Date operator-(Date ob1,Date ob21)

{

Date temp;

Temp.day=ob1.day-ob2.day;

Temp.month=ob1.month-ob2.month;

Temp.year=ob1.year=ob2.year;

Return temp;

}

تم تعديل هذه المشاركة بواسطة شعاع الأمل في 11 مايو 2009 في 23:53

#2

مافيه أحد يصحح!!

#3

السلام عليكم

لأنك أخى لم ترفق الكود الكامل للكلاس book وغيره

هذا مثال بسيط على postfix و prefix و not

طبعا يمكنك تغيير الوظيفه ل not كما تريد

#include <iostream>
using namespace std;
class A 
{
private:
	int val;
public:
	A(){ val=0;}
	A(int a){ val=a;}
	void print(){ cout<<val<<endl;}
	A& operator++()
	{
		val++;
		return *this;
	}
	A operator++(int a)
	{
		A temp=*this;
		val++;
		return temp;
	}
	A operator!()
	{
		val=100-val;
		return *this;
	}
	A operator=(A& a)
	{
		val=a.val;
		return *this;
	}
};
int main()
{
	A a(4),b(6);
	a=b++;
	a.print();
	b.print();
	(!a).print();
	return 0;
}

أرجوا ان تستفيد من المثال

سلام

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

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