برجاء من الأخوة الأفاضل المساعدة, أنشاء برامج بلغة السي بلس بلس
السلام عليكــم ورحمـة الله وبركاتــه ،،
برجاء من الأخوة الأفاضل مساعدتي في أنشاء هذين البرنامجين حيث أنني في أول طريقي و أتمنى أن يوفقني الله و قد أستفدت كثيرا من هذا المنتدى و كل الأخوة الأفاضل به :-
1) Implement a lamp class. Write the constructor that displays a text “new lamp”. And destructor that display a text “old lamp”
2) Implement a wedding lamp class that contains 10 lamp and they turns on in turn one after one then two after two , then tree after tree and so on.
و أريد من حضراتكم إذا تكرمتم شرح لهذا البرنامج و مخرجاته :-
#include <iostream>
using namespace std;
class lamp {
private:
bool a ;
public:
lamp()
{ cout<<"I aM Created default"<<endl; };
lamp ( bool b )
{ a=b;
cout<< "I aM Created"<<endl; };
~lamp(){ cout<<"I aM deleted"<<endl;};
void turn_on_off (void)
{ a= (a)^1;
cout<< "I aM switched "<<a<<endl; } ;
};//c,c0,c1;
class widding_lamps
{ public:
lamp c[10];
void light()
{for (int i=0; i<10;i++) {
c[i].turn_on_off();
c[i].turn_on_off(); }; }; };
void selebrate (){
widding_lamps z;
z.light(); }
int main ()
{ widding_lamps c1;
selebrate () ;
getchar();
return 0; }
و أسف على الأطالة بارك الله فيكم جميعا و زادكم من علمه
رد: برجاء من الأخوة الأفاضل المساعدة, أنشاء برامج بلغة السي بلس بلس
كود:
#include <iostream>
using namespace std;
class lamp {
private:
bool a ;
public:
lamp()
{ cout<<"I aM Created default"<<endl; };
lamp ( bool b )
{ a=b;
cout<< "I aM Created"<<endl; };
~lamp(){ cout<<"I aM deleted"<<endl;};
void turn_on_off (void)
{ a= (a)^1;
cout<< "I aM switched "<<a<<endl; } ;
};//c,c0,c1;
class widding_lamps
{ public:
lamp c[10];
void light()
{for (int i=0; i<10;i++) {
c[i].turn_on_off();
c[i].turn_on_off(); }; }; };
void selebrate (){
widding_lamps z;
z.light(); }
int main ()
{ widding_lamps c1;
selebrate () ;
getchar();
return 0; }
لم أقم بعمل رن للكود صراحة لعدم وجود كومبيلر على جهازى حاليا
لكن تقريبا هذا البرنامج يقوم بما طلبت أنت بالأعلى
فى الكونستركتور يطبع
I aM Created
وفى الديستركتور يطبع I aM deleted
و الكلاسس الأخرى تقريبا تقول بنفس عمل السؤال الثانى "i think its working though Trace it"
بالتوفيق أن شاء الله
رد: برجاء من الأخوة الأفاضل المساعدة, أنشاء برامج بلغة السي بلس بلس
ألف شكر لردك الكريم لقد نفعني كثيرا أعزك الله