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

حل سؤال على قانون مساحة المربع باستخدام class

بدأه norhan ahmad في 4 يوليو 2011 · 9 رد · 6,712 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم :

انا حليت هذا السؤال على قانون مساحة المربع بس ما اعرفت اكمله ومو متاكده منه الرجاء المساعدة ولكم جزيل الشكر :

القانون : طول الضلع * طول الضلع

#include<iostream>

using namespace std;

class Square

{

private:

double along ;

public:

Square() {along = 0.0;}

Square(int r);

void along (double r){along = r;}

double along(){ return along * along * along;}

double getArea();

};

Square::Square(int r)

{

Along = r;

}

double Square::getArea()

{

return Along * Along * Along ;

}

int main()

{

int s;

Square c(7);

Square *cp1 = &c;

Square*cp2 = new Square(7);

}

الرجاء المساعدة لمن يستطيع الحل وشكرا لكم

:hmm:

#2

هذا البرنامج مكتوب بلغة C تقريباً، وليس Java

597657.png
#3

الكود مكتوب بلغه الـ C++ مش C كمان هههههههه

انا عملته ليكى بس مش عندى Compiler علشان اجربه لكن ان شاء الله صحيح

Square.h file

class Square
{
private:
double along ;
public:
Square();
Square(int r);
void setLong (double r);
double getLong();
double getArea();
};

Square.cpp file

#include "Square.h"
Square::Square()
{
	along = 0.0;
}
Square::Square(int r)
{
	along = r;
}

double Square::getArea()
{
return along * along;
}

void Square::setLong(double r)
{
	along = r;
}

double Square::getLong()
{
 return along;
}

main.cpp file

#include<iostream>
#include"Square.h"
using namespace std;
int main()
{
int s;
cout<<"Enter the long of square"<<endl;
cin>>s;
Square c(s);
cout<<"Area of "+s+" = "+ c.getArea() <<endl;
}

وهذه هى الملفات مرفقه

cpp_prob.zip

بالتوفيق

Software Developer
Mahmoudkelany.com


 

#4

شكرا على الاهتمام حتى لو الكود في لغة c++ اريده لانه محتاجه له ضروري

#5
norhan ahmad كتب:

شكرا على الاهتمام حتى لو الكود في لغة c++ اريده لانه محتاجه له ضروري

العفو

لكن المشكله اننا نقول لك ان الكود C++ لان المنتدى هنا مهتم بالـ Java

يعنى المفروض يكون الموضوع فى قسمه الخاص به

ألا وهو

/index.php?showforum=14

اتمنى من الاشراف نقله الى هناك

Software Developer
Mahmoudkelany.com


 

#6

شكرا الك على المساعده وكان من دون هههههههههههههه

على كل حال شكرا وانا حبيت انزل الحل على المنتدى للاستفادة منه وهاد هو الحل وشكرا :

#include<iostream>

using namespace std;

class Square

{

private:

double along ;

public:

Square() {along = 0.0;}

Square(int r);

void setalong (double r){along = r;}

double L(){ return along * along * along;}

double getArea();

double getCircumference();

};

Square::Square(int r)

{

along = r;

}

double Square::getArea()

{

return (along * along);

}

double Square:: getCircumference()

{

return along * 4;

}

int main()

{

int s;

int t;

cout<< " Hello in your data structures "<<endl;

cout<<endl;

cout<<endl;

cout<<endl;

cout<<" ******************************************************************"<<endl;

cout<<" *** The laws of the square ***"<<endl;

cout<<" *** ***"<<endl;

cout<<" *** Area of the square = along the rib * along the rib ***" <<endl;

cout<< " *** perimeter square = along the rib * 4 ***"<<endl;

cout<<" ******************************************************************"<<endl;

cout<<endl;

cout<<endl;

cout<<endl;

cout<< " Enter the along the rib of the square : "<<endl;

cout<<endl;

cin>>t;

cout<<endl;

Square c(t);

Square *cp1 = &c;

Square*cp2 = new Square(t);

cout<<" Area of the square : "<< c.getArea()<<endl;

cout<<endl;

cout<<endl;

int l;

cout<<" Enter the along the rib of the square :"<<endl;

cout<<endl;

cin>>l;

Square v(l);

Square *cp3 = &v;

Square*cp4 = new Square(l);

cout<<endl;

cout<<" Circumference of the square : "<< v.getCircumference()<<endl;

cin>>s;

}

#7

لماذا ال constructor يقبل int فقط مع ان القيمه الداخليه لل along من النوع double

#8

اهلا اخ على

الدوال الثابتة يمكن استدعائها من اى كائن

والدوال الغير ثابتة لا يمكن استدعائها من كائن ثابت

جرب ان تعدل كود الدالة الرئيسية ليصبح كالتالى

#include<iostream> 
#include"Square.h" 

using namespace std; 

int main() 
{ 

    int s; 
    cout<<"Enter the long of square"<<endl; 
    cin >> s; 

    const Square c(s); 
    cout << "Area of " << s << " = " << c.getArea() << endl; 

    return 0;
}

واعمل ترجمة للكود compile

هذا الناتج عندى مع MinGW4.5.2

post-165385-077703000 1310157090_thumb.p

اما اذا جعلت الدالة getArea ثابتة

double getArea() const;

عندها لايظهر هذا الخطأ

شكرا على مرورك الكريم

المرفقات
Untitledddddd.png


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#9

صحيح استخدام ال const method وحدها ممكن مع ال const objects ولكن لا اره ان لها داعي في مثل هذا السؤال. ولكن قد يكون الافضل استخدامها (من الملاحظ ان صاحب الموضوع مبتدء فلا اره داعي لدخو كثير بتفاصيل كتابه الكود بال ++C)

#10
اقتباس

ولكن قد يكون الافضل استخدامها

وهذا ماجعلنى اكتب تعليقى ليس فلسفة منى ولا استعراض :)

1


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…