السلام عليكــم ورحمـة الله وبركاتــه ،،
هذه حلول وحاولاتي لبعض الأسئله عن الأوفر لودنق..
أتمنى التصحيح أو إبداء معلومات إن كان هناك أخطاء..
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;
}