مشاهدة النسخة كاملة : مساعدة في ++c


بنت اليم
31-12-2007, 02:13 PM
السلام عليكم ورحمة الله وبركاته

ممكن تساعدوني إذا ممكن يا اخواني واخواتي .....أنا ماكنت حاضرةلأسبوعين الجامعة بسبب إني كنت مريضة وخلال هالاسبوعين تم شرح class و overloading وهذا السؤال الي وجدته بالكتاب يتعلق بهم ممكن احد يساعندي بحلة ويقولي شلون حله؟
Define a class named Date that has three integer value representing hour, minute, and year with the following operations:
· Default constructor that initializes the date to 1/1/1980.
· A function that sets the date to any sensible values.
· Prints the date in a proper format.
· A function that overloads the == operator as a member function.
· A function that overloads the == operator as a non-member function.
In the main function:
· Define 2 objects with different dates.
· Print the dates.
· Apply the above defined 2 functions for == to compare the above defined dates and print “The dates are similar” or “The dates are different” accordingly.
· Assign the second date to the first date, print the dates, and compare them again by repeating the previous step.

داليا_DD
02-01-2008, 07:08 PM
انا عندي كود عن الوقت ما ادري اذا هو نفس المطلوب ولا لا

ع العموم خوذيه من الرابط


http://www.tntup.com/file.php?file=d1dfdb9eb417c2d95a3509e669cb5fb4

بنت اليم
18-01-2008, 07:43 PM
السلام عليكم
حاولت في البرنامج لكن مابعرف إذا صح ؟

# include<iostream
>

using namespace std;
class Date
**
//friend bool operator ==(const Date D1,const Date D2);
private :
int d;
int m;
int y;
public :
Date(int a=1,int b=1,int c=1980);
void set(int a,int b,int c);
void print();
bool operator ==(const Date &D);
};
Date ::Date(int a,int b,int c)
**
d=a;
m=b;
y=c;
}

void Date ::set(int a,int b,int c)
**
d=a;
m=b;
y=c;
}
void Date ::print()
**
cout<<d<<"/"<<m<<"/"<<y<<endl;
}
bool Date ::operator ==(const Date &D)
**
if (d==D.d&&m==D.m&&y==D.y)
return true ;
else
return false ;
}
/* bool operator ==(const Date D1,const Date D2)
**
if (D1.d==D2.d&&D1.m==D2.m&&D1.y==D2.y)
return true ;
else
return false ;
}*/
int main()
**
Date A(11/8/2004);
Date B(12/4/2001);
A.print();
B.print();
if (A==B)
cout<<"The dates are similar"<<endl;
else
cout<<"The dates are different"<<endl;
A=B;
A.print();
B.print();
if (A==B)
cout<<"The dates are similar"<<endl;
else
cout<<"The dates are different"<<endl;
return 0;
}